-
Notifications
You must be signed in to change notification settings - Fork 1
238 lines (206 loc) · 9.61 KB
/
Copy pathrelease.yml
File metadata and controls
238 lines (206 loc) · 9.61 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
name: Release and Publish
on:
push:
branches:
- master
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.0.0
with:
versionSpec: '6.0.0'
- name: Determine Version
id: gitversion
shell: bash
run: |
MAJOR_MINOR_PATCH=$(dotnet gitversion /output json /showvariable MajorMinorPatch)
PRE_RELEASE_LABEL=$(dotnet gitversion /output json /showvariable PreReleaseLabel)
VERSION=$(dotnet gitversion /output json /showvariable SemVer)
SAFE_VERSION=$(echo "$VERSION" | sed -E 's/[^A-Za-z0-9._+-]+/-/g')
echo "MAJOR_MINOR_PATCH=$MAJOR_MINOR_PATCH" >> $GITHUB_ENV
echo "PRE_RELEASE_LABEL=$PRE_RELEASE_LABEL" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION_SAFE=$SAFE_VERSION" >> $GITHUB_ENV
- name: Set Release Channel
id: release_channel
shell: bash
run: |
if [ "${GITHUB_REF}" = "refs/heads/master" ]; then
echo "channel=stable" >> $GITHUB_OUTPUT
echo "prerelease=false" >> $GITHUB_OUTPUT
echo "draft=true" >> $GITHUB_OUTPUT
echo "label=Release" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_REF}" == refs/heads/release/* || "${GITHUB_REF}" == refs/heads/hotfix/* ]]; then
echo "channel=rc" >> $GITHUB_OUTPUT
echo "prerelease=true" >> $GITHUB_OUTPUT
echo "draft=true" >> $GITHUB_OUTPUT
echo "label=RC" >> $GITHUB_OUTPUT
elif [ "${GITHUB_REF}" = "refs/heads/develop" ]; then
echo "channel=beta" >> $GITHUB_OUTPUT
echo "prerelease=true" >> $GITHUB_OUTPUT
echo "draft=true" >> $GITHUB_OUTPUT
echo "label=Beta" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_REF}" == refs/heads/feature/* ]]; then
echo "channel=alpha" >> $GITHUB_OUTPUT
echo "prerelease=true" >> $GITHUB_OUTPUT
echo "draft=false" >> $GITHUB_OUTPUT
echo "label=Alpha" >> $GITHUB_OUTPUT
else
echo "channel=none" >> $GITHUB_OUTPUT
echo "prerelease=false" >> $GITHUB_OUTPUT
echo "draft=false" >> $GITHUB_OUTPUT
echo "label=" >> $GITHUB_OUTPUT
fi
- name: Validate releasable branch
if: steps.release_channel.outputs.channel == 'none'
shell: bash
run: |
echo "::error::Releases are only supported from master, develop, feature/*, release/*, and hotfix/* branches."
exit 1
- name: Validate NuGet version channel
if: steps.release_channel.outputs.channel != 'none'
shell: bash
run: |
if [ "${GITHUB_REF}" = "refs/heads/master" ]; then
if [[ "${VERSION}" == *-* ]]; then
echo "::error::Master releases must produce a stable NuGet version, but GitVersion returned '${VERSION}'."
exit 1
fi
exit 0
fi
if [[ "${VERSION}" != *-* ]]; then
echo "::error::Non-master releases must produce a prerelease NuGet version, but GitVersion returned '${VERSION}'."
exit 1
fi
- name: Restore dependencies
run: dotnet restore --artifacts-path=/tmp/artifacts/blazor-hashrouting
- name: Build
run: dotnet build --configuration Release --no-restore --artifacts-path=/tmp/artifacts/blazor-hashrouting
- name: Run tests
run: dotnet test --configuration Release --no-build --artifacts-path=/tmp/artifacts/blazor-hashrouting
- name: Pack
run: dotnet pack src/Blazor.HashRouting/Blazor.HashRouting.csproj --configuration Release --no-build --artifacts-path=/tmp/artifacts/blazor-hashrouting
- name: Resolve Release Tag
if: steps.release_channel.outputs.channel != 'none'
id: resolve_tag
shell: bash
run: |
if git rev-parse "${VERSION}" >/dev/null 2>&1; then
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
echo "exists=true" >> $GITHUB_OUTPUT
echo "Using existing tag '${VERSION}'"
elif git rev-parse "v${VERSION}" >/dev/null 2>&1; then
echo "tag=v${VERSION}" >> $GITHUB_OUTPUT
echo "exists=true" >> $GITHUB_OUTPUT
echo "Using existing tag 'v${VERSION}'"
else
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
echo "exists=false" >> $GITHUB_OUTPUT
echo "::warning::No matching git tag found for '${VERSION}' or 'v${VERSION}'."
fi
- name: Ensure master tag exists
if: steps.release_channel.outputs.channel == 'stable' && steps.resolve_tag.outputs.exists != 'true'
shell: bash
run: |
echo "::error::Expected an existing git tag '${VERSION}' (or 'v${VERSION}') before creating a stable release."
exit 1
- name: Resolve Release Notes File
if: steps.release_channel.outputs.channel != 'none'
id: release_notes
shell: bash
run: |
if [ "${{ steps.release_channel.outputs.channel }}" = "stable" ]; then
notes_file="release-notes/${MAJOR_MINOR_PATCH}.md"
else
notes_file="release-notes/${MAJOR_MINOR_PATCH}-${{ steps.release_channel.outputs.channel }}.md"
fi
if [ ! -f "${notes_file}" ]; then
fallback_notes_file="release-notes/${{ steps.release_channel.outputs.channel }}.md"
if [ -f "${fallback_notes_file}" ]; then
notes_file="${fallback_notes_file}"
else
echo "::error::Expected release notes file '${notes_file}' was not found and fallback '${fallback_notes_file}' was not available."
exit 1
fi
fi
echo "file=${notes_file}" >> $GITHUB_OUTPUT
- name: Render Release Notes
if: steps.release_channel.outputs.channel != 'none'
id: render_release_notes
shell: bash
run: |
rendered_notes_file="$(mktemp)"
sed \
-e "s/{{VERSION}}/${VERSION}/g" \
-e "s/{{NUGET_VERSION}}/${VERSION}/g" \
-e "s/{{MAJOR_MINOR_PATCH}}/${MAJOR_MINOR_PATCH}/g" \
"${{ steps.release_notes.outputs.file }}" > "${rendered_notes_file}"
echo "file=${rendered_notes_file}" >> $GITHUB_OUTPUT
- name: Create GitHub release
if: steps.release_channel.outputs.channel != 'none'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
release_args=()
if [ "${{ steps.release_channel.outputs.prerelease }}" = "true" ]; then
release_args+=("--prerelease")
fi
if [ "${{ steps.release_channel.outputs.draft }}" = "true" ]; then
release_args+=("--draft")
fi
if gh release view "${{ steps.resolve_tag.outputs.tag }}" >/dev/null 2>&1; then
gh release edit "${{ steps.resolve_tag.outputs.tag }}" \
--notes-file "${{ steps.render_release_notes.outputs.file }}"
gh release upload "${{ steps.resolve_tag.outputs.tag }}" \
/tmp/artifacts/blazor-hashrouting/package/release/Blazor.HashRouting.${VERSION}.nupkg \
/tmp/artifacts/blazor-hashrouting/package/release/Blazor.HashRouting.${VERSION}.snupkg \
--clobber
else
gh release create "${{ steps.resolve_tag.outputs.tag }}" \
/tmp/artifacts/blazor-hashrouting/package/release/Blazor.HashRouting.${VERSION}.nupkg \
/tmp/artifacts/blazor-hashrouting/package/release/Blazor.HashRouting.${VERSION}.snupkg \
--title "${{ steps.release_channel.outputs.label }} ${{ steps.resolve_tag.outputs.tag }}" \
--target "${GITHUB_SHA}" \
--notes-file "${{ steps.render_release_notes.outputs.file }}" \
"${release_args[@]}"
fi
- name: Push package to GitHub Packages
if: steps.release_channel.outputs.channel != 'none'
shell: bash
run: |
dotnet nuget push "/tmp/artifacts/blazor-hashrouting/package/release/Blazor.HashRouting.${VERSION}.nupkg" \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
--skip-duplicate
- name: Push package to NuGet
if: steps.release_channel.outputs.channel == 'stable'
shell: bash
run: |
dotnet nuget push "/tmp/artifacts/blazor-hashrouting/package/release/Blazor.HashRouting.${VERSION}.nupkg" \
--api-key "${{ secrets.NUGET_API_KEY }}" \
--source "https://api.nuget.org/v3/index.json" \
--skip-duplicate
- name: Push symbols to NuGet
if: steps.release_channel.outputs.channel == 'stable'
shell: bash
run: |
dotnet nuget push "/tmp/artifacts/blazor-hashrouting/package/release/Blazor.HashRouting.${VERSION}.snupkg" \
--api-key "${{ secrets.NUGET_API_KEY }}" \
--source "https://api.nuget.org/v3/index.json" \
--skip-duplicate