---
name: Generate DAG visualizations
on:
  workflow_dispatch:
    inputs:
      comments:
        description: "Comments"

jobs:
  generate_dag:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.9"]

    steps:
      - name: Print author
        run: |
          echo "Author: ${{ github.triggering_actor }}"
          echo "Comments: ${{ github.event.inputs.comments }}"

      - name: Checkout main branch
        uses: actions/checkout@v3
        with:
          ref: refs/heads/master

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install non-python dependencies
        run: |
          sudo apt-get install -y graphviz-dev graphviz

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install snakebids

      - name: Set-up env for hippunfold
        run: |
          echo "HIPPUNFOLD_CACHE_DIR=`pwd`/test_data/fake_models" >> $GITHUB_ENV
          echo "HIPPUNFOLD=./hippunfold/run.py" >> $GITHUB_ENV

      - name: Generate rulegraph single T2w bids
        run: |
          $HIPPUNFOLD test_data/bids_singleT2w test_out participant -np --modality T2w --rulegraph | dot -Tsvg > docs/images/rulegraph_T2w.svg

      - name: Commit updates
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git diff-index --quiet HEAD || git add docs/images || commit -m "Add updated dags [skip ci]"

      - name: Push changes
        uses: ad-m/github-push-action@v0.8.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
