Skip to content
Open
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
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release

on:
push:
tags: ['v*']

permissions: {}

concurrency:
group: release
cancel-in-progress: false

jobs:
verify:
name: Verify and build gem
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
artifact-id: ${{ steps.upload.outputs.artifact-id }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- name: Verify tag is on master
run: git merge-base --is-ancestor HEAD origin/master
- uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0
with:
ruby-version: '3.4'
- name: Verify tag and version
run: test "$GITHUB_REF_NAME" = "v$(ruby -Ilib -rcommittee/version -e 'print Committee::VERSION')"
- run: bundle install
- run: bundle exec rake
- run: gem build committee.gemspec --output "$RUNNER_TEMP/committee.gem"
- name: Extract release notes
run: |
version="${GITHUB_REF_NAME#v}"
awk -v heading="## $version" '
$0 == heading || index($0, heading " ") == 1 { found = 1; next }
found && /^## / { exit }
found { print }
END { if (!found) exit 1 }
' CHANGELOG.md > "$RUNNER_TEMP/release-notes.md"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
id: upload
with:
name: release-${{ github.run_attempt }}
path: |
${{ runner.temp }}/committee.gem
${{ runner.temp }}/release-notes.md
if-no-files-found: error

publish:
name: Publish gem
needs: verify
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # Required for RubyGems trusted publishing.
steps:
- uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0
with:
ruby-version: '3.4'
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ needs.verify.outputs.artifact-id }}
path: ${{ runner.temp }}
- uses: rubygems/configure-rubygems-credentials@dc5a8d8553e6ee01fc26761a49e99e733d17954a # v2.1.0
- name: Publish through RubyGems trusted publishing
run: gem push "$RUNNER_TEMP/committee.gem"

github-release:
name: Create GitHub release
needs: [verify, publish]
runs-on: ubuntu-latest
permissions:
contents: write # Required to create the GitHub release.
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ needs.verify.outputs.artifact-id }}
path: ${{ runner.temp }}
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag --title "$GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/release-notes.md"
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,31 @@ bundle exec ruby -Ilib -Itest test/router_test.rb -n /prefix/

## Release

Before the first automated release, create a GitHub environment named `release`
and configure a [RubyGems trusted publisher](https://guides.rubygems.org/trusted-publishing/)
for the `committee` gem with owner `interagent`, repository `committee`, workflow
filename `release.yml`, and environment `release`.

1. Update the version in `lib/committee/version.rb` as appropriate for [semantic
versioning](http://semver.org) and add details to `CHANGELOG.md`.
2. Commit those changes. Use a commit message like `Bump version to 1.2.3`.
3. Run the `release` task:
2. Commit those changes and merge them into `master`. Use a commit message like
`Bump version to 1.2.3`.
3. From the updated `master` branch, create and push the matching version tag:

```
bundle exec rake release
git tag v1.2.3
git push origin v1.2.3
```

The release workflow verifies that the tagged commit is on `master` and that the
tag matches the gem version, then runs lint and tests and builds the gem. Separate
jobs publish that verified gem to RubyGems and create a GitHub release from the
matching version section in `CHANGELOG.md`.

If GitHub release creation fails after the gem has been published, rerun only the
failed GitHub release job. Rerunning the whole workflow would attempt to publish
the same gem version again.

## Tutorials

- [Validating requests and responses using OpenAPI specification with Committee](https://nicolasiensen.github.io/2022-04-18-validating-requests-and-responses-using-openapi-specification-with-committee/)
Loading