8000 Avoid running CI twice on PRs. by ezio-melotti · Pull Request #461 · python/bedevere · GitHub
[go: up one dir, main page]

Skip to content

Avoid running CI twice on PRs. #461

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

Closed
wants to merge 2 commits into from
Closed

Avoid running CI twice on PRs. #461

wants to merge 2 commits into from

Conversation

ezio-melotti
Copy link
Member

I noticed that tests are run twice on each PR:
image

This change avoids that by only running them once whenever a PR is created/updated, and then once it is merged with master.

@ezio-melotti ezio-melotti self-assigned this May 30, 2022
@codecov
Copy link
codecov bot commented May 30, 2022

Codecov Report

Merging #461 (8bcc105) into main (1f7ab83) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #461   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines         1721      1721           
  Branches       208       208           
=========================================
  Hits          1721      1721           

@hugovk
Copy link
Member
hugovk commented May 30, 2022

I'm strongly against this as it impedes contribution by making it harder for contributors to fully test their code before creating a PR.

I wrote more here: python/typeshed#7066 (comment)

I've not used this GitHub Action yet, perhaps it can help?

https://github.com/marketplace/actions/skip-duplicate-actions

@ezio-melotti
Copy link
Member Author

If I understand correctly, you are saying that by limiting the push trigger to main, if you create a branch on your fork and push changes to your branch, it won't trigger the workflow because it's not a push on master and it not part of a PR yet, right?

Personally I either test locally before pushing and/or I rely on the checks that are run on the PR once I create it (which is generally immediately after I pushed the branch on my fork) -- I never looked at the test results on my fork. If this is a use case that we want to support for this repo, we could look into the action you suggested, but I'm not familiar with it.

@hugovk hugovk mentioned this pull request May 30, 2022
@hugovk
Copy link
Member
hugovk commented May 30, 2022

If I understand correctly, you are saying that by limiting the push trigger to main, if you create a branch on your fork and push changes to your branch, it won't trigger the workflow because it's not a push on master and it not part of a PR yet, right?

Exactly.

Personally I either test locally before pushing and/or I rely on the checks that are run on the PR once I create it (which is generally immediately after I pushed the branch on my fork) -- I never looked at the test results on my fork. If this is a use case that we want to support for this repo, we could look into the action you suggested, but I'm not familiar with it.

Testing locally is good, but CIs are really powerful and allow us to easily test on multiple Python versions. It can be difficult to set up several locally, and keep them all current.

This can be a common cause of failures: maybe some new feature is used that's not available on older Pythons, or something is used that's removed in newer.

(Not relevant here, but often projects will test on multiple operating systems. This can be even harder to fully test locally, and also a common cause of failures: often something passes on the developer's machine, but not on Windows.)

It also helps avoid "works on my machine". By testing on the CI, we know we have the same setup (not always 100% true with CIs, but more so than dev machines :) We know dependencies are defined properly and installed in a clean env.

More generally, sometimes testing can take a long time locally, but CIs are usually much faster, especially with a comprehensive test matrix. (On some projects, I've not been able to test locally because it needed to install multiple GB worth of Docker stuff than I had available, but could contribute and test changes via CI.)

I believe the use of CIs are of huge benefit for software quality and development, especially when so easy nowadays; Travis CI really revolutionised this, remember how hard testing was before. We should rather encourage people to test on their own forks before creating PRs.

Fail fast: shorten the time to finding a failure, enable quicker loops of incremental development.

@nightlark
Copy link
nightlark commented May 30, 2022

If I understand correctly, you are saying that by limiting the push trigger to main, if you create a branch on your fork and push changes to your branch, it won't trigger the workflow because it's not a push on master and it not part of a PR yet, right?

Exactly.

While it is accurate to say that it won't trigger automatically on pushes, it has the workflow_dispatch trigger, so you are still able to trigger tests on other branches when you want to test them in your fork.

Here's a screen capture showing how to access the feature on GitHub.
ci-workflow-dispatch-trigger

@hugovk
Copy link
Member
hugovk commented May 30, 2022

Sure, that's also possible, but it's still an extra impediment. Making the human do more work so the computer can do less.

In your screen capture I see some 9 mouse clicks taking about 25 seconds! And then repeat for each push. The tests take around 25s, so could have finished by then.

And these tests are so quick, how much of a problem is it really for them to be run twice?

(For example, see also python/peps#2215 (comment))

@nightlark
Copy link
nightlark commented May 30, 2022

It's not 9 clicks -- to be fair, I did accidentally click on a branch that I didn't intend to, which cuts it down to 7. If you anticipate running lots of tests, you can always keep the Tests page open and cut it down to ~3 clicks.

The gh cli command also supports triggering workflow runs from the command line, so you could do it without leaving your shell window; it can also be used to view the result of workflow runs, so you don't need to switch to a browser or use any clicks to check the status of a workflow run.

@hugovk
Copy link
Member
hugovk commented May 30, 2022

It's not 9 clicks -- to be fair, I did accidentally click on a branch that I didn't intend to, which cuts it down to 7. If you anticipate running lots of tests, you can always keep the Tests page open and cut it down to ~3 clicks.

And that's an argument to keep them automated, humans can and will accidentally click the wrong thing :)

@nightlark
Copy link
8000

True. I'd just noticed this from an email notification on #463 (comment) and thought that the arguments against #461 sounded like they are all addressed by adding a workflow workflow_dispatch trigger -- then noticed in the changed files here that it already exists, so wanted to clear up that there exists a working alternative and point out where the feature is for anyone who isn't familiar with it.

Anyway, I think we are probably bikeshedding at this point given the time scales involved, small build matrix size, and the frequency of changes to this repository. As far as the change proposed in this PR goes from the perspective of a potential contributor to bedevere, I don't have a preference one way or the other for every commit triggering CI builds.

@ezio-melotti
Copy link
Member Author
ezio-melotti commented May 30, 2022

For reference, we discussed this on Discord, and this is a summary of our findings and the options we considered:

  • Currently the on: ... can be filtered by branch, paths, or tags, but not by repository or owner.
    • There is a feature request on github/feedback that would allow to include/ignore forks in the on: ...
    • Using a special prefix in the branch name is an option -- e.g. pytest uses the test-me- prefix
    • Using tags is also an option, in addition or in combination to branch prefixes
    • It's difficult to know/remember the naming conventions used by each repo
  • It is possible to use conditions to control job execution, however this will still show the duplicate tests as skipped.
    • the if: ... can be used for all jobs or individual steps
    • github.repository, github.repository_owner, github.event_name can be used to filter
    • e.g.: if: github.repository_owner != 'python' && github.event_name != 'push'
  • It is possible to use the "skip duplicate actions" action.
  • It is possible to change the workflow file in the fork, however
    • if it's changed on main, it makes it more difficult to keep it in sync with upstream
    • if it's changed in the branch, it then needs to be reverted before creating the PR
  • It is possible to use the workflow_dispatch as shown above 1

It seems that the options are:

  1. close the PR and keep the duplicate checks
  2. use if: ... to skip the duplicated jobs, even if they show up in the list of checks as skipped
  3. add the test-me- branch prefix like pytest does (and possibly a test-me tag too)

Using the "skip duplicate actions" seems a bit overkill to me, and using the workflow_dispatch is a bit cumbersome (even though it could be configured as an additional option).


Footnotes

  1. Actually I think it's more complicated than that. The video runs the tests on main using the workflow from a branch. It is possible to add a field where to enter the branch that should be tested though, using an input: field under the workflow_dispatch and then with: ref: ${{ github.event.inputs.selected_branch }}. Note that the branch name also has to be typed in, unless there is a "branch dropdown" input that I'm not aware of.

@nightlark
Copy link
nightlark commented May 30, 2022

Footnotes

  1. Actually I think it's more complicated than that. The video runs the tests on main using the workflow from a branch. It is possible to add a field where to enter the branch that should be tested though, using an input: field under the workflow_dispatch and then with: ref: ${{ github.event.inputs.selected_branch }}. Note that the branch name also has to be typed in, unless there is a "branch dropdown" input that I'm not aware of.

It uses both the workflow file and checks out the code from the selected branch -- here's the line from the job run in the screen capture showing the branch being checked out https://github.com/nightlark/bedevere/runs/6657800671?check_suite_focus=true#step:2:133

@CAM-Gerlach
Copy link
Member

FWIW, seems like either merging, moving or removing the upstream branch here is the only blocker to fully implementing python/core-workflow#460 on this last repo.

@hugovk
Copy link
Member
hugovk commented Jun 13, 2023

Of the options in #461 (comment):

  1. close the PR and keep the duplicate checks

This is my preference.

  • I don't think there's a real problem here to solve.
  • Simplest.
  • Most PRs come from forks, you have complete control to disable Actions in your fork (or not enable in the first place, by default they're disabled).
  • For rare PRs from this repo, tests are very quick and take only a minute to run.
  1. use if: ... to skip the duplicated jobs, even if they show up in the list of checks as skipped

My second choice.

  1. add the test-me- branch prefix like pytest does (and possibly a test-me tag too)

My third choice.

@AlexWaygood
Copy link
Member

FWIW I generally prefer the setup @ezio-melotti is proposing here for my own projects. But I agree with @hugovk that, given the relative infrequency of PRs to the bedevere repo, there isn't really a significant problem being solved here.

Given Hugo's strong objection, let's say that the status quo wins this one :)

@arhadthedev arhadthedev deleted the fix-gh-workflow branch June 13, 2023 08:40
@arhadthedev
Copy link
Member

@CAM-Gerlach Done.

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

Successfully merging this pull request may close these issues.

6 participants
0