1+ ---
2+
3+ name : 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+ 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+ update-version :
56+ name : Update version file and create tag
57+ runs-on : ubuntu-latest
58+ needs : [test, read-version]
59+ permissions :
60+ contents : write
61+ env :
62+ BUNDLE_FROZEN : false
63+ steps :
64+ -
65+ name : Checkout
66+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
67+ with :
68+ fetch-depth : 30
69+ fetch-tags : true
70+ -
71+ name : Set up Ruby
72+ 73+ with :
74+ ruby-version : " 3.4"
75+ bundler-cache : true
76+ -
77+ name : Update version file
78+ run : |
79+ new_version="${{ needs.read-version.outputs.new_version }}"
80+ sed -i "s/VERSION = \".*\"/VERSION = \"$new_version\"/" lib/semian/version.rb
81+ echo "Updated version file:"
82+ cat lib/semian/version.rb
83+ -
84+ name : Update Gemfile.lock
85+ run : |
86+ # Update Gemfile.lock with new version
87+ bundle install
88+ -
89+ name : Update CHANGELOG
90+ run : |
91+ chmod +x .github/scripts/update_changelog.sh
92+ .github/scripts/update_changelog.sh \
93+ "${{ needs.read-version.outputs.new_version }}" \
94+ "${{ needs.read-version.outputs.current_version }}"
95+ -
96+ name : Commit and tag version
97+ run : |
98+ new_version="${{ needs.read-version.outputs.new_version }}"
99+ git config --local user.email "[email protected] " 100+ git config --local user.name "GitHub Action"
101+ git add lib/semian/version.rb Gemfile.lock CHANGELOG.md
102+ git commit -m "Bump version to $new_version" -m "Triggered by @${{ github.actor }}"
103+ git tag "v$new_version"
104+ git push origin main
105+ git push origin "v$new_version"
106+
107+ build-and-release :
108+ name : Build gem and create GitHub release
109+ runs-on : ubuntu-latest
110+ needs : [update-version, read-version]
111+ permissions :
112+ contents : write
113+ steps :
114+ -
115+ name : Checkout
116+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
117+ with :
118+ # Uses main branch to get the updated version after the commit
119+ ref : main
120+ -
121+ name : Set up Ruby
122+ 123+ with :
124+ ruby-version : " 3.4"
125+ bundler-cache : true
126+ -
127+ name : Build C extension
128+ run : bundle exec rake build
129+ -
130+ name : Build gem
131+ run : |
132+ gem build semian.gemspec
133+ -
134+ name : Generate SHA512 checksum
135+ run : |
136+ for gem in semian-*.gem; do
137+ sha512sum "$gem" > "${gem}.sha512"
138+ done
139+ -
140+ name : Draft GitHub release
141+ env :
142+ GH_TOKEN : ${{ github.token }}
143+ run : |
144+ tag="v${{ needs.read-version.outputs.new_version }}"
145+ gh release create "$tag" \
146+ --title "$tag" \
147+ --generate-notes \
148+ --draft \
149+ semian-*.gem \
150+ semian-*.gem.sha512
151+ -
152+ name : Filter dependabot commits
153+ env :
154+ GH_TOKEN : ${{ github.token }}
155+ run : |
156+ tag="v${{ needs.read-version.outputs.new_version }}"
157+ gh release view "$tag" --json body -q '.body' > temp_notes.md
158+ grep -v -i "bump.*by.*dependabot" temp_notes.md > filtered_notes.md || true
159+ -
160+ name : Publish release
161+ env :
162+ GH_TOKEN : ${{ github.token }}
163+ run : |
164+ tag="v${{ needs.read-version.outputs.new_version }}"
165+ gh release edit "$tag" \
166+ --notes-file filtered_notes.md \
167+ --draft=false
168+
169+
0 commit comments