I have a Github action in my repository that runs only when a specific file has changed. I have marked this action as required in repository settings so that whenever it fails the automatic merge gets blocked. Merge block is working fine but if a PR doesn't include a change to that specific file, Github still blocks the PR waiting for the job to complete which won't even run. Ideally, Github should ignore this action if it is not applicable.
CodePudding user response:
A workaround could be to update the workflow to run independently of the path, but check the path in the job execution with something like the path filter action, then return the message you want on the PR if the label isn't set and set an error to block the merge, or return that everything is ok if the file hasn't been updated.
Your workflow would in that case looks like sometihing to this:
name: All Checked Verifier
on:
pull_request:
types: [labeled, unlabeled, opened, edited, synchronize]
jobs:
enforce-label:
runs-on: ubuntu-latest
steps:
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
public_api_views:
- '**/code.py'
- if: steps.changes.outputs.public_api_views == 'true'
uses: yogevbd/[email protected]
with:
REQUIRED_LABELS_ALL: "checked-everything"
REQUIRED_LABELS_ALL_DESCRIPTION: "Make sure we have checked everything and once done, add label 'checked-everything' to this PR."