Repository navigation
308 lines (264 loc) · 11 KB
/
Copy pathrelease.yml
File metadata and controls
308 lines (264 loc) · 11 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
name: Release
on:
push:
branches: [ main ]
workflow_dispatch:
env:
DOTNET_VERSION: '10.0.x'
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Retain source and runtime
run: |
mkdir -p artifacts/qualification
git rev-parse HEAD > artifacts/qualification/source.txt
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Retain configured runtime
run: dotnet --info > artifacts/qualification/runtime.txt
- name: Extract version from Directory.Build.props
id: version
run: |
VERSION=$(grep -oPm1 "(?<=<Version>)[^<]+" Directory.Build.props)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version from Directory.Build.props: $VERSION"
- name: Restore dependencies
run: dotnet restore ManagedCode.TimeSeries.slnx
- name: Build
run: dotnet build ManagedCode.TimeSeries.slnx --configuration Release --no-restore
- name: Test and enforce collector coverage
run: bash scripts/coverage.sh artifacts/qualification
- name: Retain release qualification evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: timeseries-release-qualification-${{ github.run_id }}-${{ github.run_attempt }}
path: artifacts/qualification/
if-no-files-found: error
retention-days: 30
- name: Pack NuGet packages
run: dotnet pack ManagedCode.TimeSeries.slnx --configuration Release --no-build -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg --output ./artifacts
- name: Verify exact package pair and retain hashes
shell: bash
run: |
set -euo pipefail
version='${{ steps.version.outputs.version }}'
core="./artifacts/ManagedCode.TimeSeries.${version}.nupkg"
orleans="./artifacts/ManagedCode.TimeSeries.Orleans.${version}.nupkg"
shopt -s nullglob
packages=(./artifacts/*.nupkg)
if [[ ${#packages[@]} -ne 2 || ! -f "$core" || ! -f "$orleans" ]]; then
echo "Expected exactly the Core and Orleans package pair for ${version}." >&2
printf 'Found: %s\n' "${packages[@]}" >&2
exit 1
fi
sha256sum "$core" "$orleans" > artifacts/qualification/packages.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./artifacts/*.nupkg
retention-days: 5
- name: Retain exact release package hashes
uses: actions/upload-artifact@v4
with:
name: timeseries-release-package-receipt-${{ github.run_id }}-${{ github.run_attempt }}
path: artifacts/qualification/packages.sha256
if-no-files-found: error
retention-days: 30
publish-nuget:
name: Publish to NuGet
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
published: ${{ steps.publish.outputs.published }}
version: ${{ needs.build.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Download artifacts
uses: actions/download-artifact@v5
with:
name: nuget-packages
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to NuGet
id: publish
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
set -euo pipefail
version='${{ needs.build.outputs.version }}'
core="./artifacts/ManagedCode.TimeSeries.${version}.nupkg"
orleans="./artifacts/ManagedCode.TimeSeries.Orleans.${version}.nupkg"
shopt -s nullglob
packages=(./artifacts/*.nupkg)
if [[ ${#packages[@]} -ne 2 || ! -f "$core" || ! -f "$orleans" ]]; then
echo "Expected exactly the Core and Orleans package pair for ${version}." >&2
printf 'Found: %s\n' "${packages[@]}" >&2
exit 1
fi
mkdir -p artifacts/publish
git rev-parse HEAD > artifacts/publish/source.txt
dotnet --info > artifacts/publish/runtime.txt
sha256sum "$core" "$orleans" > artifacts/publish/packages.sha256
fresh=0
duplicates=0
for package in ./artifacts/*.nupkg; do
echo "Publishing $package..."
resultFile="artifacts/publish/$(basename "$package").log"
if RESULT=$(dotnet nuget push "$package" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
2>&1); then
echo "$RESULT"
printf '%s\n' "$RESULT" > "$resultFile"
if grep -Fq "Your package was pushed." <<< "$RESULT"; then
fresh=$((fresh + 1))
printf '%s\t%s\n' "$(basename "$package")" "fresh" >> artifacts/publish/outcomes.tsv
else
echo "NuGet returned an unrecognized successful response for $package." >&2
printf '%s\t%s\n' "$(basename "$package")" "provider-error" >> artifacts/publish/outcomes.tsv
exit 1
fi
else
echo "$RESULT" >&2
printf '%s\n' "$RESULT" > "$resultFile"
if grep -Eiq '409.*conflict|already exists' <<< "$RESULT"; then
duplicates=$((duplicates + 1))
printf '%s\t%s\n' "$(basename "$package")" "duplicate" >> artifacts/publish/outcomes.tsv
else
printf '%s\t%s\n' "$(basename "$package")" "provider-error" >> artifacts/publish/outcomes.tsv
echo "NuGet rejected $package." >&2
exit 1
fi
fi
done
if [[ $fresh -gt 0 && $duplicates -gt 0 ]]; then
echo "NuGet accepted a mixed fresh/duplicate package pair; no release will be created." >&2
exit 1
elif [[ $fresh -eq 2 && $duplicates -eq 0 ]]; then
echo "published=true" >> $GITHUB_OUTPUT
echo "Both intended packages were newly published."
elif [[ $fresh -eq 0 && $duplicates -eq 2 ]]; then
echo "published=false" >> $GITHUB_OUTPUT
echo "Both intended packages already exist; no new release will be created."
else
echo "Unexpected NuGet publish outcome counts: fresh=$fresh duplicates=$duplicates." >&2
exit 1
fi
- name: Retain NuGet publish outcomes
if: always()
uses: actions/upload-artifact@v4
with:
name: timeseries-nuget-publish-${{ github.run_id }}-${{ github.run_attempt }}
path: artifacts/publish/
if-no-files-found: error
retention-days: 30
create-release:
name: Create GitHub Release and Tag
needs: publish-nuget
runs-on: ubuntu-latest
if: needs.publish-nuget.outputs.published == 'true'
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download artifacts
uses: actions/download-artifact@v5
with:
name: nuget-packages
path: ./artifacts
- name: Create and push tag
id: create_tag
run: |
VERSION="${{ needs.publish-nuget.outputs.version }}"
TAG="v$VERSION"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "::error::Tag $TAG already exists; refusing to replace its release assets."
exit 1
fi
echo "Creating tag $TAG"
git tag -a "$TAG" -m "Release $VERSION"
git push origin "$TAG"
- name: Get previous tag
id: prev_tag
run: |
CURRENT_TAG="v${{ needs.publish-nuget.outputs.version }}"
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A1 "^$CURRENT_TAG$" | tail -n1 || echo "")
if [ "$PREVIOUS_TAG" = "$CURRENT_TAG" ] || [ -z "$PREVIOUS_TAG" ]; then
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -v "^$CURRENT_TAG$" | head -n1 || echo "")
fi
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
echo "Current tag: $CURRENT_TAG"
echo "Previous tag: $PREVIOUS_TAG"
- name: Generate release notes
id: release_notes
run: |
VERSION="${{ needs.publish-nuget.outputs.version }}"
CURRENT_TAG="v$VERSION"
PREVIOUS_TAG="${{ steps.prev_tag.outputs.previous_tag }}"
echo "# Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "Released on $(date +'%Y-%m-%d')" >> release_notes.md
echo "" >> release_notes.md
if [ -n "$PREVIOUS_TAG" ]; then
echo "## 📋 Changes since $PREVIOUS_TAG" >> release_notes.md
echo "" >> release_notes.md
echo "### ✨ Features" >> release_notes.md
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --grep="^feat" --grep="^feature" >> release_notes.md || true
echo "" >> release_notes.md
echo "### 🐛 Bug Fixes" >> release_notes.md
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --grep="^fix" --grep="^bugfix" >> release_notes.md || true
echo "" >> release_notes.md
echo "### 📚 Documentation" >> release_notes.md
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --grep="^docs" --grep="^doc" >> release_notes.md || true
echo "" >> release_notes.md
echo "### 🔧 Other Changes" >> release_notes.md
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --invert-grep --grep="^feat" --grep="^feature" --grep="^fix" --grep="^bugfix" --grep="^docs" --grep="^doc" >> release_notes.md || true
echo "" >> release_notes.md
else
echo "## 🎉 Initial Release" >> release_notes.md
echo "" >> release_notes.md
echo "### Recent Changes" >> release_notes.md
git log --pretty=format:"- %s (%h)" --max-count=20 >> release_notes.md
echo "" >> release_notes.md
fi
echo "" >> release_notes.md
echo "## 📦 NuGet Packages" >> release_notes.md
echo "" >> release_notes.md
for package in ./artifacts/*.nupkg; do
PACKAGE_NAME=$(basename "$package" .nupkg)
BASE_NAME=$(echo "$PACKAGE_NAME" | sed "s/\.$VERSION//")
echo "- [$BASE_NAME v$VERSION](https://www.nuget.org/packages/$BASE_NAME/$VERSION)" >> release_notes.md
done
echo "" >> release_notes.md
echo "---" >> release_notes.md
echo "*This release was automatically created by GitHub Actions*" >> release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.publish-nuget.outputs.version }}
name: v${{ needs.publish-nuget.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: false
files: ./artifacts/*.nupkg
overwrite_files: false
token: ${{ secrets.GITHUB_TOKEN }}