-
Notifications
You must be signed in to change notification settings - Fork 0
313 lines (266 loc) · 9.97 KB
/
release.yml
File metadata and controls
313 lines (266 loc) · 9.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
dry_run:
description: "Perform a dry run (no actual release)"
required: false
default: "true"
type: choice
options:
- "true"
- "false"
version:
description: "Version to release (optional, defaults to version in lib/whodunit/chronicles/version.rb)"
required: false
type: string
create_release:
description: "Create GitHub release"
required: false
default: "true"
type: choice
options:
- "true"
- "false"
env:
RUBY_VERSION: "3.4"
jobs:
validate:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
is_dry_run: ${{ steps.config.outputs.is_dry_run }}
should_create_release: ${{ steps.config.outputs.should_create_release }}
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- name: Configure release parameters
id: config
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "is_dry_run=${{ github.event.inputs.dry_run }}" >> $GITHUB_OUTPUT
echo "should_create_release=${{ github.event.inputs.create_release }}" >> $GITHUB_OUTPUT
else
echo "is_dry_run=false" >> $GITHUB_OUTPUT
echo "should_create_release=false" >> $GITHUB_OUTPUT
fi
- name: Get version
id: version
run: |
if [[ -n "${{ github.event.inputs.version }}" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=$(ruby -r ./lib/whodunit/chronicles/version.rb -e "puts Whodunit::Chronicles::VERSION")
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION"
- name: Validate version format
run: |
VERSION="${{ steps.version.outputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[a-zA-Z0-9]+)?(-[a-zA-Z0-9]+)?$ ]]; then
echo "❌ Invalid version format: $VERSION"
echo "Expected format: X.Y.Z, X.Y.Z.pre, or X.Y.Z-prerelease"
exit 1
fi
echo "✅ Version format is valid: $VERSION"
- name: Check if version already exists
run: |
VERSION="${{ steps.version.outputs.version }}"
if gem search "whodunit-chronicles" -a | grep -q "whodunit-chronicles ($VERSION)"; then
echo "❌ Version $VERSION already exists on RubyGems"
if [[ "${{ steps.config.outputs.is_dry_run }}" != "true" ]]; then
exit 1
else
echo "Continuing with dry run..."
fi
else
echo "✅ Version $VERSION is available"
fi
- name: Run full test suite
run: bundle exec rake test
- name: Run RuboCop
run: bundle exec rake rubocop
# - name: Check documentation coverage
# run: |
# bundle exec yard doc
# DOC_COVERAGE=$(bundle exec yard stats --list-undoc | grep "100.00% documented" || echo "incomplete")
# if [[ "$DOC_COVERAGE" != *"100.00% documented"* ]]; then
# echo "❌ Documentation coverage is not 100%"
# exit 1
# fi
# echo "✅ Documentation coverage is 100%"
build:
runs-on: ubuntu-latest
needs: validate
outputs:
gem_file: ${{ steps.build.outputs.gem_file }}
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- name: Update version if specified
if: github.event.inputs.version != ''
run: |
VERSION="${{ github.event.inputs.version }}"
sed -i "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/whodunit/chronicles/version.rb
echo "Updated version to: $VERSION"
- name: Build gem
id: build
run: |
bundle exec gem build whodunit-chronicles.gemspec
GEM_FILE=$(ls whodunit-chronicles-*.gem)
echo "gem_file=$GEM_FILE" >> $GITHUB_OUTPUT
echo "Built gem: $GEM_FILE"
# Show gem contents
echo "Gem contents:"
gem contents "$GEM_FILE" | head -20
# Show gem metadata
echo "Gem metadata:"
gem spec "$GEM_FILE" | grep -E "(name|version|summary|description|homepage)"
- name: Test gem installation
run: |
GEM_FILE="${{ steps.build.outputs.gem_file }}"
gem install "$GEM_FILE"
ruby -e "require 'whodunit-chronicles'; puts 'Gem loads successfully'; puts Whodunit::Chronicles::VERSION"
- name: Upload gem artifact
uses: actions/upload-artifact@v4
with:
name: gem-file
path: ${{ steps.build.outputs.gem_file }}
retention-days: 30
security_scan:
runs-on: ubuntu-latest
needs: [validate, build]
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- name: Download gem artifact
uses: actions/download-artifact@v4
with:
name: gem-file
- name: Security scan
run: |
# Install the built gem for scanning
GEM_FILE=$(ls whodunit-chronicles-*.gem)
gem install "$GEM_FILE"
# Run bundle audit
bundle exec bundle audit check --update || echo "Bundle audit completed"
echo "✅ Security scan completed"
publish_rubygems:
runs-on: ubuntu-latest
needs: [validate, build, security_scan]
if: needs.validate.outputs.is_dry_run == 'false'
environment:
name: release
url: https://rubygems.org/gems/whodunit-chronicles
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- name: Download gem artifact
uses: actions/download-artifact@v4
with:
name: gem-file
- name: Publish to RubyGems
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
mkdir -p ~/.gem
echo ":rubygems_api_key: $GEM_HOST_API_KEY" > ~/.gem/credentials
chmod 0600 ~/.gem/credentials
GEM_FILE=$(ls whodunit-chronicles-*.gem)
echo "Publishing $GEM_FILE to RubyGems..."
gem push "$GEM_FILE"
echo "✅ Successfully published to RubyGems"
create_github_release:
runs-on: ubuntu-latest
needs: [validate, build, security_scan]
if: needs.validate.outputs.should_create_release == 'true' && needs.validate.outputs.is_dry_run == 'false'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download gem artifact
uses: actions/download-artifact@v4
with:
name: gem-file
- name: Generate changelog
id: changelog
run: |
VERSION="${{ needs.validate.outputs.version }}"
# Extract changelog section for this version
if [[ -f CHANGELOG.md ]]; then
CHANGELOG_CONTENT=$(awk "/^## \[$VERSION\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md || echo "")
if [[ -z "$CHANGELOG_CONTENT" ]]; then
CHANGELOG_CONTENT="See [CHANGELOG.md](CHANGELOG.md) for details."
fi
else
CHANGELOG_CONTENT="Release notes for version $VERSION"
fi
# Save changelog to file (GitHub Actions has multiline output limitations)
echo "$CHANGELOG_CONTENT" > changelog.txt
echo "Generated changelog for version $VERSION"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.validate.outputs.version }}
release_name: Release v${{ needs.validate.outputs.version }}
body_path: changelog.txt
draft: false
prerelease: ${{ contains(needs.validate.outputs.version, '-') }}
- name: Upload gem to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ needs.build.outputs.gem_file }}
asset_name: ${{ needs.build.outputs.gem_file }}
asset_content_type: application/octet-stream
notify:
runs-on: ubuntu-latest
needs:
[validate, build, security_scan, publish_rubygems, create_github_release]
if: always()
steps:
- name: Release summary
run: |
VERSION="${{ needs.validate.outputs.version }}"
DRY_RUN="${{ needs.validate.outputs.is_dry_run }}"
echo "## Release Summary"
echo "- Version: $VERSION"
echo "- Dry Run: $DRY_RUN"
echo "- Validation: ${{ needs.validate.result }}"
echo "- Build: ${{ needs.build.result }}"
echo "- Security Scan: ${{ needs.security_scan.result }}"
if [[ "$DRY_RUN" == "false" ]]; then
echo "- RubyGems Publish: ${{ needs.publish_rubygems.result }}"
echo "- GitHub Release: ${{ needs.create_github_release.result }}"
if [[ "${{ needs.publish_rubygems.result }}" == "success" ]]; then
echo "✅ Successfully released version $VERSION to RubyGems!"
echo "📦 Install with: gem install whodunit-chronicles -v $VERSION"
else
echo "❌ Failed to publish to RubyGems"
fi
else
echo "🏃 Dry run completed successfully!"
echo "To perform actual release, run workflow with dry_run=false"
fi