Skip to content

How to get GitHub Actions to build like we'd like it to

License

Notifications You must be signed in to change notification settings

clj-easy/gha-build-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GHA Build Example

A place to experiment with getting GitHub Actions to build like we’d like it to. If successful, we might even leave this repo around as an example/reference for those with similar build tastes.

Goals

  1. Run tests on pushes everywhere. Forks or not. This will allow folks to verity their work before submitting PRs.

  2. Avoid duplicate runs of same work

    1. Avoid confusion. A specific case that is especially annoying is that when goal 1 is enabled, we get a duplicate test run for a push to a PR. These duplicate runs are both registered as checks for the PR.

    2. Avoid unecessary compute. The planet is suffering, we don’t want to make it suffer more.

  3. Trigger release on new version tag. Again, without duplication of work.

Current Status - Experimenting

I don’t think GitHub Actions was designed with care for this combination of goals.

Can we bend it to our will? Or is this a quixotic whack-a-mole situation?

Notes

GitHub Actions must be enabled for forks

GitHub Actions must be enabled by the user for forks. Our premise that folks are typically using GHA on forks to verify before submitting PRs might be incorrect. But that does not invalidate our approach. They could be using GHA on forks. If they want to.

GitHub Actions trigger Granularity

GitHub actions allows some control over what invokes a workflow. But some controls are only available at the job level within a workflow. So sometimes we’ll trigger a workflow but skip all the jobs in that workflow. Just because that’s the way GitHub Actions currenltly works.

Experiments

De-duplicate test runs for PR push

FAILED: Experiment 1: Do not trigger tests for pull-request synchronize.

The idea is that duplicate tests runs are being triggered by the following events: - push - pull_request’s `synchronize activity

If we remove synchronize activity, would this do the trick?

No. This works for PRs created from branches off the repository. But for forks, tests are run on the fork only and not as checks for PR.

IN-PROGRESS: Experiment 2: De-duplicate test runs for PR push - suppress push trigger if in PR

If we can check that a commit is in a PR for a push event, can we simply supress the running of tests?

I can use gh, the github command line tool to search if the current commit sha is part of a PR. So if the triggering event is push and the sha is in a PR, tests should be skipped.

Look into:

  1. When opening a PR the commit is not yet part of a PR. So duplicate runs occur. Anything we can do that would work for both local branch and fork?

  2. In my testing I got occassional 403 errors, indicating rate limiting.

    You have exceeded a secondary rate limit. Please wait a few minutes before you try again.

    Not sure if this is an artifact of using gh. Or just me pushing frequently.

NOT-STARTED: Experiment 3: De-duplicate work in general - try out skip-duplicate-actions

While researching I stumbled upon https://github.com/fkirc/skip-duplicate-actions. This might be a good general solution to avoid duplicate work.

If I understand it correctly, it goes even further than I was thinking.

It can, for example, avoid re-running tests on merge that were just successfully run as part of a PR, if all files are identical. I suppose it could be smart enough to skip those tests on release as well.

Another scenario it handles is cancelling running jobs if a new job run is launched. This can happen for long-running jobs that have not completed before a new commit is pushed. Apparently GitHub Actions itself now has some support for this scenario.

Probably worth a try.

To consider

Do we need to re-run tests on release?

We think that tests should be run on release. But why? If they were already successfully run, why do we need to repeat them?

  • To double-check?

  • To handle case where a PR was merged that had failing tests?

  • To handle the case where the environment/os/build-tools might have changed since the same tests were last run?

Test Scenarios

Trigger tests for:

  • push to master or any other branch

  • push to fork of this repo

  • push to PR

    • from local branch

    • from fork

  • a release

Some specific desired behaviour:

  1. Trigger tests to run only once when working from a PR. We need the tests to be perceived by GitHub as checks for the PR.

  2. On publish, triggered by a version tag push, trigger a test run, then follow that up with a release work. An additional test run should not be triggered here. Any commit solely related to publishing should not trigger a test run (i.e. version bumps).

  3. Publish work should not be executed when on a fork.

About

How to get GitHub Actions to build like we'd like it to

Resources

License

Stars

Watchers

Forks

Packages

No packages published