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

ci: Improve the Release Process Allowing to have Release Candidates #3

Merged
merged 3 commits into from
Feb 8, 2025
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
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 'eden.reich@gmail.com'

- 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: "eden.reich@gmail.com"
GIT_COMMITTER_NAME: "GitHub Actions Bot"
GIT_COMMITTER_EMAIL: "eden.reich@gmail.com"
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}"