Skip to content

Commit 0c445c4

Browse files
committed
chore(shell-bson-parser): add publish release workflow
1 parent 7a3810c commit 0c445c4

2 files changed

Lines changed: 115 additions & 5 deletions

File tree

.github/workflows/publish.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Publish Release
2+
3+
on:
4+
push:
5+
branches:
6+
- esm
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
publish_package:
13+
if: startsWith(github.event.head_commit.message, 'release(')
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
id-token: write
18+
environment: release
19+
steps:
20+
- uses: actions/checkout@v6
21+
- name: Extract package name
22+
id: extract
23+
run: |
24+
COMMIT_MSG="${{ github.event.head_commit.message }}"
25+
# sed will get all between "release(" and "):"
26+
PACKAGE_NAME=$(echo "$COMMIT_MSG" | sed -n 's/^release(\([^)]*\)):.*/\1/p')
27+
28+
if [ -z "$PACKAGE_NAME" ]; then
29+
echo "Missing package name. Expected format: \"release(package-name):\""
30+
exit 1
31+
fi
32+
33+
echo "Package: $PACKAGE_NAME"
34+
echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
35+
- name: Install Node
36+
uses: actions/setup-node@v6
37+
with:
38+
node-version: 24
39+
registry-url: 'https://registry.npmjs.org'
40+
- name: Install dependencies & build
41+
working-directory: ./packages/${{ steps.extract.outputs.package_name }}
42+
run: yarn install && yarn build
43+
- name: Create NPM release
44+
working-directory: ./packages/${{ steps.extract.outputs.package_name }}
45+
run: npm publish --access public
46+
env:
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48+
- name: Create GitHub release
49+
uses: actions/github-script@v8
50+
with:
51+
script: |
52+
const { owner, repo } = context.repo
53+
54+
const { data: releases } = await github.rest.repos.listReleases({
55+
owner,
56+
repo
57+
})
58+
59+
const packageName = steps.extract.outputs.package_name
60+
const version = require(`./packages/${packageName}/package.json`).version
61+
const versionTag = `${packageName}-v${version}`
62+
63+
let releaseNotes = ''
64+
if (releases.length === 0) {
65+
releaseNotes = 'First release!'
66+
} else {
67+
// Get range of commits using the API (from the previous release to the current HEAD)
68+
const { data: comparison } = await github.rest.repos.compareCommits({
69+
owner,
70+
repo,
71+
base: releases[0].tag_name,
72+
head: context.sha
73+
})
74+
75+
const features = []
76+
const fixes = []
77+
const breaking =[]
78+
79+
// Split commits by standard Conventional Commits
80+
for (const { commit, sha } of comparison.commits) {
81+
const firstLine = commit.message.split('\n')[0].trim()
82+
const shortSha = sha.substring(0, 7)
83+
const entry = `- ${firstLine} (${shortSha})`
84+
85+
// Breaking Changes "!" before the colon, e.g. "feat!:"
86+
if (/^[a-zA-Z]+(?:\([^)]+\))?!:/.test(firstLine)) {
87+
breaking.push(entry)
88+
}
89+
// Features with prefix "feat:" or "feat(scope):"
90+
else if (/^feat(?:\([^)]+\))?:/.test(firstLine)) {
91+
features.push(entry)
92+
}
93+
// Bug Fixes with prefix "fix:" or "fix(scope):"
94+
else if (/^fix(?:\([^)]+\))?:/.test(firstLine)) {
95+
fixes.push(entry)
96+
}
97+
}
98+
99+
if (breaking.length > 0) releaseNotes += '### Breaking Changes\n' + breaking.join('\n') + '\n\n'
100+
if (features.length > 0) releaseNotes += '### Features\n' + features.join('\n') + '\n\n'
101+
if (fixes.length > 0) releaseNotes += '### Bug Fixes\n' + fixes.join('\n') + '\n\n'
102+
}
103+
104+
const defaultBranch = context.ref.replace('refs/heads/', '')
105+
106+
await github.rest.repos.createRelease({
107+
owner,
108+
repo,
109+
tag_name: versionTag,
110+
target_commitish: defaultBranch,
111+
name: versionTag,
112+
body: releaseNotes.trim()
113+
})
114+
115+
console.log(`Release ${versionTag} created`)

.npmrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)