From ddc69a16382b92b719777c2c2c2b94b12730191a Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 10 Mar 2021 16:34:22 -0500 Subject: Improve Actions hygiene MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 👋 hello there! I'm a fellow Googler who works on projects that leverage GitHub Actions for CI/CD. Recently I noticed a large increase in our queue time, and I've tracked it down to the [limit of 180 concurrent jobs](https://docs.github.com/en/actions/reference/usage-limits-billing-and-administration) for an organization. To help be better citizens, I'm proposing changes across a few repositories that will reduce GitHub Actions hours and consumption. I hope these changes are reasonable and I'm happy to talk through them in more detail. - (**you were already doing this, thank you!**) Only run GitHub Actions for pushes and PRs against the main branch of the repository. If your team uses a forking model, this change will not affect you. If your team pushes branches to the repository directly, this changes actions to only run against the primary branches or if you open a Pull Request against a primary branch. - For long-running jobs (especially tests), I added the "Cancel previous" workflow. This is very helpful to prevent a large queue backlog when you are doing rapid development and pushing multiple commits. Without this, GitHub Actions' default behavior is to run all actions on all commits. There are other changes you could make, depending on your project (but I'm not an expert): - If you have tests that should only run when a subset of code changes, consider gating your workflow to particular file paths. For example, we have some jobs that do Terraform linting, but [they only run when Terraform files are changed](https://github.com/google/exposure-notifications-verification-server/blob/c4f59fee71042cf668747e599e7c769fca736554/.github/workflows/terraform.yml#L3-L11). Hopefully these changes are not too controversial and also hopefully you can see how this would reduce actions consumption to be good citizens to fellow Googlers. If you have any questions, feel free to respond here or ping me on chat. Thank you! --- .github/workflows/build.yml | 4 ++++ .github/workflows/go.yml | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0381a563..b572dc94f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,10 @@ jobs: default: runs-on: ubuntu-latest steps: + - name: Cancel previous + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - run: make - run: make build OPTIONS="--build_tag_filters nogo" TARGETS="//..." diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 594dc7ffc..9432f1137 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,6 +16,11 @@ jobs: generate: runs-on: ubuntu-latest steps: + - name: Cancel previous + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} + if: ${{github.ref != 'refs/head/main'}} - id: setup run: | if ! [[ -z "${{ secrets.GO_TOKEN }}" ]]; then -- cgit v1.2.3 From 449913e65514a629b40e37e4ebbb0fe310276e94 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 11 Mar 2021 13:25:04 -0500 Subject: Update go.yml --- .github/workflows/go.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9432f1137..4c8b8ea5c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,7 +20,6 @@ jobs: uses: styfle/cancel-workflow-action@0.7.0 with: access_token: ${{ github.token }} - if: ${{github.ref != 'refs/head/main'}} - id: setup run: | if ! [[ -z "${{ secrets.GO_TOKEN }}" ]]; then -- cgit v1.2.3