Skip to content

Commit 79d166f

Browse files
authored
Merge pull request #8241 from BitGo/VL-4566
feat: create GH releases when publishing
2 parents d853b1d + 294c57a commit 79d166f

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Version Bump Summary
2+
description: Generates a JSON summary of all packages bumped in the current commit, with their previous and current versions.
3+
4+
inputs:
5+
ref:
6+
description: Git commit SHA or ref to read tags from. Defaults to HEAD.
7+
required: false
8+
default: HEAD
9+
10+
outputs:
11+
json-file:
12+
description: Path to the JSON summary temp file.
13+
value: ${{ steps.summary.outputs.json-file }}
14+
text-file:
15+
description: Path to the text summary temp file.
16+
value: ${{ steps.summary.outputs.text-file }}
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Generate version bump summary
22+
id: summary
23+
shell: bash
24+
run: node ${{ github.action_path }}/index.js ${{ inputs.ref }}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const { execSync, execFileSync } = require("child_process");
2+
const fs = require("fs");
3+
const tmp = require("tmp");
4+
5+
const ref = process.argv[2] || "HEAD";
6+
7+
const newTags = execFileSync("git", ["tag", "--points-at", ref])
8+
.toString()
9+
.trim()
10+
.split("\n")
11+
.filter(Boolean);
12+
13+
const summary = newTags.map((tag) => {
14+
const atIndex = tag.lastIndexOf("@");
15+
const packageName = tag.slice(0, atIndex);
16+
const currentVersion = tag.slice(atIndex + 1);
17+
18+
const previousTags = execSync(
19+
`git tag --sort=-version:refname -l "${packageName}@*"`
20+
)
21+
.toString()
22+
.trim()
23+
.split("\n")
24+
.filter(Boolean);
25+
26+
const previousTag = previousTags.find((t) => t !== tag);
27+
const previousVersion = previousTag
28+
? previousTag.slice(previousTag.lastIndexOf("@") + 1)
29+
: null;
30+
31+
return { package: packageName, previousVersion, currentVersion };
32+
});
33+
34+
const jsonContent = JSON.stringify(summary, null, 2);
35+
const textContent = summary
36+
.map((entry) => {
37+
const prev = entry.previousVersion || "new";
38+
return `${entry.package}: ${prev} -> ${entry.currentVersion}`;
39+
})
40+
.join("\n");
41+
42+
console.log(textContent);
43+
44+
const jsonTmp = tmp.fileSync({ prefix: "version-bump-summary-", postfix: ".json" });
45+
fs.writeFileSync(jsonTmp.name, jsonContent + "\n");
46+
47+
const txtTmp = tmp.fileSync({ prefix: "version-bump-summary-", postfix: ".txt" });
48+
fs.writeFileSync(txtTmp.name, textContent + "\n");
49+
50+
const ghOutput = process.env.GITHUB_OUTPUT;
51+
if (ghOutput) {
52+
fs.appendFileSync(ghOutput, `json-file=${jsonTmp.name}\n`);
53+
fs.appendFileSync(ghOutput, `text-file=${txtTmp.name}\n`);
54+
}

.github/workflows/npmjs-release.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
default: false
1313

1414
permissions:
15-
contents: read
15+
contents: write
1616
id-token: write
1717
pull-requests: read
1818

@@ -177,10 +177,27 @@ jobs:
177177
run: |
178178
yarn lerna publish --sign-git-tag --sign-git-commit --include-merged-tags --conventional-commits --conventional-graduate --verify-access --yes
179179
180+
- name: Generate version bump summary
181+
id: version-bump-summary
182+
if: inputs.dry-run == false
183+
continue-on-error: true
184+
uses: ./.github/actions/version-bump-summary
185+
180186
- name: Extract published version
181187
if: inputs.dry-run == false
182188
id: extract-version
183189
run: |
184190
NEW_VERSION=$(jq -r '.version' ./modules/bitgo/package.json)
185191
echo "New version: $NEW_VERSION"
186192
echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
193+
194+
- name: Create GitHub release draft
195+
if: inputs.dry-run == false && steps.version-bump-summary.outcome == 'success'
196+
continue-on-error: true
197+
env:
198+
GH_TOKEN: ${{ secrets.BITGOBOT_PAT_TOKEN || github.token }}
199+
run: |
200+
gh release create "v${{ steps.extract-version.outputs.new-version }}" \
201+
--draft \
202+
--title "v${{ steps.extract-version.outputs.new-version }}" \
203+
--notes-file "${{ steps.version-bump-summary.outputs.text-file }}"

0 commit comments

Comments
 (0)