From c7530b86b85588e41b7f845ba7cd27cdfd64de3c Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 17 Aug 2021 02:23:36 -0700 Subject: [PATCH 1/2] [skip changelog] Run relevant workflows on release branch creation The trunk-based development strategy is employed by this repository. This means that the release branch may contain a subset of the history of the default branch. The status of the GitHub Actions workflows should be evaluated before making a release. However, this is not so simple as checking the status of the commit at the tip of the release branch. The reason is that, for the sake of efficiency, the workflows are configured to run only when the processes are relevant to the trigger event (e.g., no need to run the Go unit tests for a change to the readme). In the case of the default branch, you can simply set the workflow runs filter to that branch and then check the result of the latest run of each workflow of interest. However, that was not possible to do with the release branch since it might be that the workflow was never run in that branch. The status of the latest run of the workflow in the default branch might not match the status for the release branch if the release branch does not contain the full history. For this reason, it will be helpful to trigger all relevant workflows on the creation of a release branch. This will ensure that each of those workflows will always have at least one run in the release branch. Subsequent commits pushed to the branch can run based on their usual trigger filters and the status of the latest run of each workflow in the branch will provide an accurate indication of the state of that branch. Branches are created for purposes other than releases, most notably feature branches to stage work for a pull request. Because the workflows are very comprehensive, it would not be convenient or efficient to run them on the creation of every feature branch. Unfortunately, GitHub Actions does not support filters on the `create` event of branch creation like it does for the `push` and `pull_request` events. There is support for a `branches` filter of the `push` event, but that filter is an AND to the `paths` filter and this application requires an OR. For this reason, the workflows must be triggered by the creation of any branch. The unwanted job runs are prevented by adding a `run-determination` job with the branch filter handled by Bash commands. The other jobs of the workflow use this `run-determination` job as a dependency, only running when it indicates they should via a job output. Because this minimal `run-determination` job runs very quickly, it is roughly equivalent to the workflow having been skipped entirely for non-release branch creations. This approach has been in use for some time already in the website deployment workflow. --- .github/workflows/check-go-task.yml | 39 +++++++++++++++++++ .github/workflows/check-i18n-task.yml | 29 ++++++++++++++ .github/workflows/check-protobuf-task.yml | 33 ++++++++++++++++ .github/workflows/publish-go-tester-task.yml | 29 ++++++++++++++ .../workflows/test-go-integration-task.yml | 30 ++++++++++++++ .github/workflows/test-go-task.yml | 30 ++++++++++++++ 6 files changed, 190 insertions(+) diff --git a/.github/workflows/check-go-task.yml b/.github/workflows/check-go-task.yml index 7b82220be90..f7b3a3c84d9 100644 --- a/.github/workflows/check-go-task.yml +++ b/.github/workflows/check-go-task.yml @@ -7,6 +7,7 @@ env: # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows on: + create: push: paths: - ".github/workflows/check-go-task.ya?ml" @@ -25,8 +26,36 @@ on: repository_dispatch: jobs: + run-determination: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ \ + "${{ github.event_name }}" != "create" || \ + ( \ + "${{ github.event_name }}" == "create" && \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ + ) \ + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "::set-output name=result::$RESULT" + check-errors: name: check-errors (${{ matrix.module.path }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest strategy: @@ -62,6 +91,8 @@ jobs: check-outdated: name: check-outdated (${{ matrix.module.path }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest strategy: @@ -100,6 +131,8 @@ jobs: check-style: name: check-style (${{ matrix.module.path }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest strategy: @@ -138,6 +171,8 @@ jobs: check-formatting: name: check-formatting (${{ matrix.module.path }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest strategy: @@ -176,6 +211,8 @@ jobs: check-config: name: check-config (${{ matrix.module.path }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest strategy: @@ -208,6 +245,8 @@ jobs: # Do a simple "smoke test" build for the modules with no other form of validation build: name: build (${{ matrix.module.path }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest strategy: diff --git a/.github/workflows/check-i18n-task.yml b/.github/workflows/check-i18n-task.yml index f871219f0ea..1521364a790 100644 --- a/.github/workflows/check-i18n-task.yml +++ b/.github/workflows/check-i18n-task.yml @@ -6,6 +6,7 @@ env: # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows on: + create: push: paths: - ".github/workflows/check-i18n-task.ya?ml" @@ -26,7 +27,35 @@ on: repository_dispatch: jobs: + run-determination: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ \ + "${{ github.event_name }}" != "create" || \ + ( \ + "${{ github.event_name }}" == "create" && \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ + ) \ + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "::set-output name=result::$RESULT" + check: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check-protobuf-task.yml b/.github/workflows/check-protobuf-task.yml index d07acbc0c98..bc50a6847e5 100644 --- a/.github/workflows/check-protobuf-task.yml +++ b/.github/workflows/check-protobuf-task.yml @@ -6,6 +6,7 @@ env: # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows on: + create: push: paths: - ".github/workflows/check-protobuf-task.ya?ml" @@ -20,7 +21,35 @@ on: repository_dispatch: jobs: + run-determination: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ \ + "${{ github.event_name }}" != "create" || \ + ( \ + "${{ github.event_name }}" == "create" && \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ + ) \ + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "::set-output name=result::$RESULT" + build: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest steps: @@ -54,6 +83,8 @@ jobs: run: task protoc:compile check: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest steps: @@ -81,6 +112,8 @@ jobs: run: task protoc:check check-formatting: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/publish-go-tester-task.yml b/.github/workflows/publish-go-tester-task.yml index 383aecb9387..135e5cd1a07 100644 --- a/.github/workflows/publish-go-tester-task.yml +++ b/.github/workflows/publish-go-tester-task.yml @@ -3,6 +3,7 @@ name: Publish Tester Build # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: + create: push: paths: - ".github/workflows/publish-go-tester-task.ya?ml" @@ -28,7 +29,35 @@ env: BUILDS_ARTIFACT: build-artifacts jobs: + run-determination: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ \ + "${{ github.event_name }}" != "create" || \ + ( \ + "${{ github.event_name }}" == "create" && \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ + ) \ + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "::set-output name=result::$RESULT" + build: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test-go-integration-task.yml b/.github/workflows/test-go-integration-task.yml index 0f5ed0a9e85..9d510b9851b 100644 --- a/.github/workflows/test-go-integration-task.yml +++ b/.github/workflows/test-go-integration-task.yml @@ -9,6 +9,7 @@ env: # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: + create: push: paths: - ".github/workflows/test-go-integration-task.ya?ml" @@ -33,7 +34,36 @@ on: repository_dispatch: jobs: + run-determination: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ \ + "${{ github.event_name }}" != "create" || \ + ( \ + "${{ github.event_name }}" == "create" && \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ + ) \ + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "::set-output name=result::$RESULT" + test: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' + strategy: matrix: operating-system: diff --git a/.github/workflows/test-go-task.yml b/.github/workflows/test-go-task.yml index 179967ba01a..6ac0d690f4c 100644 --- a/.github/workflows/test-go-task.yml +++ b/.github/workflows/test-go-task.yml @@ -7,6 +7,7 @@ env: # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: + create: push: paths: - ".github/workflows/test-go-task.ya?ml" @@ -29,7 +30,36 @@ on: repository_dispatch: jobs: + run-determination: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ \ + "${{ github.event_name }}" != "create" || \ + ( \ + "${{ github.event_name }}" == "create" && \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ + ) \ + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "::set-output name=result::$RESULT" + test: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' + strategy: matrix: operating-system: From 73146cef2b8b62732726efb898ad9c8235cc704d Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 17 Aug 2021 08:24:56 -0700 Subject: [PATCH 2/2] [skip changlog] Simplify jobs run determination logic Co-authored-by: Cristian Maglie --- .github/workflows/check-go-task.yml | 5 +---- .github/workflows/check-i18n-task.yml | 5 +---- .github/workflows/check-protobuf-task.yml | 5 +---- .github/workflows/publish-go-tester-task.yml | 5 +---- .github/workflows/test-go-integration-task.yml | 5 +---- .github/workflows/test-go-task.yml | 5 +---- 6 files changed, 6 insertions(+), 24 deletions(-) diff --git a/.github/workflows/check-go-task.yml b/.github/workflows/check-go-task.yml index f7b3a3c84d9..b78173bb2a8 100644 --- a/.github/workflows/check-go-task.yml +++ b/.github/workflows/check-go-task.yml @@ -38,10 +38,7 @@ jobs: # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. if [[ \ "${{ github.event_name }}" != "create" || \ - ( \ - "${{ github.event_name }}" == "create" && \ - "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ - ) \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ ]]; then # Run the other jobs. RESULT="true" diff --git a/.github/workflows/check-i18n-task.yml b/.github/workflows/check-i18n-task.yml index 1521364a790..8a3cc8211ea 100644 --- a/.github/workflows/check-i18n-task.yml +++ b/.github/workflows/check-i18n-task.yml @@ -39,10 +39,7 @@ jobs: # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. if [[ \ "${{ github.event_name }}" != "create" || \ - ( \ - "${{ github.event_name }}" == "create" && \ - "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ - ) \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ ]]; then # Run the other jobs. RESULT="true" diff --git a/.github/workflows/check-protobuf-task.yml b/.github/workflows/check-protobuf-task.yml index bc50a6847e5..22ce1c7cf63 100644 --- a/.github/workflows/check-protobuf-task.yml +++ b/.github/workflows/check-protobuf-task.yml @@ -33,10 +33,7 @@ jobs: # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. if [[ \ "${{ github.event_name }}" != "create" || \ - ( \ - "${{ github.event_name }}" == "create" && \ - "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ - ) \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ ]]; then # Run the other jobs. RESULT="true" diff --git a/.github/workflows/publish-go-tester-task.yml b/.github/workflows/publish-go-tester-task.yml index 135e5cd1a07..ab9b83cff91 100644 --- a/.github/workflows/publish-go-tester-task.yml +++ b/.github/workflows/publish-go-tester-task.yml @@ -41,10 +41,7 @@ jobs: # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. if [[ \ "${{ github.event_name }}" != "create" || \ - ( \ - "${{ github.event_name }}" == "create" && \ - "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ - ) \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ ]]; then # Run the other jobs. RESULT="true" diff --git a/.github/workflows/test-go-integration-task.yml b/.github/workflows/test-go-integration-task.yml index 9d510b9851b..6cd3de82aa0 100644 --- a/.github/workflows/test-go-integration-task.yml +++ b/.github/workflows/test-go-integration-task.yml @@ -46,10 +46,7 @@ jobs: # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. if [[ \ "${{ github.event_name }}" != "create" || \ - ( \ - "${{ github.event_name }}" == "create" && \ - "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ - ) \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ ]]; then # Run the other jobs. RESULT="true" diff --git a/.github/workflows/test-go-task.yml b/.github/workflows/test-go-task.yml index 6ac0d690f4c..77bed498630 100644 --- a/.github/workflows/test-go-task.yml +++ b/.github/workflows/test-go-task.yml @@ -42,10 +42,7 @@ jobs: # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. if [[ \ "${{ github.event_name }}" != "create" || \ - ( \ - "${{ github.event_name }}" == "create" && \ - "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ - ) \ + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ ]]; then # Run the other jobs. RESULT="true"