1

I currently have a Github Actions workflow setup with the following trigger:

on:
  pull_request:
     paths: 
       - 'myFolder/*.yml'

I want this workflow to run on pull request events where a file matching with myfolder/*.yml has been changed. While this workflow does run on pull request events where this file has changed, it also runs on subsequent events even if they do not make any further changes.

The workflow this trigger is for runs a process using configuration from within the yml files and so if no changes happen to any of these files between commits (even if other files that do not match the filter are changed), the result will always be the same and does not need to be run.

I looked through the documentation for Github Actions and could not find anything that exactly matches my situation so would appreciate some help and pointers.

A simplified version with some name changes of the full workflow yml is:

name: Read yml files
on:
  pull_request:
    paths:
      - 'myFolder/*.yml'
jobs:
  promote:
    runs-on: ubuntu-latest

    name: Read files

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

      - name: Read
        run: npm run read-yml
2
  • 1
    You can't achieve what you want using on trigger alone. You would need to check the paths used on a step. I suggest using a paths-filter action to do so.
    – GuiFalourd
    Mar 4, 2022 at 14:01
  • Thanks for the link to the action! I assumed that would be the case but wanted to check!
    – Vistari
    Mar 4, 2022 at 14:18

1 Answer 1

2

It's not possible to do on YML workflow level.

You can however detect your case and leave early from a workflow.

I can suggest using changed-files action:

- name: Get changed files
  id: changed-files
  uses: tj-actions/[email protected]

- name: List all added files
  run: |
    for file in ${{ steps.changed-files.outputs.added_files }}; do
      echo "$file was added"
    done

or you can use renamed_files, deleted_files if it fits better to your needs.

Then you can detect if there are any files that may trigger your generation action - if not, simply end the workflow.

1
  • 1
    Thanks Grzegorz, I assumed that would be the case and appreciate sharing the action. I'll look to incorporate this into my workflow!
    – Vistari
    Mar 4, 2022 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.