Skip to content

Commit

Permalink
ci: Improve the Release Process Allowing to have Release Candidates (#3)
Browse files Browse the repository at this point in the history
* chore: Update semantic release configuration for improved clarity

Also add rc/* branch to allow to have prereleases before actually releasing.

Add cargo verify-project to ensure the project is in a good state.

Signed-off-by: Eden Reich <[email protected]>

* chore: Nitpicking - Update CI workflow syntax for improved readability

Signed-off-by: Eden Reich <[email protected]>

* ci: Enhance GitHub Actions release workflow with improved configuration and error handling

Signed-off-by: Eden Reich <[email protected]>

---------

Signed-off-by: Eden Reich <[email protected]>
  • Loading branch information
edenreich authored Feb 8, 2025
1 parent 265bdec commit b97e5da
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 77 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
name: CI

on:
push:
branches: ["main"]
branches:
- main
pull_request:
branches: ["main"]
branches:
- main

env:
CARGO_TERM_COLOR: always
Expand Down
46 changes: 35 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Release

on:
Expand All @@ -13,15 +14,26 @@ jobs:
runs-on: ubuntu-24.04
permissions:
contents: write
issues: write
pull-requests: write
outputs:
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
persist-credentials: false
ref: main

- name: Configure Git signing
run: |
echo "${{ secrets.BOT_GPG_PRIVATE_KEY }}" | gpg --import
git config --global user.signingkey ${{ secrets.BOT_GPG_KEY_ID }}
git config --global commit.gpgsign true
git config --global commit.signoff true
git config --global user.name 'GitHub Actions Bot'
git config --global user.email '[email protected]'
- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -40,36 +52,48 @@ jobs:
- name: Create a release if needed
id: semantic
env:
CI: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: "GitHub Actions Bot"
GIT_AUTHOR_EMAIL: "[email protected]"
GIT_COMMITTER_NAME: "GitHub Actions Bot"
GIT_COMMITTER_EMAIL: "[email protected]"
run: |
dry_run_output=$(semantic-release --dry-run 2>&1 || true)
# Create first release if not exists using gh cli - Initial Release Version 0.1.0
# This is an HACK because semantic release doesn't support versions under 1.0.0
# But if we already have a release then it respects it and start to increment from there
if ! gh release view 0.1.0 >/dev/null 2>&1; then
gh release create 0.1.0 --title "Initial Release" --notes "Initial Release" --target main
fi
# Run semantic-release in dry-run first to capture version
DRY_OUTPUT=$(semantic-release --dry-run 2>&1 || true)
# Check if there are no changes
if $(echo "$dry_run_output" | grep -q "no new version is released"); then
if $(echo "$DRY_OUTPUT" | grep -q "no new version is released"); then
echo "No new release needed"
echo "new_release_published=false" >> $GITHUB_OUTPUT
exit 0
fi
# Extract version from dry run output
version=$(echo "$dry_run_output" | grep -o "The next release version is [0-9]\+\.[0-9]\+\.[0-9]\+" | cut -d ' ' -f6)
if [ -z "$version" ]; then
VERSION=$(echo "$DRY_OUTPUT" | grep -o "The next release version is [0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?" | cut -d ' ' -f6)
if [ -z "$VERSION" ]; then
echo "Error: Could not determine version"
exit 1
fi
echo "new_release_version=$version" >> $GITHUB_OUTPUT
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT
# Run actual release
if semantic-release; then
echo "Release successful"
echo "Successfully released version $VERSION"
echo "new_release_published=true" >> $GITHUB_OUTPUT
else
echo "Release failed"
exit 1
fi
env:
CI: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
needs: github_release
Expand All @@ -79,7 +103,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: main
ref: ${{ github.ref }}

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
Expand Down
126 changes: 62 additions & 64 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -1,67 +1,65 @@
---
branches:
- main
tagFormat: ${version}
- { name: main, prerelease: false, channel: latest }
- { name: "rc/*", prerelease: rc, channel: rc }
verifyConditions:
- "@semantic-release/github"
- "@semantic-release/git"

plugins:
- [
"@semantic-release/commit-analyzer",
{
preset: "conventionalcommits",
releaseRules:
[
{ type: "feat", release: "minor" },
{ type: "impr", release: "patch" },
{ type: "refactor", release: "patch" },
{ type: "perf", release: "patch" },
{ type: "fix", release: "patch" },
{ type: "ci", release: "patch" },
{ type: "docs", release: "patch" },
{ type: "chore", release: "patch" },
{ type: "style", release: "patch" },
{ type: "test", release: "patch" },
{ type: "build", release: "patch" },
],
},
]
- [
"@semantic-release/release-notes-generator",
{
preset: "conventionalcommits",
presetConfig:
{
types:
[
{ type: "feat", section: "✨ Features" },
{ type: "impr", section: "πŸš€ Improvements" },
{ type: "refactor", section: "♻️ Improvements" },
{ type: "perf", section: "⚑️ Improvements" },
{ type: "fix", section: "πŸ› Bug Fixes" },
{ type: "ci", section: "πŸ‘· CI" },
{ type: "docs", section: "πŸ“š Documentation" },
{ type: "chore", section: "πŸ”§ Miscellaneous" },
{ type: "style", section: "🎨 Miscellaneous" },
{ type: "test", section: "βœ… Miscellaneous" },
{ type: "build", section: "πŸ“¦ Miscellaneous" },
],
},
},
]
- ["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" }]
- [
"@semantic-release/exec",
{
"prepareCmd": 'sed -i ''s/^version = .*$/version = "${nextRelease.version}"/'' Cargo.toml && cargo check',
},
]
- [
"@semantic-release/github",
{
"assets": ["CHANGELOG.md"],
"releasedLabels": ["released"],
"releaseNameTemplate": "πŸš€ Version ${nextRelease.version}",
},
]
- [
"@semantic-release/git",
{ "assets": ["CHANGELOG.md", "Cargo.lock", "Cargo.toml"] },
]
- - "@semantic-release/commit-analyzer"
- preset: "conventionalcommits"
releaseRules:
- { type: "feat", release: "minor" }
- { type: "impr", release: "patch" }
- { type: "refactor", release: "patch" }
- { type: "perf", release: "patch" }
- { type: "fix", release: "patch" }
- { type: "ci", release: "patch" }
- { type: "docs", release: "patch" }
- { type: "style", release: "patch" }
- { type: "test", release: "patch" }
- { type: "build", release: "patch" }
- { type: "chore", release: "patch", scope: "!release" }

- - "@semantic-release/release-notes-generator"
- preset: "conventionalcommits"
presetConfig:
types:
- { type: "feat", section: "✨ Features" }
- { type: "impr", section: "πŸš€ Improvements" }
- { type: "refactor", section: "♻️ Improvements" }
- { type: "perf", section: "⚑️ Improvements" }
- { type: "fix", section: "πŸ› Bug Fixes" }
- { type: "ci", section: "πŸ‘· CI" }
- { type: "docs", section: "πŸ“š Documentation" }
- { type: "chore", section: "πŸ”§ Miscellaneous" }
- { type: "style", section: "🎨 Miscellaneous" }
- { type: "test", section: "βœ… Miscellaneous" }
- { type: "build", section: "πŸ“¦ Miscellaneous" }

- - "@semantic-release/changelog"
- changelogFile: CHANGELOG.md
changelogTitle: "# Changelog\n\nAll notable changes to this project will be documented in this file."
verifyConditions: true

- - "@semantic-release/exec"
- verifyConditions: "cargo verify-project"
prepareCmd: 'sed -i ''s/^version = .*$/version = "${nextRelease.version}"/'' Cargo.toml && cargo check'

- - "@semantic-release/github"
- assets:
- CHANGELOG.md
releasedLabels: ["released"]
releaseNameTemplate: "πŸš€ Version ${nextRelease.version}"
successCommentCondition: "false"

- - "@semantic-release/git"
- assets:
- CHANGELOG.md
- Cargo.lock
- Cargo.toml
message: "chore(release): πŸ”– ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"

repositoryUrl: "https://github.com/inference-gateway/rust-sdk"
tagFormat: "${version}"

0 comments on commit b97e5da

Please sign in to comment.