Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semantic release support #3

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: stefanzweifel/git-auto-commit-action@v5
if: always()
with:
commit_message: Run format
commit_message: 'ci: Format code'
commit_user_name: ${{ secrets.GIT_USER_NAME }}
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>
2 changes: 1 addition & 1 deletion .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Generate code
commit_message: 'ci: Generate code'
commit_user_name: ${{ secrets.GIT_USER_NAME }}
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,29 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact_name }}
path: pkg/
- name: Generate release notes
id: changelog
run: |
mkdir tmp
outfile=tmp/changelog.txt
echo "outfile=${outfile}" >> $GITHUB_OUTPUT
npx standard-changelog@^5.0.0 --release-count 2 --infile $outfile.tmp --outfile $outfile.tmp
sed '1,3d' $outfile.tmp > $outfile
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GH_TOKEN }}
fail_on_unmatched_files: true
prerelease: ${{ contains(github.ref_name, 'pre') }}
files: pkg/*
body_path: ${{ github.workspace }}/${{ steps.changelog.outputs.outfile }}
rubygems:
name: RubyGems.org
uses: ./.github/workflows/_publish.yml
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Semantic Release

run-name: Semantic Release from ${{ github.ref_name }}

on:
push:
branches:
- '**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
semantic:
name: Determine version
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
new_release_published: ${{ steps.release.outputs.new_release_published }}
new_release_version: ${{ steps.release.outputs.new_release_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Semantic release
id: release
uses: cycjimmy/semantic-release-action@v4
with:
dry_run: true
release:
name: Release version
runs-on: ubuntu-latest
timeout-minutes: 30
needs: semantic
if: needs.semantic.outputs.new_release_published == 'true' && needs.semantic.outputs.new_release_version != '1.0.0'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Release version ${{ needs.semantic.outputs.new_release_version }} on ${{ github.ref_name }}
run: gh workflow run version.yml --raw-field version=$VERSION --ref $BRANCH
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
VERSION: ${{ needs.semantic.outputs.new_release_version }}
BRANCH: ${{ github.ref_name }}
11 changes: 11 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{ "name": "beta", "prerelease": true },
{ "name": "alpha", "prerelease": true }
],
"plugins": ["@semantic-release/commit-analyzer"]
}
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ Bootstrap a new Ruby gem in five minutes or less.
- [Standard] Ruby style guide, linter, and formatter.
- Productive and fun testing with [RSpec].
- Code coverage reporting with [SimpleCov].
- Continuous testing and gem publishing with [GitHub Actions].
- Fully automated version management and package publishing with [semantic-release].
- Continuous checks and tests with [GitHub Actions].
- [Keep a CHANGELOG].
- Consistent coding with [EditorConfig].
- Badges from [Shields.io].
- Start coding instantly with [GitHub Codespaces].

[bundler]: https://bundler.io/
[editorconfig]: https://editorconfig.org/
[gem release]: https://github.com/svenfuchs/gem-release
[github actions]: https://github.com/features/actions
[github codespaces]: https://github.com/features/codespaces
[keep a changelog]: https://keepachangelog.com/
[rspec]: https://rspec.info/
[rubygems.org]: https://rubygems.org/
[ruby]: https://www.ruby-lang.org/
[rubygems.org]: https://rubygems.org/
[semantic-release]: https://semantic-release.gitbook.io/semantic-release/
[shields.io]: https://shields.io/
[simplecov]: https://github.com/simplecov-ruby/simplecov
[standard]: https://github.com/testdouble/standard
[gem release]: https://github.com/svenfuchs/gem-release

### Bootstrapping a new project

Expand Down Expand Up @@ -171,12 +175,30 @@ $ bundle install

### Publishing

Use [gem release] to release a new version.
New versions are created with [gem release].

#### Automatic

New versions are released automatically with [semantic-release]
as long as commits follow the [Angular Commit Message Conventions].

Publishing may be triggered using a [workflow_dispatch on GitHub Actions].
[Angular Commit Message Conventions]: https://semantic-release.gitbook.io/semantic-release/#commit-message-format
[semantic-release]: https://semantic-release.gitbook.io/

#### Manual

Publish a new version by triggering a [version workflow_dispatch on GitHub Actions].
The `version` input will be passed to the `--version` option of `gem bump`.

This may be done on the web or using the [GitHub CLI] with

```
$ gh workflow run version.yml --raw-field version=<version>
```

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

## GitHub Actions

Expand All @@ -190,7 +212,7 @@ These must be set manually.

### Secrets for Optional GitHub Actions

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

Expand Down
2 changes: 1 addition & 1 deletion makenew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ makenew () {
read -p '> GitHub user or organization name (my-user): ' mk_user
read -p '> GitHub repository name (my-repo): ' mk_repo

sed_delete README.md '10,96d'
sed_delete README.md '10,100d'
sed_insert README.md '10i' 'TODO'

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