Skip to content

Commit 868ac1e

Browse files
committed
Add semantic-release support
1 parent 472d20b commit 868ac1e

File tree

7 files changed

+78
-5
lines changed

7 files changed

+78
-5
lines changed

.github/workflows/format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: stefanzweifel/git-auto-commit-action@v5
3636
if: always()
3737
with:
38-
commit_message: Run format
38+
commit_message: 'ci: Format code'
3939
commit_user_name: ${{ secrets.GIT_USER_NAME }}
4040
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
4141
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>

.github/workflows/generate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Commit
3737
uses: stefanzweifel/git-auto-commit-action@v5
3838
with:
39-
commit_message: Generate code
39+
commit_message: 'ci: Generate code'
4040
commit_user_name: ${{ secrets.GIT_USER_NAME }}
4141
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
4242
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>

.github/workflows/publish.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,29 @@ jobs:
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
2325
- name: Download artifact
2426
uses: actions/download-artifact@v4
2527
with:
2628
name: ${{ needs.build.outputs.artifact_name }}
2729
path: .
30+
- name: Generate release notes
31+
id: changelog
32+
run: |
33+
mkdir tmp
34+
outfile=tmp/changelog.txt
35+
echo "outfile=${outfile}" >> $GITHUB_OUTPUT
36+
npx standard-changelog@^2.0.0 --release-count 2 --infile $outfile.tmp --outfile $outfile.tmp
37+
sed '1,3d' $outfile.tmp > $outfile
2838
- name: Create GitHub release
2939
uses: softprops/action-gh-release@v2
3040
with:
3141
token: ${{ secrets.GH_TOKEN }}
3242
fail_on_unmatched_files: true
3343
prerelease: ${{ contains(github.ref_name, '-') }}
3444
files: '*.tgz'
45+
body_path: ${{ github.workspace }}/${{ steps.changelog.outputs.outfile }}
3546
npm:
3647
name: npm
3748
uses: ./.github/workflows/_publish.yml
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: Semantic Release
3+
4+
run-name: Semantic Release from ${{ github.ref_name }}
5+
6+
on:
7+
push:
8+
branches:
9+
- '**'
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref_name }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
semantic:
17+
name: Determine version
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 30
20+
outputs:
21+
new_release_published: ${{ steps.release.outputs.new_release_published }}
22+
new_release_version: ${{ steps.release.outputs.new_release_version }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
- name: Semantic release
29+
id: release
30+
uses: cycjimmy/semantic-release-action@v4
31+
with:
32+
dry_run: true
33+
release:
34+
name: Release version
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 30
37+
needs: semantic
38+
if: ${{ needs.semantic.outputs.new_release_published == 'true' }}
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 1
44+
- name: Release version ${{ steps.release.outputs.new_release_version }} on ${{ github.ref_name }}
45+
run: gh workflow run version.yml --raw-field version=$VERSION --ref $BRANCH
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
48+
VERSION: ${{ needs.semantic.outputs.new_release_version }}
49+
BRANCH: ${{ github.ref_name }}

.releaserc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"branches": [
3+
"+([0-9])?(.{+([0-9]),x}).x",
4+
"main",
5+
"next",
6+
"next-major",
7+
{ "name": "beta", "prerelease": true },
8+
{ "name": "alpha", "prerelease": true }
9+
],
10+
"plugins": ["@semantic-release/commit-analyzer"]
11+
}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Bootstrap a new TypeScript module in five minutes or less.
1919
- [Prettier] code.
2020
- Futuristic debuggable unit testing with [AVA].
2121
- Code coverage reporting with [Istanbul] and [c8].
22-
- Continuous testing and package publishing with [GitHub Actions].
22+
- Fully automated version management and package publishing with [semantic-release].
23+
- Continuous checks and tests with [GitHub Actions].
2324
- [Keep a CHANGELOG].
2425
- Consistent coding with [EditorConfig].
2526
- Badges from [Shields.io].
@@ -35,6 +36,7 @@ Bootstrap a new TypeScript module in five minutes or less.
3536
[Node.js]: https://nodejs.org/
3637
[Prettier]: https://prettier.io/
3738
[Shields.io]: https://shields.io/
39+
[semantic-release]: https://semantic-release.gitbook.io/semantic-release/
3840
[TypeScript]: https://www.typescriptlang.org/
3941
[c8]: https://github.com/bcoe/c8
4042
[landlubber]: https://github.com/razor-x/landlubber
@@ -198,7 +200,7 @@ These must be set manually.
198200

199201
### Secrets for Optional GitHub Actions
200202

201-
The version and format GitHub actions
203+
The version, format, generate, and semantic-release GitHub actions
202204
require a user with write access to the repository.
203205
Set these additional secrets to enable the action:
204206

makenew.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ makenew () {
5757
read -p '> GitHub user or organization name (my-user): ' mk_user
5858
read -p '> GitHub repository name (my-repo): ' mk_repo
5959

60-
sed_delete README.md '10,103d'
60+
sed_delete README.md '10,105d'
6161
sed_insert README.md '10i' 'TODO'
6262

6363
find_replace "s/^ \"version\": \".*\"/ \"version\": \"0.0.0\"/g"

0 commit comments

Comments
 (0)