Skip to content

Commit 3eba8e4

Browse files
authored
chore: add a release workflow (#744)
1 parent f6c5881 commit 3eba8e4

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

.github/workflows/release.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches: [master]
6+
workflow_dispatch:
7+
8+
jobs:
9+
release-check:
10+
name: Check if version is published
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
shell: bash
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
22+
- name: Check if version is published
23+
id: check
24+
run: |
25+
currentVersion="$( node -e "console.log(require('./package.json').version)" )"
26+
isPublished="$( npm view @mapbox/node-pre-gyp versions --json | jq -c --arg cv "$currentVersion" 'any(. == $cv)' )"
27+
echo "published=$isPublished" >> "$GITHUB_OUTPUT"
28+
echo "currentVersion: $currentVersion"
29+
echo "isPublished: $isPublished"
30+
outputs:
31+
published: ${{ steps.check.outputs.published }}
32+
33+
publish:
34+
needs: release-check
35+
if: ${{ needs.release-check.outputs.published == 'false' }}
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: write
39+
defaults:
40+
run:
41+
shell: bash
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version: 22
49+
50+
- run: npm ci
51+
52+
- run: npm audit
53+
54+
- run: npm run lint
55+
56+
- run: npm run update-crosswalk # To support newer versions of Node.js
57+
58+
- run: npm run build --if-present
59+
60+
- run: npm test
61+
62+
- name: Get version
63+
id: package-version
64+
uses: martinbeentjes/[email protected]
65+
66+
- name: Prepare release changelog
67+
id: prepare_release
68+
run: |
69+
RELEASE_TYPE="$(node -e "console.log(require('semver').prerelease('${{ steps.package-version.outputs.current-version }}') ? 'prerelease' : 'regular')")"
70+
if [[ $RELEASE_TYPE == 'regular' ]]; then
71+
echo "prerelease=false" >> "$GITHUB_OUTPUT"
72+
else
73+
echo "prerelease=true" >> "$GITHUB_OUTPUT"
74+
fi
75+
76+
- name: Extract changelog for version
77+
run: |
78+
awk '/^##/ { p = 0 }; p == 1 { print }; $0 == "## ${{ steps.package-version.outputs.current-version }}" { p = 1 };' CHANGELOG.md > changelog_for_version.md
79+
cat changelog_for_version.md
80+
81+
- name: Publish to Github
82+
uses: ncipollo/release-action@v1
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
with:
86+
tag: v${{ steps.package-version.outputs.current-version }}
87+
name: v${{ steps.package-version.outputs.current-version }}
88+
bodyFile: changelog_for_version.md
89+
allowUpdates: true
90+
draft: false
91+
prerelease: ${{ steps.prepare_release.outputs.prerelease }}
92+
93+
- name: Publish to NPM (release)
94+
if: ${{ steps.prepare_release.outputs.prerelease == 'false' }}
95+
run: |
96+
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
97+
npm publish --access public
98+
env:
99+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
100+
101+
- name: Publish to NPM (prerelease)
102+
if: ${{ steps.prepare_release.outputs.prerelease == 'true' }}
103+
run: |
104+
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
105+
npm publish --tag next --access public
106+
env:
107+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

RELEASE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Instructions for making a release
2+
3+
1. Change the version number in `package.json`. Run the following command in the package root directory, replacing <update_type> with one of the semantic versioning release types (prerelease, prepatch, preminor, premajor, patch, minor, major):
4+
5+
```
6+
npm version <update_type> --preid pre --no-git-tag-version
7+
```
8+
9+
`--preid` specifies which suffix to use in the release such as `pre`, `next`, `beta`, `rc`, etc.
10+
11+
`prepatch`, `preminor`, and `premajor` start a new series of pre-releases while bumping the patch, minor, or major version. E.g. `premajor` with `--preid pre` would do a prerelease for a new major using the `-pre` suffix (i.e. it would be a new major with `-pre.0`)
12+
13+
You can use `prerelease` to bump the version for a new pre-release version. E.g. you could run `npm version prerelease --preid pre --no-git-tag-version` to go from `-pre.0` to `-pre.1`.
14+
15+
For regular versions, you can use `patch`, `minor`, or `major`. E.g. `npm version major --no-git-tag-version`.
16+
17+
2. Update the changelog, which can be found in `CHANGELOG.md`. The heading must match `## <VERSION>` exactly, or it will not be picked up. For example, for version 1.0.11:
18+
19+
```
20+
## 1.0.11
21+
```
22+
23+
3. Commit and push the changes. On push the release workflow will automaticlly check if the release has been published on npm. If the release has not yet been published, the workflow will update the abi crosswalk file and publish a new npm release.

0 commit comments

Comments
 (0)