Home > front end >  Mark a conditional Github Action as required
Mark a conditional Github Action as required

Time:01-12

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.

I have put up a public enter image description here

and i forked the repo enter image description here

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."
  •  Tags:  
  • Related