Skip to content

Commit 4a57c29

Browse files
feat: Improve release process using github workflow (#18)
* Create release workflow * Add changelog * Add update to third-party license and remove publish job in ci.yml * update release to include .node files in github release * Update to author commits by github-actions bot * Use git-cliff for changelog * Add the changelog to the npm package * Change to commit from apix bot * Update checkout token Co-authored-by: Melanija Cvetic <[email protected]> --------- Co-authored-by: Melanija Cvetic <[email protected]>
1 parent fa2f55f commit 4a57c29

File tree

5 files changed

+312
-49
lines changed

5 files changed

+312
-49
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -290,54 +290,6 @@ jobs:
290290
with:
291291
github-token: ${{ secrets.GITHUB_TOKEN }}
292292
parallel-finished: true
293-
publish:
294-
name: Publish
295-
runs-on: ubuntu-latest
296-
permissions:
297-
contents: write
298-
id-token: write
299-
needs:
300-
- lint
301-
- test
302-
- test-macOS-windows-binding
303-
- test-linux-binding
304-
steps:
305-
- uses: actions/checkout@v5
306-
- name: Setup node
307-
uses: actions/setup-node@v4
308-
with:
309-
node-version: 22
310-
cache: yarn
311-
- name: Install dependencies
312-
run: yarn install
313-
- name: create npm dirs
314-
run: yarn napi create-npm-dirs
315-
- name: Download all artifacts
316-
uses: actions/download-artifact@v5
317-
with:
318-
path: artifacts
319-
- name: Move artifacts
320-
run: yarn artifacts
321-
- name: List packages
322-
run: ls -R ./npm
323-
shell: bash
324-
- name: Publish
325-
run: |
326-
npm config set provenance true
327-
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
328-
then
329-
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
330-
npm publish --access public
331-
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
332-
then
333-
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
334-
npm publish --tag next --access public
335-
else
336-
echo "Not a release, skipping publish"
337-
fi
338-
env:
339-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
340-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
341293
license-and-audit:
342294
runs-on: ubuntu-latest
343295
steps:

.github/workflows/release.yml

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to release (e.g., 1.0.0)'
8+
required: true
9+
type: string
10+
11+
env:
12+
DEBUG: napi:*
13+
APP_NAME: atlas-local
14+
MACOSX_DEPLOYMENT_TARGET: '10.13'
15+
16+
jobs:
17+
update-version:
18+
name: Update Version
19+
runs-on: ubuntu-latest
20+
outputs:
21+
version: ${{ steps.version.outputs.version }}
22+
steps:
23+
- name: Set Apix Bot token
24+
id: app-token
25+
uses: mongodb/apix-action/token@6c3fde402c21942fa46cde003f190c2b23c59530
26+
with:
27+
app-id: ${{ secrets.APIXBOT_APP_ID }}
28+
private-key: ${{ secrets.APIXBOT_APP_PEM }}
29+
- uses: actions/checkout@v5
30+
with:
31+
token: ${{ steps.app-token.outputs.token }}
32+
fetch-depth: 0
33+
- name: Setup node
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 22
37+
cache: yarn
38+
- name: Install Rust toolchain
39+
uses: dtolnay/rust-toolchain@stable
40+
with:
41+
toolchain: stable
42+
targets: x86_64-unknown-linux-gnu
43+
- name: Install dependencies
44+
run: yarn install
45+
- name: Install cargo tools for license verification
46+
run: |
47+
cargo install --locked --version 0.8.2 cargo-about
48+
- name: Update package.json version
49+
run: |
50+
npm version ${{ github.event.inputs.version }} --no-git-tag-version
51+
- name: Update Cargo.toml version
52+
run: |
53+
sed -i 's/^version = ".*"/version = "${{ github.event.inputs.version }}"/' Cargo.toml
54+
- name: Update third-party licenses
55+
run: |
56+
cargo about generate about.hbs > LICENSE-3RD-PARTY.txt
57+
- name: Generate changelog
58+
uses: orhun/git-cliff-action@v4
59+
with:
60+
config: cliff.toml
61+
args: --verbose
62+
env:
63+
OUTPUT: CHANGELOG.md
64+
GITHUB_REPO: ${{ github.repository }}
65+
- name: Build to update generated files
66+
run: yarn build --target x86_64-unknown-linux-gnu --use-napi-cross
67+
- name: Commit version changes
68+
run: |
69+
git config --global user.name "${{ steps.app-token.outputs.user-name }}"
70+
git config --global user.email "${{ steps.app-token.outputs.user-email }}"
71+
git add package.json Cargo.toml index.js index.d.ts CHANGELOG.md LICENSE-3RD-PARTY.txt
72+
git commit -m "${{ github.event.inputs.version }}"
73+
git push
74+
- name: Set version output
75+
id: version
76+
run: echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
77+
78+
build:
79+
name: Build Release
80+
needs: update-version
81+
strategy:
82+
fail-fast: false
83+
matrix:
84+
settings:
85+
- host: macos-latest
86+
target: x86_64-apple-darwin
87+
build: yarn build --target x86_64-apple-darwin
88+
- host: windows-latest
89+
build: yarn build --target x86_64-pc-windows-msvc
90+
target: x86_64-pc-windows-msvc
91+
- host: ubuntu-latest
92+
target: x86_64-unknown-linux-gnu
93+
build: yarn build --target x86_64-unknown-linux-gnu --use-napi-cross
94+
- host: macos-latest
95+
target: aarch64-apple-darwin
96+
build: yarn build --target aarch64-apple-darwin
97+
- host: ubuntu-latest
98+
target: aarch64-unknown-linux-gnu
99+
build: yarn build --target aarch64-unknown-linux-gnu --use-napi-cross
100+
runs-on: ${{ matrix.settings.host }}
101+
steps:
102+
- uses: actions/checkout@v5
103+
with:
104+
ref: main
105+
- name: Setup node
106+
uses: actions/setup-node@v4
107+
with:
108+
node-version: 22
109+
cache: yarn
110+
- name: Install Rust toolchain
111+
uses: dtolnay/rust-toolchain@stable
112+
with:
113+
toolchain: stable
114+
targets: ${{ matrix.settings.target }}
115+
- name: Cache cargo
116+
uses: actions/cache@v4
117+
with:
118+
path: |
119+
~/.cargo/registry/index/
120+
~/.cargo/registry/cache/
121+
~/.cargo/git/db/
122+
~/.napi-rs
123+
.cargo-cache
124+
target/
125+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
126+
- uses: mlugg/setup-zig@v2
127+
if: ${{ contains(matrix.settings.target, 'musl') }}
128+
with:
129+
version: 0.14.1
130+
- name: Install cargo-zigbuild
131+
uses: taiki-e/install-action@v2
132+
if: ${{ contains(matrix.settings.target, 'musl') }}
133+
env:
134+
GITHUB_TOKEN: ${{ github.token }}
135+
with:
136+
tool: cargo-zigbuild
137+
- name: Setup toolchain
138+
run: ${{ matrix.settings.setup }}
139+
if: ${{ matrix.settings.setup }}
140+
shell: bash
141+
- name: Install dependencies
142+
run: yarn install
143+
- name: Build
144+
run: ${{ matrix.settings.build }}
145+
shell: bash
146+
- name: Upload artifact
147+
uses: actions/upload-artifact@v4
148+
with:
149+
name: bindings-${{ matrix.settings.target }}
150+
path: |
151+
${{ env.APP_NAME }}.*.node
152+
${{ env.APP_NAME }}.*.wasm
153+
if-no-files-found: error
154+
155+
publish:
156+
name: Publish Release
157+
runs-on: ubuntu-latest
158+
permissions:
159+
contents: write
160+
id-token: write
161+
needs: [update-version, build]
162+
steps:
163+
- uses: actions/checkout@v5
164+
with:
165+
ref: main
166+
- name: Setup node
167+
uses: actions/setup-node@v4
168+
with:
169+
node-version: 22
170+
cache: yarn
171+
- name: Install dependencies
172+
run: yarn install
173+
- name: Create npm dirs
174+
run: yarn napi create-npm-dirs
175+
- name: Download all artifacts
176+
uses: actions/download-artifact@v5
177+
with:
178+
path: artifacts
179+
- name: Move artifacts
180+
run: yarn artifacts
181+
- name: List packages
182+
run: ls -R ./npm
183+
shell: bash
184+
- name: Create GitHub Release
185+
uses: softprops/action-gh-release@v2
186+
with:
187+
tag_name: v${{ needs.update-version.outputs.version }}
188+
name: Release v${{ needs.update-version.outputs.version }}
189+
files: artifacts/bindings-*/*.node
190+
env:
191+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
192+
- name: Publish to NPM
193+
run: |
194+
npm config set provenance true
195+
COMMIT_MSG=$(git log -1 --pretty=%B)
196+
if echo "$COMMIT_MSG" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$" > /dev/null;
197+
then
198+
echo "Publishing stable release to latest tag"
199+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
200+
npm publish --access public
201+
elif echo "$COMMIT_MSG" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+" > /dev/null;
202+
then
203+
echo "Publishing pre-release to next tag"
204+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
205+
npm publish --tag next --access public
206+
else
207+
echo "Invalid release tag format: '$COMMIT_MSG'"
208+
echo "Expected format: X.Y.Z or X.Y.Z-suffix"
209+
echo "Skipping publish"
210+
exit 0
211+
fi
212+
env:
213+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ The complete API documentation is available in the generated TypeScript definiti
7373

7474
Contributions are welcome! Please feel free to submit a Pull Request.
7575

76+
## Changelog
77+
78+
See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes.
79+
7680
## License
7781

7882
This project is licensed under the Apache License, Version 2.0 (see `LICENSE`). It also makes use of third-party libraries, which are distributed under their own respective licenses (see `LICENSE-3RD-PARTY.txt`).

cliff.toml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
5+
[changelog]
6+
# A Tera template to be rendered for each release in the changelog.
7+
# See https://keats.github.io/tera/docs/#introduction
8+
body = """
9+
{% if version %}\
10+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
11+
{% else %}\
12+
## [unreleased]
13+
{% endif %}\
14+
{% for group, commits in commits | group_by(attribute="group") %}
15+
### {{ group | striptags | trim | upper_first }}
16+
{% for commit in commits %}
17+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
18+
{% if commit.breaking %}[**breaking**] {% endif %}\
19+
{{ commit.message | upper_first }}\
20+
{% endfor %}
21+
{% endfor %}
22+
"""
23+
# Remove leading and trailing whitespaces from the changelog's body.
24+
trim = true
25+
# Render body even when there are no releases to process.
26+
render_always = true
27+
# An array of regex based postprocessors to modify the changelog.
28+
postprocessors = [
29+
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/$GITHUB_REPO/issues/${2}))" },
30+
]
31+
# render body even when there are no releases to process
32+
# render_always = true
33+
# output file path
34+
# output = "test.md"
35+
36+
[git]
37+
# Parse commits according to the conventional commits specification.
38+
# See https://www.conventionalcommits.org
39+
conventional_commits = true
40+
# Exclude commits that do not match the conventional commits specification.
41+
filter_unconventional = true
42+
# Require all commits to be conventional.
43+
# Takes precedence over filter_unconventional.
44+
require_conventional = false
45+
# Split commits on newlines, treating each line as an individual commit.
46+
split_commits = false
47+
# An array of regex based parsers to modify commit messages prior to further processing.
48+
commit_preprocessors = [
49+
# Replace issue numbers with link templates to be updated in `changelog.postprocessors`.
50+
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
51+
# Check spelling of the commit message using https://github.com/crate-ci/typos.
52+
# If the spelling is incorrect, it will be fixed automatically.
53+
#{ pattern = '.*', replace_command = 'typos --write-changes -' },
54+
]
55+
# Prevent commits that are breaking from being excluded by commit parsers.
56+
protect_breaking_commits = false
57+
# An array of regex based parsers for extracting data from the commit message.
58+
# Assigns commits to groups.
59+
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
60+
commit_parsers = [
61+
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
62+
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
63+
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
64+
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
65+
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
66+
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
67+
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
68+
{ message = "^chore\\(release\\): prepare for", skip = true },
69+
{ message = "^chore\\(deps.*\\)", skip = true },
70+
{ message = "^chore\\(pr\\)", skip = true },
71+
{ message = "^chore\\(pull\\)", skip = true },
72+
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
73+
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
74+
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
75+
{ message = ".*", group = "<!-- 10 -->💼 Other" },
76+
]
77+
# Exclude commits that are not matched by any commit parser.
78+
filter_commits = false
79+
# An array of link parsers for extracting external references, and turning them into URLs, using regex.
80+
link_parsers = [
81+
{ pattern = "#(\\d+)", href = "https://github.com/$GITHUB_REPO/issues/$1" }
82+
]
83+
# Include only the tags that belong to the current branch.
84+
use_branch_tags = false
85+
# Order releases topologically instead of chronologically.
86+
topo_order = false
87+
# Order releases topologically instead of chronologically.
88+
topo_order_commits = true
89+
# Order of commits in each group/release within the changelog.
90+
# Allowed values: newest, oldest
91+
sort_commits = "oldest"
92+
# Process submodules commits
93+
recurse_submodules = false

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"index.d.ts",
2222
"index.js",
2323
"LICENSE",
24-
"LICENSE-3RD-PARTY.txt"
24+
"LICENSE-3RD-PARTY.txt",
25+
"CHANGELOG.md"
2526
],
2627
"napi": {
2728
"binaryName": "atlas-local",

0 commit comments

Comments
 (0)