Anyone who can help with a GitHub Action. I'm tryi...
# github-actions
s
Anyone who can help with a GitHub Action. I'm trying to check if any relevant files has changed, if so run some test steps, if not just end the pipeline with success to make the GitHub required step pass.
Copy code
required-test:
  name: required-test
  runs-on: ubuntu-latest
  environment: production
  strategy:
    fail-fast: false
    matrix:
      python-version: [ '3.11' ]

  steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0

    - name: Check if any files changed
      id: changed-files
      uses: tj-actions/changed-files@v37
      with:
        files: |
          .github/workflows/test_project2.yml
          test_project2/**

    - name: Run step if no files changed
      if: steps.changed-files.outputs.any_changed == 'false'
      run: |
        echo "No relevant files changed. Return success"
        exit 0

    - name: Test
      run: |
        echo "test"
But even with the exit 0 the step Test is run and depending jobs also run. How do I exit the full workflow here?
p
Didn't you mean to do
exit 1
? with exit code 0 it's a success and the workflow continues. That however fails the run and you may not want that. At the price of duplication if there's more steps to follow, you can include the condition to every step
Copy code
if: steps.changed-files.outputs.any_changed == 'true'
I guess this is the very thing you wanted to avoid
you could also split jobs so job1 only runs changed-files action and exposed an output and then job2 runs based on the if condition - no need to duplicate to all steps
s
My main issue is I want the test job to be required for PR's. So if files in a certain folder has changed run the tests, if not changed in that folder the test will just return success to make the required test pass in the PR to allow it to be merged into main.
p
I see, I can't think of any GHA native way to achieve it
g
@Dan Miller (Cloud Posse)
d
I'm not familiar with
tj-actions/changed-files
, but we do something similiar with Atmos and the github-action-atmos-affected-stacks action
p
It doesn't matter how you detect the affected stacks or changed files. You get a bool on the output and the question is what you can do with it to end the pipeline cleanly based on it