Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Ability to run a workflow if and only if certain file/directory changes #124

Closed
1 task done
aleclerc-sonrai opened this issue Jul 8, 2021 · 5 comments · Fixed by #137
Closed
1 task done
Labels
enhancement New feature or request

Comments

@aleclerc-sonrai
Copy link

Is your feature request related to a problem? Please describe.

Use case:
I want to run a workflow if and only if any file under a certain directory changes.

If any other files have changed I do not want to run the workflow.

In my case, I'm trying to auto-approve a PR using this action https://github.com/marketplace/actions/auto-approve
but only if files under the dev directory have been updated, and nothing else.

Describe the solution you'd like?

Ideally something like this:

    steps:
    - uses: actions/checkout@v2
    - name: Get changed files for dev
      id: changed-files-dev
      uses: tj-actions/changed-files@v8.4
      with:
        files: |
          dev
    - uses: hmarr/auto-approve-action@v2
      if: steps.changed-files-dev.outputs.only_changed == 'true'
      with:
        github-token: "${{ secrets.GITHUB_TOKEN }}"

Where only_changed would be true if any file in that directory were present, and ONLY files in that directory were in the diff (i.e no other files)

Describe alternatives you've considered?

I've tried something like this:

    steps:
    - uses: actions/checkout@v2
    - name: Get changed files for dev
      id: changed-files-dev
      uses: tj-actions/changed-files@v8.4
      with:
        files: |
          dev
    - name: Get changed files for all
      id: changed-files-rest
      uses: tj-actions/changed-files@v8.4
      with:
        files: |
          ^(dev)
    - uses: hmarr/auto-approve-action@v2
      if: steps.changed-files-dev.outputs.any_changed == 'true' && steps.changed-files-rest.outputs.any_changed == 'false'
      with:
        github-token: "${{ secrets.GITHUB_TOKEN }}"

But that doesn't seem to work and feels clunky.

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@aleclerc-sonrai aleclerc-sonrai added the enhancement New feature or request label Jul 8, 2021
@jackton1
Copy link
Member

jackton1 commented Jul 11, 2021

Have you tried ??

  steps:
    - uses: actions/checkout@v2
    - name: Get changed files for dev
      id: changed-files
      uses: tj-actions/changed-files@v8.4
      with:
        files: |
          dev
    - uses: hmarr/auto-approve-action@v2
      if: steps.changed-files-dev.outputs.any_changed == 'true'
      with:
        github-token: "${{ secrets.GITHUB_TOKEN }}"

@aleclerc-sonrai
Copy link
Author

Yeh so that does work, but if i have a file that's not under dev it'll also approve it. I was hoping to get an if in these files, and no others.

@jackton1
Copy link
Member

I doubt that the step would still run for other files but I’m guessing your requesting that if other files and the dev folder change you don’t want to approve the PR just for only the dev folder changes ?

@aleclerc-sonrai
Copy link
Author

Yeh that was the idea. However I. did this combined with CODEOWNERS PR restrictions for all files except dev, and that seems to work.

@jackton1
Copy link
Member

I'll look into adding support for this.

Glad you found a way around the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants