Skip to content

Commit bf325b1

Browse files
committed
ci: add manual release action
1 parent b678707 commit bf325b1

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Manual Publish Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
commit-sha:
7+
description: 'The commit SHA to release from (e.g., 256e888 or full SHA)'
8+
required: true
9+
type: string
10+
dry-run:
11+
description: 'Dry run - validate without publishing'
12+
required: false
13+
type: boolean
14+
default: false
15+
16+
jobs:
17+
check-permissions:
18+
name: Check permissions
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check if user is in application-security team
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
const org = 'MetaMask';
26+
const team = 'application-security';
27+
const actor = context.actor;
28+
29+
try {
30+
const { data: membership } = await github.rest.teams.getMembershipForUserInOrg({
31+
org: org,
32+
team_slug: team,
33+
username: actor,
34+
});
35+
36+
if (membership.state === 'active') {
37+
console.log(`✓ User ${actor} is a member of @${org}/${team}`);
38+
} else {
39+
core.setFailed(`✗ User ${actor} is not an active member of @${org}/${team}`);
40+
}
41+
} catch (error) {
42+
if (error.status === 404) {
43+
core.setFailed(`✗ User ${actor} is not a member of @${org}/${team}`);
44+
} else {
45+
core.setFailed(`Error checking team membership: ${error.message}`);
46+
}
47+
}
48+
49+
validate-commit:
50+
needs: check-permissions
51+
name: Validate commit
52+
runs-on: ubuntu-latest
53+
outputs:
54+
FULL_SHA: ${{ steps.get-sha.outputs.FULL_SHA }}
55+
PACKAGE_NAME: ${{ steps.package-info.outputs.PACKAGE_NAME }}
56+
PACKAGE_VERSION: ${{ steps.package-info.outputs.PACKAGE_VERSION }}
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
with:
61+
fetch-depth: 0
62+
- name: Get full SHA
63+
id: get-sha
64+
run: |
65+
FULL_SHA=$(git rev-parse ${{ github.event.inputs.commit-sha }})
66+
if [ -z "$FULL_SHA" ]; then
67+
echo "Error: Could not resolve commit SHA: ${{ github.event.inputs.commit-sha }}"
68+
exit 1
69+
fi
70+
echo "FULL_SHA=$FULL_SHA" >> "$GITHUB_OUTPUT"
71+
echo "Resolved commit SHA: $FULL_SHA"
72+
- name: Checkout specific commit
73+
run: git checkout ${{ steps.get-sha.outputs.FULL_SHA }}
74+
- name: Show commit details
75+
run: |
76+
echo "Commit details:"
77+
git log -1 --pretty=format:"Author: %an <%ae>%nDate: %ad%nSubject: %s%nBody: %b" ${{ steps.get-sha.outputs.FULL_SHA }}
78+
- name: Get package info
79+
id: package-info
80+
run: |
81+
PACKAGE_NAME=$(jq -r '.name' package.json)
82+
PACKAGE_VERSION=$(jq -r '.version' package.json)
83+
echo "PACKAGE_NAME=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
84+
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
85+
echo "Package: $PACKAGE_NAME@$PACKAGE_VERSION"
86+
- name: Check for existing release
87+
run: |
88+
TAG="v${{ steps.package-info.outputs.PACKAGE_VERSION }}"
89+
if git rev-parse "$TAG" >/dev/null 2>&1; then
90+
echo "⚠️ Warning: Tag $TAG already exists"
91+
git log -1 --pretty=format:"Existing tag points to: %H%n" "$TAG"
92+
else
93+
echo "✓ Tag $TAG does not exist yet"
94+
fi
95+
96+
dry-run-summary:
97+
needs: validate-commit
98+
if: github.event.inputs.dry-run == 'true'
99+
name: Dry run summary
100+
runs-on: ubuntu-latest
101+
steps:
102+
- name: Display dry run summary
103+
run: |
104+
echo "## 🔍 Dry Run Summary"
105+
echo ""
106+
echo "**Mode:** Dry run (no changes will be made)"
107+
echo "**Package:** ${{ needs.validate-commit.outputs.PACKAGE_NAME }}@${{ needs.validate-commit.outputs.PACKAGE_VERSION }}"
108+
echo "**Commit:** ${{ needs.validate-commit.outputs.FULL_SHA }}"
109+
echo ""
110+
echo "✓ All validation checks passed"
111+
echo "ℹ️ To publish this release, run the workflow again with 'Dry run' unchecked"
112+
113+
publish-release:
114+
needs: validate-commit
115+
if: github.event.inputs.dry-run == 'false'
116+
name: Publish release
117+
permissions:
118+
contents: write
119+
uses: ./.github/workflows/publish-release.yml
120+
with:
121+
commit-sha: ${{ needs.validate-commit.outputs.FULL_SHA }}
122+
slack-icon-url: 'https://raw.githubusercontent.com/MetaMask/action-npm-publish/main/robo.png'
123+
slack-subteam: 'S042S7RE4AE'
124+
slack-username: 'MetaMask bot'
125+
secrets:
126+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/publish-release.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
required: false
1616
type: string
1717
default: 'MetaMask bot'
18+
commit-sha:
19+
required: false
20+
type: string
21+
description: 'Optional commit SHA to checkout for release'
1822
secrets:
1923
SLACK_WEBHOOK_URL:
2024
required: true
@@ -25,6 +29,8 @@ jobs:
2529
runs-on: ubuntu-latest
2630
steps:
2731
- uses: actions/checkout@v4
32+
with:
33+
ref: ${{ inputs.commit-sha || github.sha }}
2834
- id: name-hash
2935
name: Get Slack name and hash
3036
shell: bash
@@ -74,7 +80,7 @@ jobs:
7480
# This is to guarantee that the most recent tag is fetched, which we
7581
# need for updating the shorthand major version tag.
7682
fetch-depth: 0
77-
ref: ${{ github.sha }}
83+
ref: ${{ inputs.commit-sha || github.sha }}
7884
- name: Publish release
7985
uses: MetaMask/action-publish-release@v3
8086
id: publish-release

0 commit comments

Comments
 (0)