Skip to content

Commit bb92243

Browse files
authored
Merge pull request #8204 from BitGo/VL-4495
feat: port npmjs release workflow to public repo
2 parents b13c88f + 2eb4d1e commit bb92243

1 file changed

Lines changed: 186 additions & 0 deletions

File tree

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
name: BitGoJS Release
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
dry-run:
8+
description: |
9+
If true, only runs checks without performing the actual release
10+
type: boolean
11+
required: false
12+
default: false
13+
14+
permissions:
15+
contents: read
16+
id-token: write
17+
pull-requests: read
18+
19+
env:
20+
NX_NO_CLOUD: true
21+
NX_SKIP_NX_CACHE: true
22+
23+
jobs:
24+
get-release-context:
25+
name: Get release context
26+
runs-on: ${{ vars.BASE_RUNNER_TYPE || 'ubuntu-latest' }}
27+
timeout-minutes: 10
28+
outputs:
29+
last-release-tag: ${{ steps.get-release-info.outputs.last-release-tag }}
30+
last-release-sha: ${{ steps.get-release-info.outputs.last-release-sha }}
31+
current-master-sha: ${{ steps.get-release-info.outputs.current-master-sha }}
32+
commits-since-release: ${{ steps.get-release-info.outputs.commits-since-release }}
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v6
36+
with:
37+
ref: master
38+
fetch-depth: 0
39+
fetch-tags: true
40+
41+
- name: Get release information
42+
id: get-release-info
43+
run: |
44+
# Get the latest stable release tag
45+
LAST_RELEASE_TAG=$(git tag --sort=-version:refname | grep -E 'bitgo@[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
46+
47+
# Get the commit SHA for that release
48+
LAST_RELEASE_SHA=$(git rev-parse "$LAST_RELEASE_TAG^{}")
49+
50+
# Get the current master HEAD commit
51+
CURRENT_MASTER_SHA=$(git rev-parse HEAD)
52+
53+
# Count commits since last release
54+
COMMITS_SINCE_RELEASE=$(git log --oneline "${LAST_RELEASE_TAG}..HEAD" | wc -l)
55+
56+
# Verify we have commits to process
57+
if [ "$COMMITS_SINCE_RELEASE" -eq 0 ]; then
58+
echo "::error::No commits found since last release $LAST_RELEASE_TAG. Nothing to process."
59+
exit 1
60+
fi
61+
62+
# Output the information
63+
echo "Last release tag: $LAST_RELEASE_TAG"
64+
echo "Last release SHA: $LAST_RELEASE_SHA"
65+
echo "Current master SHA: $CURRENT_MASTER_SHA"
66+
echo "Commits since release: $COMMITS_SINCE_RELEASE"
67+
68+
# Set outputs
69+
{
70+
echo "last-release-tag=$LAST_RELEASE_TAG"
71+
echo "last-release-sha=$LAST_RELEASE_SHA"
72+
echo "current-master-sha=$CURRENT_MASTER_SHA"
73+
echo "commits-since-release=$COMMITS_SINCE_RELEASE"
74+
} >> "$GITHUB_OUTPUT"
75+
76+
echo "Commits to process:"
77+
git log --oneline "${LAST_RELEASE_TAG}..HEAD"
78+
79+
- name: Generate release commit summary
80+
run: |
81+
{
82+
echo "## Commits to be Released"
83+
echo ""
84+
echo "From ${{ steps.get-release-info.outputs.last-release-sha }} to ${{ steps.get-release-info.outputs.current-master-sha }}"
85+
echo ""
86+
} >> "$GITHUB_STEP_SUMMARY"
87+
88+
# Get commits excluding merge commits
89+
git log --oneline --no-merges "${{ steps.get-release-info.outputs.last-release-sha }}..${{ steps.get-release-info.outputs.current-master-sha }}" | while read -r line; do
90+
commit_hash=$(echo "$line" | cut -d' ' -f1)
91+
commit_msg=$(echo "$line" | cut -d' ' -f2-)
92+
93+
# Get full commit message to check for TICKET: pattern
94+
full_commit_msg=$(git log -1 --pretty=format:"%B" "$commit_hash")
95+
96+
# Extract Jira ticket from commit message (handles multiple patterns, case insensitive)
97+
# 1. Direct pattern in subject: VL-1234, CORE-567, etc.
98+
# 2. TICKET: VL-1234 pattern in body
99+
jira_ticket=$(echo "$full_commit_msg" | grep -oiE '(ticket:\s*)?[A-Z]+-[0-9]+' | sed 's/[Tt][Ii][Cc][Kk][Ee][Tt]:\s*//' | head -1)
100+
101+
if [[ -n "$jira_ticket" ]]; then
102+
jira_link="[$jira_ticket](https://bitgoinc.atlassian.net/browse/${jira_ticket})"
103+
echo "- \`$commit_hash\` $commit_msg - $jira_link" >> "$GITHUB_STEP_SUMMARY"
104+
else
105+
echo "- \`$commit_hash\` $commit_msg" >> "$GITHUB_STEP_SUMMARY"
106+
fi
107+
done
108+
109+
echo "" >> "$GITHUB_STEP_SUMMARY"
110+
111+
release-bitgojs:
112+
name: Release BitGoJS
113+
needs:
114+
- get-release-context
115+
runs-on: ${{ vars.BASE_RUNNER_TYPE || 'ubuntu-latest' }}
116+
timeout-minutes: 60
117+
environment: npmjs-release
118+
steps:
119+
- name: Checkout repository
120+
uses: actions/checkout@v6
121+
with:
122+
ref: ${{ needs.get-release-context.outputs.current-master-sha }}
123+
token: ${{ secrets.BITGOBOT_PAT_TOKEN || github.token }}
124+
fetch-depth: 0
125+
126+
- name: Configure GPG
127+
if: inputs.dry-run == false
128+
run: |
129+
echo "${{ secrets.BITGOBOT_GPG_PRIVATE_KEY }}" | gpg --batch --import
130+
git config --global user.signingkey 67A9A0B77F0BD445E45CC8B719828A304678A92F
131+
git config --global commit.gpgsign true
132+
git config --global user.email "bitgobot@bitgo.com"
133+
git config --global user.name "bitgobot"
134+
135+
- name: Configure npmrc
136+
if: inputs.dry-run == false
137+
env:
138+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
139+
run: |
140+
echo "engine-strict=true" > ~/.npmrc
141+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
142+
143+
- name: Setup Node.js with nvm
144+
uses: actions/setup-node@v6
145+
with:
146+
node-version-file: ".nvmrc"
147+
148+
- name: Test NPM authentication
149+
if: inputs.dry-run == false
150+
run: |
151+
npm whoami --registry https://registry.npmjs.org/
152+
153+
- name: Switch to rel/latest branch
154+
run: |
155+
git checkout rel/latest
156+
git pull origin rel/latest
157+
158+
- name: Merge master into rel/latest
159+
run: |
160+
echo "Merging master commit ${{ needs.get-release-context.outputs.current-master-sha }} into rel/latest"
161+
git merge ${{ needs.get-release-context.outputs.current-master-sha }} --no-edit
162+
163+
- name: Install dependencies
164+
run: |
165+
yarn install --frozen-lockfile
166+
167+
- name: Run yarn audit
168+
run: |
169+
yarn run audit-high
170+
171+
- name: Run dependency check
172+
run: |
173+
yarn check-deps
174+
175+
- name: Publish new version
176+
if: inputs.dry-run == false
177+
run: |
178+
yarn lerna publish --sign-git-tag --sign-git-commit --include-merged-tags --conventional-commits --conventional-graduate --verify-access --yes
179+
180+
- name: Extract published version
181+
if: inputs.dry-run == false
182+
id: extract-version
183+
run: |
184+
NEW_VERSION=$(jq -r '.version' ./modules/bitgo/package.json)
185+
echo "New version: $NEW_VERSION"
186+
echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)