Skip to content

Commit 3ace45e

Browse files
authored
Modify release workflow to preview changes through a PR (#825)
* Update release workflow to use PR for review and confirm * Update RELEASE.md
1 parent 6c0243e commit 3ace45e

File tree

4 files changed

+266
-246
lines changed

4 files changed

+266
-246
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
3+
name: Create Release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
release_type:
9+
description: Type of release
10+
required: true
11+
default: patch
12+
type: choice
13+
options:
14+
- major
15+
- minor
16+
- patch
17+
18+
jobs:
19+
test:
20+
name: Run tests
21+
uses: ./.github/workflows/test.yml
22+
23+
read-version:
24+
name: Read current version and calculate new version
25+
runs-on: ubuntu-latest
26+
outputs:
27+
current_version: ${{ steps.current_version.outputs.version }}
28+
new_version: ${{ steps.new_version.outputs.version }}
29+
steps:
30+
-
31+
name: Checkout
32+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
33+
-
34+
name: Set up Ruby
35+
uses: ruby/setup-ruby@v1.263.0
36+
with:
37+
ruby-version: "3.4"
38+
bundler-cache: true
39+
-
40+
name: Read current version
41+
id: current_version
42+
run: |
43+
current_version=$(ruby -e "require './lib/semian/version'; puts Semian::VERSION")
44+
echo "version=$current_version" >> $GITHUB_OUTPUT
45+
echo "Current version: $current_version"
46+
-
47+
name: Calculate new version
48+
id: new_version
49+
run: |
50+
chmod +x .github/scripts/calculate_version.sh
51+
.github/scripts/calculate_version.sh \
52+
"${{ steps.current_version.outputs.version }}" \
53+
"${{ github.event.inputs.release_type }}"
54+
55+
create-pr:
56+
name: Create pull request for version bump
57+
runs-on: ubuntu-latest
58+
needs: [test, read-version]
59+
permissions:
60+
contents: write
61+
pull-requests: write
62+
steps:
63+
-
64+
name: Checkout
65+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
66+
with:
67+
fetch-depth: 30
68+
fetch-tags: true
69+
-
70+
name: Set up Ruby
71+
uses: ruby/setup-ruby@v1.263.0
72+
with:
73+
ruby-version: "3.4"
74+
bundler-cache: true
75+
-
76+
name: Create changes
77+
env:
78+
BUNDLE_FROZEN: false
79+
run: |
80+
new_version="${{ needs.read-version.outputs.new_version }}"
81+
82+
# Create version file changes
83+
sed -i "s/VERSION = \".*\"/VERSION = \"$new_version\"/" lib/semian/version.rb
84+
85+
# Create Gemfile.lock changes
86+
bundle install
87+
88+
# Create CHANGELOG changes
89+
chmod +x .github/scripts/update_changelog.sh
90+
.github/scripts/update_changelog.sh \
91+
"${{ needs.read-version.outputs.new_version }}" \
92+
"${{ needs.read-version.outputs.current_version }}"
93+
-
94+
name: Create pull request
95+
env:
96+
GH_TOKEN: ${{ github.token }}
97+
run: |
98+
new_version="${{ needs.read-version.outputs.new_version }}"
99+
branch_name="release/v$new_version"
100+
101+
# Configure git
102+
git config --local user.email "action@github.com"
103+
git config --local user.name "GitHub Action"
104+
105+
# Create and checkout new branch
106+
git checkout -b "$branch_name"
107+
108+
# Add and commit changes
109+
git add lib/semian/version.rb Gemfile.lock CHANGELOG.md
110+
git commit -m "Bump version to $new_version" -m "Triggered by @${{ github.actor }}"
111+
112+
# Push the branch
113+
git push origin "$branch_name"
114+
115+
# Create pull request
116+
gh pr create \
117+
--title "Release v$new_version" \
118+
--body "Automated version bump to $new_version
119+
120+
This PR includes:
121+
- Updated version in \`lib/semian/version.rb\`
122+
- Updated \`Gemfile.lock\`
123+
- Updated \`CHANGELOG.md\`
124+
125+
**Release type:** ${{ github.event.inputs.release_type }}
126+
**Triggered by:** @${{ github.actor }}
127+
128+
After merging this PR, the **Publish Release** workflow will automatically \
129+
build the gem and publish it to GitHub releases." \
130+
--base main \
131+
--head "$branch_name"
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
3+
name: Publish Release
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
paths:
10+
- lib/semian/version.rb
11+
12+
jobs:
13+
check-version-bump:
14+
name: Check if this is a version bump
15+
runs-on: ubuntu-latest
16+
outputs:
17+
is_release: ${{ steps.check.outputs.is_release }}
18+
version: ${{ steps.version.outputs.version }}
19+
steps:
20+
-
21+
name: Checkout
22+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
with:
24+
fetch-depth: 2
25+
-
26+
name: Check if commit is version bump
27+
id: check
28+
run: |
29+
# Check if the commit message indicates a version bump
30+
commit_msg=$(git log -1 --pretty=%s)
31+
if [[ "$commit_msg" =~ ^"Bump version to" ]]; then
32+
echo "is_release=true" >> $GITHUB_OUTPUT
33+
echo "✅ Detected version bump commit: $commit_msg"
34+
else
35+
echo "is_release=false" >> $GITHUB_OUTPUT
36+
echo "❌ Not a version bump commit: $commit_msg"
37+
fi
38+
-
39+
name: Set up Ruby
40+
if: steps.check.outputs.is_release == 'true'
41+
uses: ruby/setup-ruby@v1.263.0
42+
with:
43+
ruby-version: "3.4"
44+
bundler-cache: true
45+
-
46+
name: Read version
47+
if: steps.check.outputs.is_release == 'true'
48+
id: version
49+
run: |
50+
version=$(ruby -e "require './lib/semian/version'; puts Semian::VERSION")
51+
echo "version=$version" >> $GITHUB_OUTPUT
52+
echo "Current version: $version"
53+
54+
build-and-release:
55+
name: Build gem and create GitHub release
56+
runs-on: ubuntu-latest
57+
needs: [check-version-bump]
58+
if: needs.check-version-bump.outputs.is_release == 'true'
59+
permissions:
60+
contents: write
61+
steps:
62+
-
63+
name: Checkout
64+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
65+
-
66+
name: Set up Ruby
67+
uses: ruby/setup-ruby@v1.263.0
68+
with:
69+
ruby-version: "3.4"
70+
bundler-cache: true
71+
-
72+
name: Create and push tag
73+
env:
74+
VERSION: ${{ needs.check-version-bump.outputs.version }}
75+
run: |
76+
git config --local user.email "action@github.com"
77+
git config --local user.name "GitHub Action"
78+
git tag "v$VERSION"
79+
git push origin "v$VERSION"
80+
echo "✅ Created and pushed tag v$VERSION"
81+
-
82+
name: Build C extension
83+
run: bundle exec rake build
84+
-
85+
name: Build gem
86+
run: |
87+
gem build semian.gemspec
88+
-
89+
name: Generate SHA512 checksum
90+
run: |
91+
for gem in semian-*.gem; do
92+
sha512sum "$gem" > "${gem}.sha512"
93+
done
94+
-
95+
name: Draft GitHub release
96+
env:
97+
GH_TOKEN: ${{ github.token }}
98+
VERSION: ${{ needs.check-version-bump.outputs.version }}
99+
run: |
100+
tag="v$VERSION"
101+
gh release create "$tag" \
102+
--title "$tag" \
103+
--generate-notes \
104+
--draft \
105+
semian-*.gem \
106+
semian-*.gem.sha512
107+
-
108+
name: Filter release PR commits
109+
env:
110+
GH_TOKEN: ${{ github.token }}
111+
VERSION: ${{ needs.check-version-bump.outputs.version }}
112+
run: |
113+
tag="v$VERSION"
114+
gh release view "$tag" --json body -q '.body' > temp_notes.md
115+
116+
# Filter out dependabot commits and the release PR itself
117+
grep -v -i "bump.*by.*dependabot" temp_notes.md | \
118+
grep -v -i "release v.*by.*@github-actions" > filtered_notes.md || true
119+
120+
echo "Filtered release notes:"
121+
cat filtered_notes.md
122+
-
123+
name: Publish release
124+
env:
125+
GH_TOKEN: ${{ github.token }}
126+
VERSION: ${{ needs.check-version-bump.outputs.version }}
127+
run: |
128+
tag="v$VERSION"
129+
gh release edit "$tag" \
130+
--notes-file filtered_notes.md \
131+
--draft=false
132+
echo "🚀 Published release $tag"

0 commit comments

Comments
 (0)