Quantcast
Channel: Is it possible to run the job only when a specific file changes?
Viewing all articles
Browse latest Browse all 14

Is it possible to run the job only when a specific file changes?

$
0
0

We solved this using tj-actions/changed-files as suggested here. Our requirement was to only run the job in case one of the files changed, but we didn’t want to cancel midway through (i.e. start a job, run tj-actions-changed-files, then proceed or cancel).

Our solution:

jobs:
  test:
    # {...}
  changedfiles:
    name: Check for changed files
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Check if changed files for serviceA
        id: serviceA
        uses: tj-actions/changed-files@v23.1
        with:
          files: |
            Dockerfile
            serviceA/
            lib/
      - name: Set output for serviceA
        id: serviceA_output
        if: steps.serviceA.outputs.any_changed == 'true'
        run: |
          echo "::set-output name=any_changed::true"
    outputs:
      serviceA: steps.serviceA_output.outputs.any_changed
  build-publish:
    name: Build and publish (serviceA)
    needs: [test, changedfiles]
    if: needs.changedfiles.outputs.serviceA
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
     # ...

Would be great with a natively supported feature for this!

Read full topic


Viewing all articles
Browse latest Browse all 14