Merge pull request #3 from azu/update-homebrew-0.2.0 #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Release | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
description: 'Release type' | ||
required: true | ||
default: 'patch' | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | ||
with: | ||
node-version: '20' | ||
- name: Install semver CLI | ||
run: npm install -g semver | ||
- name: Get current version | ||
id: current_version | ||
run: | | ||
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/') | ||
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT | ||
echo "Current version: $CURRENT_VERSION" | ||
- name: Set release type | ||
id: release_type | ||
run: | | ||
RELEASE_TYPE="${{ github.event.inputs.release_type }}" | ||
echo "type=$RELEASE_TYPE" >> $GITHUB_OUTPUT | ||
echo "Release type: $RELEASE_TYPE" | ||
- name: Calculate new version | ||
id: new_version | ||
run: | | ||
CURRENT_VERSION="${{ steps.current_version.outputs.current }}" | ||
RELEASE_TYPE="${{ steps.release_type.outputs.type }}" | ||
NEW_VERSION=$(semver -i $RELEASE_TYPE $CURRENT_VERSION) | ||
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT | ||
echo "New version: $NEW_VERSION" | ||
- name: Update Cargo.toml | ||
run: | | ||
NEW_VERSION="${{ steps.new_version.outputs.new }}" | ||
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml | ||
echo "Updated Cargo.toml to version $NEW_VERSION" | ||
- name: Update CHANGELOG.md | ||
run: | | ||
NEW_VERSION="${{ steps.new_version.outputs.new }}" | ||
TODAY=$(date +%Y-%m-%d) | ||
# Get commits since last tag for changelog | ||
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | ||
if [ -n "$LAST_TAG" ]; then | ||
COMMITS=$(git log ${LAST_TAG}..HEAD --oneline --pretty=format:"- %s") | ||
else | ||
COMMITS=$(git log --oneline --pretty=format:"- %s" -10) | ||
fi | ||
# Insert new version section after "## [Unreleased]" | ||
sed -i "/## \[Unreleased\]/a\\ | ||
\\ | ||
## [$NEW_VERSION] - $TODAY\\ | ||
\\ | ||
### Changes\\ | ||
$COMMITS" CHANGELOG.md | ||
echo "Updated CHANGELOG.md" | ||
- name: Commit version bump | ||
run: | | ||
NEW_VERSION="${{ steps.new_version.outputs.new }}" | ||
git config --local user.email "action@github.com" | ||
git config --local user.name "GitHub Action" | ||
git add Cargo.toml CHANGELOG.md | ||
git commit -m "chore: release v$NEW_VERSION | ||
🤖 Generated with [Claude Code](https://claude.ai/code) | ||
Co-Authored-By: Claude <noreply@anthropic.com>" | ||
- name: Create and push tag | ||
run: | | ||
NEW_VERSION="${{ steps.new_version.outputs.new }}" | ||
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION" | ||
git push origin main | ||
git push origin "v$NEW_VERSION" | ||
- name: Trigger Homebrew update | ||
run: | | ||
NEW_VERSION="${{ steps.new_version.outputs.new }}" | ||
# Wait a moment for the release workflow to complete | ||
sleep 60 | ||
gh workflow run "Update Homebrew Formula" --field tag="v$NEW_VERSION" | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |