-
-
Notifications
You must be signed in to change notification settings - Fork 24
380 lines (325 loc) · 13.2 KB
/
automated-release.yml
File metadata and controls
380 lines (325 loc) · 13.2 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
name: Automated Release Pipeline
on:
push:
branches:
- main
- master
paths-ignore:
- '**.md'
- 'docs/**'
- '.github/ISSUE_TEMPLATE/**'
- 'LICENSE'
- '.gitignore'
- '.editorconfig'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
jobs:
version-and-build:
name: Version and Build
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
package_version: ${{ steps.version.outputs.version }}
changelog: ${{ steps.version.outputs.changelog }}
should_release: ${{ steps.version.outputs.should_release }}
steps:
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5
with:
dotnet-version: 8.0.x
- name: Cache NuGet packages
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v4
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/Directory.Build.props') }}
restore-keys: |
nuget-${{ runner.os }}-
- name: Determine version from conventional commits
id: version
run: |
#!/bin/bash
set -e
echo "=== Automated Semantic Versioning from Conventional Commits ==="
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
CURRENT_VERSION=${LATEST_TAG#v}
echo "Current version: $CURRENT_VERSION"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
PATCH=${PATCH%%-*}
echo "Parsed version: $MAJOR.$MINOR.$PATCH"
if git rev-parse "$LATEST_TAG" >/dev/null 2>&1; then
COMMITS=$(git log "$LATEST_TAG..HEAD" --oneline --no-merges)
else
COMMITS=$(git log --oneline --no-merges)
fi
echo "=== Commits since last tag ==="
echo "$COMMITS"
echo "==========================="
BUMP_TYPE="none"
if echo "$COMMITS" | grep -iE "(BREAKING CHANGE:|BREAKING:|^[a-f0-9]+ [a-z]+(\(.*\))?!:)" > /dev/null; then
BUMP_TYPE="major"
echo "Found BREAKING CHANGE - will bump MAJOR version"
fi
if [ "$BUMP_TYPE" = "none" ] && echo "$COMMITS" | grep -iE "^[a-f0-9]+ feat(\(.*\))?:" > /dev/null; then
BUMP_TYPE="minor"
echo "Found feat: commits - will bump MINOR version"
fi
if [ "$BUMP_TYPE" = "none" ] && echo "$COMMITS" | grep -iE "^[a-f0-9]+ (fix|refactor|perf|docs)(\(.*\))?:" > /dev/null; then
BUMP_TYPE="patch"
echo "Found fix:/refactor:/perf:/docs: commits - will bump PATCH version"
fi
if [ "$BUMP_TYPE" = "none" ] && echo "$COMMITS" | grep -iE "^[a-f0-9]+ (add|implement|create|new) " > /dev/null; then
BUMP_TYPE="minor"
echo "Found Add/Implement/Create commits - will bump MINOR version"
fi
if [ "$BUMP_TYPE" = "none" ] && echo "$COMMITS" | grep -iE "^[a-f0-9]+ (fix|update|improve|enhance|resolve|patch|correct|repair) " > /dev/null; then
BUMP_TYPE="minor"
echo "Found Fix/Update/Improve commits - will bump MINOR version"
fi
case $BUMP_TYPE in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
echo "Bumping MAJOR: $CURRENT_VERSION -> $MAJOR.$MINOR.$PATCH"
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
echo "Bumping MINOR: $CURRENT_VERSION -> $MAJOR.$MINOR.$PATCH"
;;
patch)
PATCH=$((PATCH + 1))
echo "Bumping PATCH: $CURRENT_VERSION -> $MAJOR.$MINOR.$PATCH"
;;
none)
echo "No conventional commits found, no version bump"
echo "should_release=false" >> $GITHUB_OUTPUT
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "changelog=No release needed - no conventional commits found" >> $GITHUB_OUTPUT
exit 0
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "New version: $NEW_VERSION"
echo "=== Generating Changelog ==="
CHANGELOG=$(printf '## Changes in v%s\n\n' "$NEW_VERSION")
BREAKING=$(echo "$COMMITS" | grep -iE "BREAKING CHANGE:|BREAKING:" || true)
if [ -n "$BREAKING" ]; then
CHANGELOG+=$(printf '### Breaking Changes\n')
while IFS= read -r line; do
CHANGELOG+=$(printf '%s\n' "- ${line#* }")
done < <(echo "$BREAKING")
CHANGELOG+=$(printf '\n')
fi
FEATURES=$(echo "$COMMITS" | grep -iE "^[a-f0-9]+ feat(\(.*\))?:" || true)
if [ -n "$FEATURES" ]; then
CHANGELOG+=$(printf '### Features\n')
while IFS= read -r line; do
MSG=$(echo "$line" | sed -E 's/^[a-f0-9]+ feat(\(.*\))?: //')
CHANGELOG+=$(printf '%s\n' "- $MSG")
done < <(echo "$FEATURES")
CHANGELOG+=$(printf '\n')
fi
FIXES=$(echo "$COMMITS" | grep -iE "^[a-f0-9]+ fix(\(.*\))?:" || true)
if [ -n "$FIXES" ]; then
CHANGELOG+=$(printf '### Bug Fixes\n')
while IFS= read -r line; do
MSG=$(echo "$line" | sed -E 's/^[a-f0-9]+ fix(\(.*\))?: //')
CHANGELOG+=$(printf '%s\n' "- $MSG")
done < <(echo "$FIXES")
CHANGELOG+=$(printf '\n')
fi
PERF=$(echo "$COMMITS" | grep -iE "^[a-f0-9]+ perf(\(.*\))?:" || true)
if [ -n "$PERF" ]; then
CHANGELOG+=$(printf '### Performance Improvements\n')
while IFS= read -r line; do
MSG=$(echo "$line" | sed -E 's/^[a-f0-9]+ perf(\(.*\))?: //')
CHANGELOG+=$(printf '%s\n' "- $MSG")
done < <(echo "$PERF")
CHANGELOG+=$(printf '\n')
fi
REFACTOR=$(echo "$COMMITS" | grep -iE "^[a-f0-9]+ refactor(\(.*\))?:" || true)
if [ -n "$REFACTOR" ]; then
CHANGELOG+=$(printf '### Code Refactoring\n')
while IFS= read -r line; do
MSG=$(echo "$line" | sed -E 's/^[a-f0-9]+ refactor(\(.*\))?: //')
CHANGELOG+=$(printf '%s\n' "- $MSG")
done < <(echo "$REFACTOR")
CHANGELOG+=$(printf '\n')
fi
DOCS=$(echo "$COMMITS" | grep -iE "^[a-f0-9]+ docs(\(.*\))?:" || true)
if [ -n "$DOCS" ]; then
CHANGELOG+=$(printf '### Documentation\n')
while IFS= read -r line; do
MSG=$(echo "$line" | sed -E 's/^[a-f0-9]+ docs(\(.*\))?: //')
CHANGELOG+=$(printf '%s\n' "- $MSG")
done < <(echo "$DOCS")
CHANGELOG+=$(printf '\n')
fi
NEW_FEATURES=$(echo "$COMMITS" | grep -iE "^[a-f0-9]+ (add|implement|create|new) " | grep -viE "^[a-f0-9]+ (feat|fix|refactor|perf|docs)(\(.*\))?:") || true
if [ -n "$NEW_FEATURES" ]; then
CHANGELOG+=$(printf '### New Features\n')
while IFS= read -r line; do
MSG=$(echo "$line" | sed -E 's/^[a-f0-9]+ //')
CHANGELOG+=$(printf '%s\n' "- $MSG")
done < <(echo "$NEW_FEATURES")
CHANGELOG+=$(printf '\n')
fi
OTHER_FIXES=$(echo "$COMMITS" | grep -iE "^[a-f0-9]+ (fix|update|improve|enhance|resolve|patch|correct|repair) " | grep -viE "^[a-f0-9]+ (feat|fix|refactor|perf|docs)(\(.*\))?:") || true
if [ -n "$OTHER_FIXES" ]; then
CHANGELOG+=$(printf '### Bug Fixes & Improvements\n')
while IFS= read -r line; do
MSG=$(echo "$line" | sed -E 's/^[a-f0-9]+ //')
CHANGELOG+=$(printf '%s\n' "- $MSG")
done < <(echo "$OTHER_FIXES")
CHANGELOG+=$(printf '\n')
fi
echo "$CHANGELOG"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
echo "$CHANGELOG" > /tmp/changelog.txt
{
echo 'changelog<<EOF'
cat /tmp/changelog.txt
echo EOF
} >> $GITHUB_OUTPUT
- name: Restore dependencies
if: steps.version.outputs.should_release == 'true'
run: dotnet restore
- name: Build
if: steps.version.outputs.should_release == 'true'
run: dotnet build -c Release --no-restore
pack:
name: Pack NuGet
runs-on: ubuntu-latest
needs: version-and-build
timeout-minutes: 20
if: needs.version-and-build.outputs.should_release == 'true'
steps:
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Setup .NET
uses: actions/setup-dotnet@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5
with:
dotnet-version: 8.0.x
- name: Cache NuGet packages
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v4
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/Directory.Build.props') }}
restore-keys: |
nuget-${{ runner.os }}-
- name: Restore and Build
run: |
dotnet restore
dotnet build -c Release --no-restore
- name: Pack NuGet
run: |
if [ -f "src/OoplesFinance.YahooFinanceAPI.csproj" ]; then
dotnet pack src/OoplesFinance.YahooFinanceAPI.csproj -c Release -o out --no-build /p:PackageVersion=${{ needs.version-and-build.outputs.package_version }}
echo "Package created: OoplesFinance.YahooFinanceAPI.${{ needs.version-and-build.outputs.package_version }}.nupkg"
else
echo "Error: src/OoplesFinance.YahooFinanceAPI.csproj not found"
exit 1
fi
- name: Verify TFMs in package (net48, net8.0)
run: |
set -e
shopt -s nullglob
pkgs=(out/*.nupkg)
if [ ${#pkgs[@]} -eq 0 ]; then
echo "Error: No packages found in out/"
exit 1
fi
for pkg in "${pkgs[@]}"; do
echo "Inspecting $pkg"
files=$(unzip -Z1 "$pkg")
for tfm in net48 net8.0; do
if ! echo "$files" | grep -qE "^lib/${tfm}/.+\.dll$"; then
echo "Error: Missing ${tfm} lib in package"
exit 1
else
echo "Found ${tfm} in package"
fi
done
done
echo "All required TFMs verified successfully"
- name: Upload package artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v4
with:
name: nuget-package-${{ github.sha }}
path: out/*.nupkg
if-no-files-found: error
publish-nuget:
name: Publish to NuGet
runs-on: ubuntu-latest
needs: [version-and-build, pack]
timeout-minutes: 10
if: needs.version-and-build.outputs.should_release == 'true'
steps:
- name: Download package
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: nuget-package-${{ github.sha }}
path: out/
- name: Setup .NET
uses: actions/setup-dotnet@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5
with:
dotnet-version: 8.0.x
- name: Push to NuGet
run: |
shopt -s nullglob
pkgs=(out/*.nupkg)
if [ ${#pkgs[@]} -eq 0 ]; then
echo "Error: No .nupkg files found in out/ directory"
exit 1
fi
for pkg in "${pkgs[@]}"; do
echo "Publishing $pkg to NuGet..."
dotnet nuget push "$pkg" \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
done
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [version-and-build, publish-nuget]
timeout-minutes: 10
if: needs.version-and-build.outputs.should_release == 'true'
steps:
- name: Download package
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: nuget-package-${{ github.sha }}
path: out/
- name: List artifacts
run: ls -lah out/
- name: Create GitHub Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
with:
tag_name: v${{ needs.version-and-build.outputs.package_version }}
name: Release v${{ needs.version-and-build.outputs.package_version }}
body: ${{ needs.version-and-build.outputs.changelog }}
files: out/*.nupkg
draft: false
prerelease: false
make_latest: true
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}