Search code examples
githubyamlgithub-actionspipeline

GitHub Actions won't start jobs wit job output in if statement


Good day to you, colleagues!

I set up a workflow in which I wanted to start jobs only when some checks finished with "true". But jobs don't start. I used answers in this and this as an example but it doesn't work.

name: testing-workflow
run-name: test-run

on:
  push:
    branches:
      - '*'
    
jobs:

  check_where_changed:
    name: Check files
    outputs:
      modified_workflow_dir: ${{ steps.check_files_again2.outputs.modified_workflow_dir }}

    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          fetch-depth: 2

      - name: Check Modified Files In Workflow Directory
        id: check_files_again2
        run: |
          echo "checking paths of modified files"
          git diff --name-only HEAD^ HEAD > files.txt
          while IFS= read -r file
          do
            echo $file
            if [[ $file != .github/workflows/* ]]; then
              echo "This modified file is not under the workflows dir."
              echo "modified_workflow_dir=false" >> $GITHUB_OUTPUT
              break
            else
              echo "File modified in workflows dir, setting up variables"
              echo "modified_workflow_dir=true" >> $GITHUB_OUTPUT
            fi
          done < files.txt
          cat $GITHUB_OUTPUT


  workflow_test:
    name: Job For Testing Purposes
    if: needs.check_where_changed.outputs.modified_workflow_dir == 'true'
    needs: [ check_where_changed ]
    runs-on: ubuntu-latest

    steps:
      - name: Test echo
        run: echo "Testing Message"

Tried to fix syntax in different ways as was advised in different forums, ended up with official documentation syntax. Tried to read $GITHUB_OUTPUT with cat in workflow - everything seems fine, but next jobs wont start.


Solution

  • typo in modified_worflow_dir --> modified_workflow_dir (missing k)

    so try:

          modified_workflow_dir: ${{ steps.check_files_again2.outputs.modified_workflow_dir }}
    
    

    instead of:

          modified_workflow_dir: ${{ steps.check_files_again2.outputs.modified_worflow_dir }}