Skip to content

Commit 8136978

Browse files
committed
ci: migrate releases to semantic-release
1 parent 4f5e569 commit 8136978

6 files changed

Lines changed: 12375 additions & 2622 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Semantic Pull Request
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- edited
7+
- opened
8+
- reopened
9+
- synchronize
10+
11+
permissions:
12+
contents: read
13+
pull-requests: read
14+
15+
jobs:
16+
validate-title:
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 5
19+
steps:
20+
- name: Validate pull request title
21+
uses: amannn/action-semantic-pull-request@01d5fd8a8ebb9aafe902c40c53f0f4744f7381eb
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
11
name: Release @doist/react-interpolate package
22

33
on:
4-
release:
5-
types: [created]
6-
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
77

88
permissions:
9-
# Enable the use of OIDC for trusted publishing and npm provenance
9+
contents: write
10+
issues: write
11+
pull-requests: write
1012
id-token: write
11-
# Enable the use of GitHub Packages registry
1213
packages: write
1314

15+
concurrency:
16+
group: ${{ github.workflow }}
17+
cancel-in-progress: false
18+
1419
jobs:
1520
publish:
1621
runs-on: ubuntu-latest
1722
timeout-minutes: 60
1823
steps:
24+
- name: Generate release bot token
25+
id: release-bot
26+
if: ${{ secrets.DOIST_RELEASE_BOT_ID != '' && secrets.DOIST_RELEASE_BOT_PRIVATE_KEY != '' }}
27+
uses: actions/create-github-app-token@v3
28+
with:
29+
app-id: ${{ secrets.DOIST_RELEASE_BOT_ID }}
30+
private-key: ${{ secrets.DOIST_RELEASE_BOT_PRIVATE_KEY }}
31+
permission-contents: write
32+
permission-issues: write
33+
permission-pull-requests: write
34+
1935
- name: Checkout repository
2036
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
39+
token: ${{ steps.release-bot.outputs.token || github.token }}
2140

2241
- name: Setup Node.js from .node-version
23-
uses: actions/setup-node@v3
42+
uses: actions/setup-node@v4
2443
with:
44+
cache: npm
2545
node-version-file: .node-version
46+
registry-url: https://registry.npmjs.org/
47+
scope: "@doist"
2648

2749
- name: Ensure npm 11.5.1 or later is installed
2850
run: npm install -g npm@latest
@@ -35,26 +57,39 @@ jobs:
3557
env:
3658
CI: true
3759

60+
- name: Test the codebase
61+
run: npm run test
62+
env:
63+
CI: true
64+
3865
- name: Build the codebase
3966
run: npm run build
4067

41-
- name: Publish to GitHub Package Registry
42-
uses: actions/setup-node@v3
43-
with:
44-
node-version-file: .node-version
45-
registry-url: https://npm.pkg.github.com/
46-
scope: "@doist"
47-
- run: npm publish
68+
- name: Publish package to npm registry
69+
id: semantic-release
70+
run: npx semantic-release
4871
env:
49-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
GITHUB_TOKEN: ${{ steps.release-bot.outputs.token || github.token }}
73+
GIT_AUTHOR_EMAIL: doistbot@users.noreply.github.com
74+
GIT_AUTHOR_NAME: Doist Bot
75+
GIT_COMMITTER_EMAIL: doistbot@users.noreply.github.com
76+
GIT_COMMITTER_NAME: Doist Bot
5077

51-
- name: Clear npm config between GitHub/npm registries
52-
run: rm -f $NPM_CONFIG_USERCONFIG
78+
- name: Clear npm config between registries
79+
if: ${{ steps.semantic-release.outputs.package-published == 'true' }}
80+
run: rm -f "$NPM_CONFIG_USERCONFIG"
5381

54-
- name: Publish to npm registry
55-
uses: actions/setup-node@v3
82+
- name: Setup GitHub Packages registry
83+
if: ${{ steps.semantic-release.outputs.package-published == 'true' }}
84+
uses: actions/setup-node@v4
5685
with:
86+
cache: npm
5787
node-version-file: .node-version
58-
registry-url: https://registry.npmjs.org/
88+
registry-url: https://npm.pkg.github.com/
5989
scope: "@doist"
60-
- run: npm publish --provenance --access public
90+
91+
- name: Publish package to GitHub Packages
92+
if: ${{ steps.semantic-release.outputs.package-published == 'true' }}
93+
run: npm publish
94+
env:
95+
NODE_AUTH_TOKEN: ${{ github.token }}

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,15 @@ import { SYNTAX_I18NEXT } from "react-interpolate"
215215

216216
# Releasing
217217

218-
A new version of @doist/react-interpolate is published both on npm and GitHub Package Registry whenever a new release on GitHub is created.
218+
Merges to `main` automatically trigger `semantic-release`.
219219

220-
To update the version in both `package.json` and `package-lock.json` run:
220+
The release workflow will:
221221

222-
```sh
223-
npm --no-git-tag-version version <major|minor|patch>
224-
```
222+
- determine the next version from Conventional Commits
223+
- update `package.json`, `package-lock.json`, and `CHANGELOG.md`
224+
- create the Git tag and GitHub release
225+
- publish `@doist/react-interpolate` to both npm and GitHub Packages
225226

226-
Once these changes have been pushed and merged, create a release on GitHub.
227+
This means there is no manual version bump and no manual GitHub release creation step anymore.
227228

228-
A GitHub Action will automatically perform all the necessary steps and will release the version number that's specified inside the `package.json`'s `version` field so make sure that the release tag reflects the version you want to publish.
229+
Because the repository uses squash-merge style commit messages, pull request titles must follow the [Conventional Commits specification](https://www.conventionalcommits.org/). CI validates this automatically.

0 commit comments

Comments
 (0)