Repository navigation
204 lines (178 loc) · 7.36 KB
/
Copy pathrelease.yml
File metadata and controls
204 lines (178 loc) · 7.36 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
package_version:
description: "SemVer package version to validate; blank uses VersionPrefix"
required: false
type: string
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
package:
name: Validate and package
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.version.outputs.package_version }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
steps:
- name: Check out release source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: global.json
- name: Validate release version and source
id: version
shell: pwsh
env:
DISPATCH_VERSION: ${{ inputs.package_version }}
run: >-
./scripts/Resolve-ReleaseVersion.ps1
-EventName $env:GITHUB_EVENT_NAME
-GitRef $env:GITHUB_REF
-GitRefName $env:GITHUB_REF_NAME
-DispatchVersion $env:DISPATCH_VERSION
-GitHubOutputPath $env:GITHUB_OUTPUT
- name: Verify solution structure
shell: pwsh
run: ./scripts/Verify-SolutionStructure.ps1
- name: Restore
run: dotnet restore ChessRealms.Engine.slnx --locked-mode
- name: Release build
run: dotnet build ChessRealms.Engine.slnx --configuration Release --no-restore -p:ContinuousIntegrationBuild=true
- name: Fast tests
run: dotnet test ChessRealms.Engine.slnx --configuration Release --no-build --filter "TestCategory!=Deep" -p:ContinuousIntegrationBuild=true
- name: Pack once
run: >-
dotnet pack src/ChessRealms.Engine/ChessRealms.Engine.csproj
--configuration Release
--no-build
--output artifacts/packages
-p:PackageVersion=${{ steps.version.outputs.package_version }}
-p:ContinuousIntegrationBuild=true
- name: Verify package contents and metadata
shell: pwsh
run: >-
./scripts/Verify-Package.ps1
-PackagePath "artifacts/packages/ChessRealms.Engine.${{ steps.version.outputs.package_version }}.nupkg"
-ExpectedPackageId ChessRealms.Engine
-ExpectedPackageVersion "${{ steps.version.outputs.package_version }}"
- name: Smoke-test the packed package as a consumer
shell: pwsh
run: >-
./scripts/Test-PackageConsumer.ps1
-PackagePath "artifacts/packages/ChessRealms.Engine.${{ steps.version.outputs.package_version }}.nupkg"
-ExpectedPackageId ChessRealms.Engine
-ExpectedPackageVersion "${{ steps.version.outputs.package_version }}"
- name: Generate SHA-256 checksums
shell: pwsh
run: |
Get-ChildItem artifacts/packages/ChessRealms.Engine.*.*nupkg |
Sort-Object Name |
ForEach-Object {
$hash = (Get-FileHash -Algorithm SHA256 -LiteralPath $_.FullName).Hash.ToLowerInvariant()
"$hash $($_.Name)"
} | Set-Content artifacts/packages/SHA256SUMS.txt
- name: Upload validated release artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: nuget-release-${{ steps.version.outputs.package_version }}
path: |
artifacts/packages/ChessRealms.Engine.${{ steps.version.outputs.package_version }}.nupkg
artifacts/packages/ChessRealms.Engine.${{ steps.version.outputs.package_version }}.snupkg
artifacts/packages/SHA256SUMS.txt
if-no-files-found: error
retention-days: 30
publish:
name: Publish to NuGet
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: package
runs-on: ubuntu-latest
environment: nuget-production
permissions:
contents: read
id-token: write
steps:
- name: Check out release metadata
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: global.json
- name: Download validated release artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: nuget-release-${{ needs.package.outputs.package_version }}
path: artifacts/packages
- name: Verify artifact checksums
working-directory: artifacts/packages
run: sha256sum --check SHA256SUMS.txt
- name: Refuse a conflicting GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${{ github.ref_name }}" --repo "${{ github.repository }}" >/dev/null 2>&1; then
echo "A GitHub Release already exists for ${{ github.ref_name }}; refusing to publish a conflicting release." >&2
exit 1
fi
- name: Obtain temporary NuGet credential
id: nuget-login
uses: NuGet/login@ebc737b6fc418a6ca0073cf116ec8dc156d8b81e # v1
with:
user: ${{ vars.NUGET_USER }}
- name: Publish package and symbols
run: >-
dotnet nuget push
"artifacts/packages/ChessRealms.Engine.${{ needs.package.outputs.package_version }}.nupkg"
--api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}"
--source https://api.nuget.org/v3/index.json
github-release:
name: Create GitHub Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: [package, publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download validated release artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: nuget-release-${{ needs.package.outputs.package_version }}
path: artifacts/packages
- name: Refuse to overwrite an existing release
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${{ github.ref_name }}" --repo "${{ github.repository }}" >/dev/null 2>&1; then
echo "A GitHub Release already exists for ${{ github.ref_name }}; refusing to overwrite it." >&2
exit 1
fi
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
prerelease=()
if [[ "${{ needs.package.outputs.is_prerelease }}" == "true" ]]; then
prerelease+=(--prerelease)
fi
gh release create "${{ github.ref_name }}" \
artifacts/packages/ChessRealms.Engine.${{ needs.package.outputs.package_version }}.nupkg \
artifacts/packages/ChessRealms.Engine.${{ needs.package.outputs.package_version }}.snupkg \
artifacts/packages/SHA256SUMS.txt \
--repo "${{ github.repository }}" \
--verify-tag \
--title "ChessRealms.Engine ${{ needs.package.outputs.package_version }}" \
--generate-notes \
"${prerelease[@]}"