Skip to content

Commit 22ebde4

Browse files
jladieuichengchang
andauthored
Fix verify_consumer_pacts GitHub action. (#1531)
* Fix `verify_consumer_pacts` GitHub action. This is followup after: #1511 That PR (and associated changes) introduced the first WDS <-> WSM pact verification to WSM, but inadvertently broke the `verify_consumer_pacts` GitHub action in the process. This PR fixes that, while also adopting semantic versioning for reporting verification to Pact Broker. Various relevant threads: * https://broadinstitute.slack.com/archives/C043YJ40719/p1699888771297559 * https://broadinstitute.slack.com/archives/C043YJ40719/p1700155493619189 * https://broadinstitute.slack.com/archives/C043YJ40719/p1700154543175189 GitHub Actions logic copied from: DataBiosphere/terra-billing-profile-manager#324 Also enable pending pacts. See: https://docs.pact.io/pact_broker/advanced_topics/pending_pacts --------- Co-authored-by: Ivan <[email protected]>
1 parent b4c9451 commit 22ebde4

File tree

5 files changed

+259
-81
lines changed

5 files changed

+259
-81
lines changed

.github/workflows/consumer_contract_tests.yml

+63-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,58 @@ on:
2121
branches: [ main ]
2222
paths-ignore: [ '**.md' ]
2323

24+
env:
25+
PUBLISH_CONTRACTS_RUN_NAME: 'publish-contracts-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
26+
CAN_I_DEPLOY_RUN_NAME: 'can-i-deploy-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
27+
2428
jobs:
29+
bump-check:
30+
runs-on: ubuntu-latest
31+
outputs:
32+
is-bump: ${{ steps.skiptest.outputs.is-bump }}
33+
steps:
34+
- uses: actions/checkout@v3
35+
- name: Skip version bump merges
36+
id: skiptest
37+
uses: ./.github/actions/bump-skip
38+
with:
39+
event-name: ${{ github.event_name }}
40+
41+
# The primary objective of this section is to carefully control the dispatching of tags,
42+
# ensuring it only occurs during the 'Tag, publish, deploy' workflow.
43+
# However, a challenge arises with contract tests, as they require knowledge of the upcoming tag
44+
# before the actual deployment. To address this, we leverage the dry run feature provided by bumper.
45+
# This allows us to obtain the next tag for publishing contracts and verifying consumer pacts without
46+
# triggering the tag dispatch. This approach sidesteps the need for orchestrating multiple workflows,
47+
# simplifying our implementation.
48+
#
49+
# We regulate the tag job to meet the following requirements according to the trigger event type:
50+
# 1. pull_request event (due to opening or updating of PR branch):
51+
# dry-run flag is set to false
52+
# this allows the new semver tag #major.#minor.#patch-#commit to be used to identity pacticipant version for development purpose
53+
# PR has no effect on the value of the latest tag in settings.gradle on disk
54+
# 2. PR merge to main, this triggers a push event on the main branch:
55+
# dry-run flag is set to true
56+
# this allows the new semver tag #major.#minor.#patch to be used to identity pacticipant version, and
57+
# this action will not update the value of the latest tag in settings.gradle on disk
58+
#
59+
# Note: All workflows from the same PR merge should have the same copy of settings.gradle on disk,
60+
# which should be the one from the HEAD of the main branch before the workflow starts running
61+
regulated-tag-job:
62+
needs: [ bump-check ]
63+
if: ${{ needs.bump-check.outputs.is-bump == 'no' }}
64+
uses: ./.github/workflows/tag.yml
65+
with:
66+
# The 'ref' parameter ensures that the consumer version is postfixed with the HEAD commit of the PR branch,
67+
# facilitating cross-referencing of a pact between Pact Broker and GitHub.
68+
ref: ${{ github.head_ref || '' }}
69+
dry-run: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
70+
secrets: inherit
71+
2572
init-github-context:
2673
runs-on: ubuntu-latest
74+
needs: [ bump-check ]
75+
if: ${{ needs.bump-check.outputs.is-bump == 'no' }}
2776
outputs:
2877
repo-branch: ${{ steps.extract-branch.outputs.repo-branch }}
2978
repo-version: ${{ steps.extract-branch.outputs.repo-version }}
@@ -56,7 +105,8 @@ jobs:
56105
57106
wsm-consumer-contract-tests:
58107
runs-on: ubuntu-latest
59-
needs: [ init-github-context ]
108+
needs: [ bump-check, init-github-context ]
109+
if: ${{ needs.bump-check.outputs.is-bump == 'no' }}
60110
outputs:
61111
pact-b64: ${{ steps.encode-pact.outputs.pact-b64 }}
62112

@@ -77,15 +127,22 @@ jobs:
77127
78128
publish-contracts:
79129
runs-on: ubuntu-latest
80-
needs: [ init-github-context, wsm-consumer-contract-tests ]
130+
needs: [ bump-check, init-github-context, wsm-consumer-contract-tests, regulated-tag-job ]
131+
if: ${{ needs.bump-check.outputs.is-bump == 'no' }}
81132
steps:
82133
- name: Dispatch to terra-github-workflows
83-
uses: broadinstitute/workflow-dispatch@v3
134+
uses: broadinstitute/workflow-dispatch@v4.0.0
84135
with:
136+
run-name: "${{ env.PUBLISH_CONTRACTS_RUN_NAME }}"
85137
workflow: .github/workflows/publish-contracts.yaml
86138
repo: broadinstitute/terra-github-workflows
87139
ref: refs/heads/main
88140
token: ${{ secrets.BROADBOT_TOKEN }} # github token for access to kick off a job in the private repo
89-
inputs: '{ "pact-b64": "${{ needs.wsm-consumer-contract-tests.outputs.pact-b64 }}", "repo-owner": "${{ github.repository_owner }}", "repo-name": "${{ github.event.repository.name }}", "repo-branch": "${{ needs.init-github-context.outputs.repo-branch }}" }'
90-
91-
141+
inputs: '{
142+
"run-name": "${{ env.PUBLISH_CONTRACTS_RUN_NAME }}",
143+
"pact-b64": "${{ needs.wsm-consumer-contract-tests.outputs.pact-b64 }}",
144+
"repo-owner": "${{ github.repository_owner }}",
145+
"repo-name": "${{ github.event.repository.name }}",
146+
"repo-branch": "${{ needs.init-github-context.outputs.repo-branch }}",
147+
"release-tag": "${{ needs.regulated-tag-job.outputs.new-tag }}"
148+
}'

.github/workflows/tag.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Tag
2+
on:
3+
workflow_dispatch:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
description: "The branch, tag or SHA to checkout"
8+
default: ''
9+
required: false
10+
type: string
11+
dry-run:
12+
description: "Determine the next version without tagging the branch. The workflow can use the outputs new_tag and tag in subsequent steps. Possible values are true and false (default)"
13+
default: false
14+
required: false
15+
type: string
16+
print-tag:
17+
description: "Echo tag to console"
18+
default: true
19+
required: false
20+
type: string
21+
outputs:
22+
tag:
23+
description: "The value of the latest tag after running this action"
24+
value: ${{ jobs.tag-job.outputs.tag }}
25+
new-tag:
26+
description: "The value of the newly created tag"
27+
value: ${{ jobs.tag-job.outputs.new-tag }}
28+
secrets:
29+
BROADBOT_TOKEN:
30+
required: true
31+
32+
jobs:
33+
# On tag vs. new-tag.
34+
# The new-tag is always the tag resulting from a bump to the original tag.
35+
# However, the tag is by definition the value of the latest tag after running the action,
36+
# which might not change if dry run is used, and remains same as the original tag.
37+
tag-job:
38+
runs-on: ubuntu-latest
39+
outputs:
40+
tag: ${{ steps.tag.outputs.tag }}
41+
new-tag: ${{ steps.tag.outputs.new_tag }}
42+
steps:
43+
- name: Checkout current code
44+
uses: actions/checkout@v3
45+
with:
46+
ref: ${{ inputs.ref }}
47+
token: ${{ secrets.BROADBOT_TOKEN }} # this allows the push to succeed later
48+
- name: Bump the tag to a new version
49+
# https://github.com/DataBiosphere/github-actions/tree/master/actions/bumper
50+
uses: databiosphere/github-actions/actions/[email protected]
51+
id: tag
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.BROADBOT_TOKEN }}
54+
HOTFIX_BRANCHES: hotfix.*
55+
DEFAULT_BUMP: patch
56+
DRY_RUN: ${{ inputs.dry-run }}
57+
RELEASE_BRANCHES: main
58+
VERSION_FILE_PATH: settings.gradle
59+
VERSION_LINE_MATCH: "^\\s*gradle.ext.wsmVersion\\s*=\\s*\".*\""
60+
VERSION_SUFFIX: SNAPSHOT
61+
- name: Echo tag to console
62+
if: ${{ inputs.print-tag == 'true' }}
63+
run: |
64+
echo "Newly created version tag: '${{ steps.tag.outputs.new_tag }}'"
65+
echo "settings.gradle"
66+
echo "==============="
67+
cat settings.gradle

0 commit comments

Comments
 (0)