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

GitHub Actions has overlapping triggers which causes tests to run twice when pushing to an open PR #1370

Closed
AzfaarQureshi opened this issue Nov 10, 2020 · 8 comments
Labels
backlog bug Something isn't working

Comments

@AzfaarQureshi
Copy link
Contributor

AzfaarQureshi commented Nov 10, 2020

What is the issue
There are overlapping triggers for the test workflow which causes it to run twice if you commit to an open PR

Why is this a problem
Well, it's not that deep of a problem but:

  • you have to wait longer for CI to resolve
  • uses up twice the GitHub Actions minutes
  • slows down all other workflows as the 21 redundant runners increase queue times

it's more of a mild inconvenience but the fix is super quick (I can make a PR if the change is green-lit 😄)

We can solve this by only allowing pushes on master to trigger the workflow

# test.yml
name: Test
on:
  push:
   # branches-ignore:
   # - 'release/*'
    branches: master # proposed addition
  pull_request:

Steps to reproduce

  1. Open a PR
    • GitHub Actions test workflow only runs once under the pull_request trigger (expected behavior)
    • 21 total checks
  2. Push a commit to the open PR
    • test workflow runs twice, once under pull_request (expected) and again under push (unexpected)
    • 42 total checks
      Screen Shot 2020-11-09 at 8 30 35 PM
      Screen Shot 2020-11-09 at 8 46 07 PM
@AzfaarQureshi AzfaarQureshi added the bug Something isn't working label Nov 10, 2020
@NathanielRN
Copy link
Contributor

I think you can also use the pull request types as defined on the documentation:

on:
  pull_request:
    types: [opened, reopened]

@AzfaarQureshi
Copy link
Contributor Author

@NathanielRN yup that could work as well! My only concern is that if we restrict the pull_request trigger instead of push, we'll have the tests run whenever a commit is pushed upstream, even if the branch has no PR associated with it. That seems a bit unnecessary because it's probably not that useful to have CI to run while your work is WIP.

what do you think?

@NathanielRN
Copy link
Contributor

@AzfaarQureshi I personally find it really helpful to see tests on my commits, then when I make the PR I can be sure that it is passing tests and can be merged.

Not to mention that people have the ability to make pushes to their branches after its been approved. Please let me me if I misunderstood, but if you restrict it to only pushes to master then people can push something broken to their PR and tests won't run to block it from being merged. Running them on push means what you give is what you get: the code you pushed always has tests ran against it.

@AzfaarQureshi
Copy link
Contributor Author

AzfaarQureshi commented Nov 10, 2020

@NathanielRN oh, the tests will still run whenever you push new commits to an open PR. For example https://github.com/open-o11y/opentelemetry-python/pull/7/commits you can see that beside every commit there is a link to a unique execution of the test workflow (you can confirm this by looking at the runner ID and see they're diff). Restricting push to master only means that the push itself won't trigger a new workflow but commits to a branch with an open PR will still result in CI re-triggering

@NathanielRN
Copy link
Contributor

@AzfaarQureshi

Right that's because by default the pull request includes the type synchronize which provides the behavior you explained.

Like I said a push on every commit seems useful to me, especially since it allows developers to see if their code passes tests on remote (without having to open a PR to check this!) which is the end goal. I've found in the past that passing only locally can be misleading.

@AzfaarQureshi
Copy link
Contributor Author

AzfaarQureshi commented Nov 10, 2020

@NathanielRN

I've found in the past that passing only locally can be misleading.

Not sure what you mean by this exactly because the tests will still be run upstream when you open the PR

Please let me me if I misunderstood, but if you restrict it to only pushes to master then people can push something broken to their PR and tests won't run to block it from being merged.

right, as you mentioned, the synchronize type will prevent this from ever happening since any new push to a branch with an open pr re-triggers the CI. Am I misunderstanding your point? we can continue the convo in thread on gitter if you want.

It seems like @codeboten also had a chore listed to restrict the push to run on master only 9f5de45. Was there prior community discussion/consensus on this matter?

Either way, @NathanielRN's suggested change

on:
  pull_request:
    types: [opened, reopened]

also achieves the same result of removing redundant workflows so that change is fine by me too 😄

@github-actions
Copy link

github-actions bot commented Apr 9, 2021

This issue was marked stale due to lack of activity. It will be closed in 30 days.

@lzchen
Copy link
Contributor

lzchen commented Apr 19, 2021

Closing, we only run CI on pull requests now (except pushes to main).

@lzchen lzchen closed this as completed Apr 19, 2021
budak7273 added a commit to budak7273/2023S-Team4-ExplodingKittens that referenced this issue Mar 23, 2023
aszlig added a commit to nixcloud/ip2unix that referenced this issue Aug 6, 2023
This is seems to be a common[1] issue[2] and there really is not a very
satisfactory solution other than adding an "if" on the job rather than
on the top-level workflow. Of course, there were other solutions listed,
but they'd involve managing a hardcoded list of branch names where the
"on push" action is triggered.

So I went for the workaround listed in [1], which adds an if to the job
specification.

[1]: zopefoundation/meta#145
[2]: open-telemetry/opentelemetry-python#1370

Signed-off-by: aszlig <aszlig@nix.build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants