Skip to content

Commit d03819b

Browse files
committed
Add semantic-release support
1 parent d326597 commit d03819b

File tree

7 files changed

+98
-7
lines changed

7 files changed

+98
-7
lines changed

.github/workflows/format.yml

+1-1
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

+1-1
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

+11
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: pkg/
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, 'pre') }}
3444
files: pkg/*
45+
body_path: ${{ github.workspace }}/${{ steps.changelog.outputs.outfile }}
3546
rubygems:
3647
name: RubyGems.org
3748
uses: ./.github/workflows/_publish.yml
+49
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' && needs.semantic.outputs.new_release_version != '1.0.0'
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 1
44+
- name: Release version ${{ needs.semantic.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

+11
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

+24-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Bootstrap a new Ruby gem in five minutes or less.
1717
- [Standard] Ruby style guide, linter, and formatter.
1818
- Productive and fun testing with [RSpec].
1919
- Code coverage reporting with [SimpleCov].
20-
- Continuous testing and gem publishing with [GitHub Actions].
20+
- Fully automated version management and package publishing with [semantic-release].
21+
- Continuous checks and tests with [GitHub Actions].
2122
- [Keep a CHANGELOG].
2223
- Consistent coding with [EditorConfig].
2324
- Badges from [Shields.io].
@@ -32,6 +33,7 @@ Bootstrap a new Ruby gem in five minutes or less.
3233
[rspec]: https://rspec.info/
3334
[ruby]: https://www.ruby-lang.org/
3435
[rubygems.org]: https://rubygems.org/
36+
[semantic-release]: https://semantic-release.gitbook.io/semantic-release/
3537
[shields.io]: https://shields.io/
3638
[simplecov]: https://github.com/simplecov-ruby/simplecov
3739
[standard]: https://github.com/testdouble/standard
@@ -173,12 +175,30 @@ $ bundle install
173175

174176
### Publishing
175177

178+
#### Automatic
179+
180+
New versions are released automatically with [semantic-release]
181+
as long as commits follow the [Angular Commit Message Conventions].
182+
183+
[Angular Commit Message Conventions]: https://semantic-release.gitbook.io/semantic-release/#commit-message-format
184+
[semantic-release]: https://semantic-release.gitbook.io/
185+
186+
#### Manual
187+
176188
Use [gem release] to release a new version.
177189

178-
Publishing may be triggered using a [workflow_dispatch on GitHub Actions].
190+
Publish a new version by triggering a [version workflow_dispatch on GitHub Actions].
191+
The `version` input will be passed as the first argument to [npm-version].
192+
193+
This may be done on the web or using the [GitHub CLI] with
194+
195+
```
196+
$ gh workflow run version.yml --raw-field version=<version>
197+
```
179198

180199
[gem release]: https://github.com/svenfuchs/gem-release
181-
[workflow_dispatch on github actions]: https://github.com/makenew/rbgem/actions?query=workflow%3Aversion
200+
[GitHub CLI]: https://cli.github.com/
201+
[version workflow_dispatch on GitHub Actions]: https://github.com/seamapi/javascript-http/actions?query=workflow%3Aversion
182202

183203
## GitHub Actions
184204

@@ -192,7 +212,7 @@ These must be set manually.
192212

193213
### Secrets for Optional GitHub Actions
194214

195-
The version and format GitHub actions
215+
The version, format, generate, and semantic-release GitHub actions
196216
require a user with write access to the repository.
197217
Set these additional secrets to enable the action:
198218

makenew.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ makenew () {
5858
read -p '> GitHub user or organization name (my-user): ' mk_user
5959
read -p '> GitHub repository name (my-repo): ' mk_repo
6060

61-
sed_delete README.md '10,98d'
61+
sed_delete README.md '10,100d'
6262
sed_insert README.md '10i' 'TODO'
6363

6464
find_replace "s/^ \"VERSION\" = \".*\"/ \"VERSION\" = \"0.0.0\"/g"

0 commit comments

Comments
 (0)