Skip to content

Commit f0f0f0e

Browse files
committed
Alert users about incomplete release PRs
Currently we use the `is-release` action to determine whether a commit merged to `main` is a release commit, and if so, we run the release workflow. A commit becomes a release commit when: - the root package version is bumped - the subject of the merged commit matches "Release X.Y.Z", "Release/X.Y.Z", or something similar However, oftentimes engineers will create a PR and bump some packages' versions but forget to bump the root version. When this PR is merged, the release workflow won't run — but by then it is too late, and the engineer is forced to revert the PR and recreate it correctly. This is painful. To prevent this, this commit replaces the `is-action` with a custom workflow that looks at three things: - whether the root package is bumped - whether the title of the release is well-formed - whether any of the packages in the monorepo have been bumped As before, this workflow runs when a release commit is merged, and the result is used to determine whether to run the release workflow. But now, this workflow also runs on each pull request and acts as a gate: - If the engineer bumps the root package but does not fulfill the other two requirements, then the workflow will fail and the PR will not be mergeable. - If the engineer does not bump the root package but fulfills one or both of the other two requirements, then the workflow will not fail, but it will show a warning so that the engineer can double-check. - (Pull requests that do not fulfill any of the three requirements will be ignored.)
1 parent 43a6816 commit f0f0f0e

File tree

5 files changed

+606
-32
lines changed

5 files changed

+606
-32
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,6 @@ jobs:
4040
needs: check-workflows
4141
uses: ./.github/workflows/lint-build-test.yml
4242

43-
is-release:
44-
name: Determine whether this is a release merge commit
45-
needs: lint-build-test
46-
if: github.event_name == 'push'
47-
runs-on: ubuntu-latest
48-
outputs:
49-
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
50-
steps:
51-
- id: is-release
52-
uses: MetaMask/action-is-release@dc4672b05e3b1d464cdaf783579b04a4e43f8b02
53-
with:
54-
commit-starts-with: 'Release [version],Release v[version],Release/[version],Release/v[version],Release `[version]`'
55-
56-
publish-release:
57-
name: Publish release
58-
needs: is-release
59-
if: needs.is-release.outputs.IS_RELEASE == 'true'
60-
permissions:
61-
contents: write
62-
uses: ./.github/workflows/publish-release.yml
63-
secrets:
64-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
65-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
66-
67-
create-update-issues:
68-
name: Create update issues
69-
needs: [is-release, publish-release]
70-
if: needs.is-release.outputs.IS_RELEASE == 'true'
71-
uses: ./.github/workflows/create-update-issues.yaml
72-
secrets:
73-
CORE_CREATE_UPDATE_ISSUES_TOKEN: ${{ secrets.CORE_CREATE_UPDATE_ISSUES_TOKEN }}
74-
7543
all-jobs-complete:
7644
name: All jobs complete
7745
runs-on: ubuntu-latest
@@ -97,3 +65,30 @@ jobs:
9765
if [[ $passed != "true" ]]; then
9866
exit 1
9967
fi
68+
69+
validate-release:
70+
name: Identify and validate release PR/commit
71+
needs:
72+
- analyse-code
73+
- lint-build-test
74+
uses: ./.github/workflows/validate-release.yml
75+
with:
76+
valid-release-title-patterns: 'Release [version],Release v[version],Release/[version],Release/v[version],Release \`[version]\`'
77+
78+
publish-release:
79+
name: Publish release
80+
needs: validate-release
81+
if: "github.event_name == 'push' && needs.validate-release.outputs.RELEASE_VALIDATION_RESULT == 'valid-release'"
82+
permissions:
83+
contents: write
84+
uses: ./.github/workflows/publish-release.yml
85+
secrets:
86+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
87+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
88+
89+
create-update-issues:
90+
name: Create update issues
91+
needs: publish-release
92+
uses: ./.github/workflows/create-update-issues.yaml
93+
secrets:
94+
CORE_CREATE_UPDATE_ISSUES_TOKEN: ${{ secrets.CORE_CREATE_UPDATE_ISSUES_TOKEN }}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Validate Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
valid-release-title-patterns:
7+
type: string
8+
description: "Validate that the name of the release commit or PR starts with a string in this comma-separated list. Use '[version]' to refer to the current release version."
9+
required: false
10+
outputs:
11+
RELEASE_VALIDATION_RESULT:
12+
description: The release validation result
13+
value: ${{ jobs.validate-release.outputs.RELEASE_VALIDATION_RESULT }}
14+
15+
jobs:
16+
validate-release:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
RELEASE_VALIDATION_RESULT: ${{ steps.validate-release.outputs.RELEASE_VALIDATION_RESULT }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
ref: ${{ github.sha }}
24+
# We need the latest commit and the one before it so we can compare them
25+
fetch-depth: 2
26+
- name: Validate release
27+
id: validate-release
28+
run: |
29+
case "$GITHUB_EVENT_NAME" in
30+
push)
31+
yarn ts-node scripts/validate-release.ts "$GITHUB_EVENT_NAME" "$GITHUB_EVENT_BEFORE" "$GITHUB_SHA" "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" "$VALID_RELEASE_TITLE_PATTERNS"
32+
;;
33+
pull_request)
34+
yarn ts-node scripts/validate-release.ts "$GITHUB_EVENT_NAME" "$GITHUB_BASE_REF" "$GITHUB_SHA" "$GITHUB_EVENT_PULL_REQUEST_TITLE" "$VALID_RELEASE_TITLE_PATTERNS"
35+
;;
36+
*)
37+
echo "Unknown GitHub event name: $GITHUB_EVENT_NAME"
38+
exit 1
39+
esac
40+
shell: bash
41+
env:
42+
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
43+
GITHUB_EVENT_HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
44+
GITHUB_EVENT_PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
45+
VALID_RELEASE_TITLE_PATTERNS: ${{ inputs.valid-release-title-patterns }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"ws@7.4.6": "^7.5.10"
5151
},
5252
"devDependencies": {
53+
"@actions/core": "^1.11.1",
5354
"@babel/core": "^7.23.5",
5455
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
5556
"@babel/preset-typescript": "^7.23.3",

0 commit comments

Comments
 (0)