Skip to content

Commit 4ea43c4

Browse files
Copilotjkowalleck
andcommitted
feat: add version verification and secret validation to release workflow
Co-authored-by: jkowalleck <[email protected]>
1 parent a1e89e1 commit 4ea43c4

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

.github/RELEASE.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Release Process
2+
3+
This repository uses an automated release pipeline via GitHub Actions.
4+
5+
## How It Works
6+
7+
The release workflow (`.github/workflows/release.yml`) is triggered when a version tag is pushed to the repository. The workflow:
8+
9+
1. **Runs tests** - Ensures all tests pass before releasing
10+
2. **Builds the gem** - Creates the `.gem` package using `bundle exec rake build`
11+
3. **Generates checksums** - Creates SHA-512 checksums for the gem package
12+
4. **Creates GitHub Release** - Publishes a release on GitHub with the gem and checksums as artifacts
13+
5. **Publishes to RubyGems** - Automatically pushes the gem to [rubygems.org](https://rubygems.org)
14+
15+
## Triggering a Release
16+
17+
### For Stable Releases
18+
19+
1. Update the version in `lib/cyclonedx/ruby/version.rb`
20+
2. Update `CHANGELOG.md` with the changes
21+
3. Commit the changes: `git commit -am "🔖 Prepare release v1.2.0"`
22+
4. Create and push a tag: `git tag v1.2.0 && git push origin v1.2.0`
23+
24+
### For Prereleases
25+
26+
Prereleases follow the same process but use a tag with a prerelease identifier:
27+
28+
- Alpha: `git tag v1.3.0-alpha.1 && git push origin v1.3.0-alpha.1`
29+
- Beta: `git tag v1.3.0-beta.1 && git push origin v1.3.0-beta.1`
30+
- Release Candidate: `git tag v1.3.0-rc.1 && git push origin v1.3.0-rc.1`
31+
32+
Prereleases are automatically detected by the workflow and marked as "prerelease" on GitHub.
33+
34+
## Version Tag Format
35+
36+
- **Stable releases**: `v<MAJOR>.<MINOR>.<PATCH>` (e.g., `v1.2.0`)
37+
- **Prereleases**: `v<MAJOR>.<MINOR>.<PATCH>-<PRERELEASE>` (e.g., `v1.3.0-alpha.1`)
38+
39+
The version in the tag must match the version in `lib/cyclonedx/ruby/version.rb`.
40+
41+
## Required Secrets
42+
43+
The workflow requires the following GitHub repository secret to be configured:
44+
45+
### `RUBYGEMS_API_KEY`
46+
47+
This is your RubyGems API key for publishing gems. To set it up:
48+
49+
1. Generate an API key on [rubygems.org](https://rubygems.org/profile/edit):
50+
- Go to your profile → Edit Profile → API Keys
51+
- Create a new API key with "Push rubygem" scope
52+
53+
2. Add it to GitHub repository secrets:
54+
- Go to repository Settings → Secrets and variables → Actions
55+
- Click "New repository secret"
56+
- Name: `RUBYGEMS_API_KEY`
57+
- Value: Your RubyGems API key
58+
- Click "Add secret"
59+
60+
**Note**: The `publish` job only runs on the official repository (`CycloneDX/cyclonedx-ruby-gem`) to prevent accidental publishes from forks.
61+
62+
## Release Artifacts
63+
64+
Each release includes the following artifacts:
65+
66+
1. **Gem Package** (`cyclonedx-ruby-<version>.gem`) - The built Ruby gem
67+
2. **SHA-512 Checksum** (`cyclonedx-ruby-<version>.gem.sha512`) - Checksum for verification
68+
69+
These artifacts are attached to the GitHub Release and can be downloaded for verification.
70+
71+
## Monitoring Releases
72+
73+
- **GitHub Actions**: Check the [Actions tab](https://github.com/CycloneDX/cyclonedx-ruby-gem/actions) for workflow runs
74+
- **GitHub Releases**: View all releases in the [Releases section](https://github.com/CycloneDX/cyclonedx-ruby-gem/releases)
75+
- **RubyGems**: Check [rubygems.org/gems/cyclonedx-ruby](https://rubygems.org/gems/cyclonedx-ruby) for published versions
76+
77+
## Troubleshooting
78+
79+
### Release workflow fails on tests
80+
81+
The workflow will not create a release if tests fail. Fix the failing tests and push a new commit, then create the tag again.
82+
83+
### Gem fails to publish to RubyGems
84+
85+
Check that:
86+
- The `RUBYGEMS_API_KEY` secret is set correctly
87+
- The API key has the "Push rubygem" permission
88+
- The gem version doesn't already exist on RubyGems (versions cannot be overwritten)
89+
90+
### Prerelease not detected correctly
91+
92+
Ensure your tag follows the format `v<VERSION>-<PRERELEASE>` where `<PRERELEASE>` contains a hyphen or dot (e.g., `alpha.1`, `beta-2`, `rc.1`).

.github/workflows/release.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ jobs:
2626
id: version
2727
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
2828

29+
- name: Verify version matches code
30+
run: |
31+
TAG_VERSION="${{ steps.version.outputs.VERSION }}"
32+
CODE_VERSION=$(ruby -r ./lib/cyclonedx/ruby/version.rb -e 'puts Cyclonedx::Ruby::VERSION')
33+
echo "Tag version: $TAG_VERSION"
34+
echo "Code version: $CODE_VERSION"
35+
if [ "$TAG_VERSION" != "$CODE_VERSION" ]; then
36+
echo "::error::Version mismatch! Tag is v$TAG_VERSION but code version is $CODE_VERSION"
37+
exit 1
38+
fi
39+
2940
- name: Determine if prerelease
3041
id: prerelease
3142
run: |
@@ -79,6 +90,13 @@ jobs:
7990
ruby-version: '3.3'
8091
bundler-cache: true
8192

93+
- name: Check for RubyGems API key
94+
run: |
95+
if [ -z "${{ secrets.RUBYGEMS_API_KEY }}" ]; then
96+
echo "::error::RUBYGEMS_API_KEY secret is not set"
97+
exit 1
98+
fi
99+
82100
- name: Build gem
83101
run: bundle exec rake build
84102

0 commit comments

Comments
 (0)