actions / runner

The Runner for GitHub Actions :rocket:
https://github.com/features/actions
MIT License
4.77k stars 932 forks source link

on.pull_request.paths-ignore are not respected correctly #2324

Open GRBurst opened 1 year ago

GRBurst commented 1 year ago

Describe the bug

According to the documentation we can use paths-ignore in the same way for pull_request events as we can do for push events on.<push|pull_request|pull_request_target>.<paths|paths-ignore>.

However, if we define a workflow like the following, the behavior differs:

name: Echo Date

on:
  push:
    paths-ignore:
      - 'README.md'
  pull_request:
    types: [opened, synchronize]
    paths-ignore:
      - 'README.md'

jobs:
  echo-date:
    runs-on: ubuntu-latest
    name: "Echo"

    steps:
      - name: Run echo date
        run: |
          echo -e "Hello at $(date -I)"

Although it seems to be working at the beginning when I (1) created a pr, (2) pushed a change on README.md and (3) nothing triggered, the behavior changed as soon as one commit of the pr references a file outside of the paths-ignore list. After a change to a file outside of the paths-ignore list, all following commits trigger the workflow.

Someone else mentioned a problem here as well: https://github.com/actions/runner/issues/545#issuecomment-1321467176

To Reproduce You can find a minimal example here: https://github.com/GRBurst/pull_requests.paths

Steps to reproduce the behavior:

  1. Create an action as above (or fork the example)
  2. Create a new branch and a pr
  3. Add commits, where at least one commit changes a file outside the paths-ignore declaration
  4. Check that all following commits trigger the workflow (the pull_request events triggers, the push does not).

Expected behavior I expect that the conditions to run the actions only take the last commit into account. So if I have commit that changes a file outside the path definition, it triggers the workflow. If a following commit does only changes to files declared in the paths-ignore list, the workflow should not trigger.

Runner Version and Platform

Version of your runner? -> 2.299.1

OS of the machine running the runner? OSX/Windows/Linux/... -> Ubuntu, 22.04.1, LTS

rene-hermenau commented 1 year ago

Can confirm the bug

nickfujita commented 1 year ago

Confirmed when trying this Github suggested solution in the troubleshooting docs: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks

ShutdownRepo commented 1 year ago

I also confirm this bug.

zdenko-kovac commented 1 year ago

I can also confirm the bug:

Workflow: https://github.com/zdenko-kovac/testing/blob/main/.github/workflows/testPR.yaml PR with 3 commits: https://github.com/zdenko-kovac/testing/pull/2

where:

kingthorin commented 1 year ago

It's been half a year, any news on this?

ilyesAj commented 1 year ago

as a work around you can make :

  pull_request:
     paths:
       - '!docs/**'
       - '.github/**'
mmulligan03 commented 1 year ago

Is there an update on this issue? Has anyone developed a workaround?

pavetok commented 1 year ago

It seems pull_request.paths affected too.

qrkourier commented 1 year ago

Is there an update on this issue? Has anyone developed a workaround?

@ilyesAj's workaround to negate paths patterns didn't work for me. I tried it the way they wrote it, and I tried it like this because the workflow syntax reference indicates that negations may only subtract from selected paths. The result of both workaround attempts was that no pull request event types triggered the workflow irrespective of change objects matching the paths filter patterns.

  pull_request:
     paths:
       - '**'
       - '!docs/**'
       - '.github/**'
wallyrion commented 1 year ago

Also, I have a similar issue in my project. Paths working for 'push' but not working for 'pull_requests' This workflow always runs when new changes are added in a pull request regardless of the changed path

on: push: branches: ["refactoring/move-to-separate-solutions"] paths:

deleugpn commented 1 year ago

According to this explanation https://github.com/orgs/community/discussions/25161#discussioncomment-3246673 this "bug" is by design. Apparently when we make the on: pull-request actions, it will automatically use the synchronize event which will always consider all commits of a file change.

Although understandable, I think what we're missing here is a different implementation of the on: pull request functionality. If we had something like:

on:
  pull_request:
    types: [pushed]

Perhaps the pushed event could work differently than the synchronize event and thus not creating a huge breaking change effect. This way we could have a setup where we only run GH Actions based on pull requests events that includes a push of a commit, but also offers path filters on the most recent commit only. After all, if I have a deployment action and I'm only changing docs file, it doesn't matter that previous commits made changes to the real code, I still don't want to re-run all my deployment and pay for GH Actions when there's clearly no functionality change.

munapower commented 7 months ago

I have a similar issue. I have defined a workflow with the following:

name: Update Documentation
on: 
  push:
    paths-ignore: 
      - '.github/workflows/**'
      - "!**.md"
  pull_request:
    paths-ignore: 
        - '.github/workflows/**'
        - "!**.md"

When I push a change of the yaml that contains this code it doesn't execute. This is expected. Then I made a change to "samples/chaincode/echo-go/chaincode/echo.go" and pushed it and the workflow did run. I understand that it shouldn't have since the "!**.md" would have been true, right?

khiemthanhicario commented 2 months ago

Me too. I have the same bug. The paths-ignore does not work. The flow always run unexpectedly.

sabman commented 1 month ago

Same here. Running out of credit as a result of this. 😞 this is pretty disappointing.

Zidaan-Hayat commented 1 month ago

Still facing the same issue, how has it been nearly 2 years?

kingthorin commented 1 month ago

Well it's pretty simple if you just consider the numbers. They have 100s of thousands or maybe even millions of users and what like a dozen or two have chimed in on this issue. Plus the fact that really anyone could tackle and fix it....this is a public repo. 🤷‍♂️

rmprakash7 commented 3 weeks ago

Confirming same issue. I hope someone puts in a fix!

nukopy commented 1 week ago

I have same issue. paths-ignore is not working.

A workflow triggered by this commit in this pull request.

name: CI

on:
  push:
    branches:
      - main
    paths-ignore:
      - ".gitignore"
      - "**.md"
  pull_request:
    paths-ignore:
      - ".gitignore"
      - "**.md"
...