-
Notifications
You must be signed in to change notification settings - Fork 16
243 lines (214 loc) · 8.15 KB
/
publish.yml
File metadata and controls
243 lines (214 loc) · 8.15 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
name: Publish
on:
push:
tags: [ 'v*' ]
workflow_dispatch:
inputs:
dry_run:
description: 'Skip publish + release (exercises verify-gate + build-pack only). Used for Phase 4 operational dry-run.'
type: boolean
default: true
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
statuses: read
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: true
jobs:
verify-gate:
name: Verify tag, version, and Jenkins status
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Tag regex (push trigger only)
if: github.event_name == 'push'
run: |
set -euo pipefail
if [[ ! "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9\.-]+)?$ ]]; then
echo "::error::Tag '${GITHUB_REF_NAME}' does not match ^v[0-9]+\\.[0-9]+\\.[0-9]+(-[A-Za-z0-9\\.-]+)?\\$"
exit 1
fi
echo "Tag '${GITHUB_REF_NAME}' matches regex."
- name: Tag-version match (push trigger only)
if: github.event_name == 'push'
run: |
set -euo pipefail
TAG_VERSION="${GITHUB_REF_NAME#v}"
PROP_VERSION=$(grep -oP '(?<=<Version>)[^<]+' Source/Directory.Build.props)
if [[ "${TAG_VERSION}" != "${PROP_VERSION}" ]]; then
echo "::error::Tag '${TAG_VERSION}' does not match Directory.Build.props '<Version>${PROP_VERSION}</Version>'"
exit 1
fi
echo "Tag version '${TAG_VERSION}' matches Directory.Build.props."
- name: Jenkins B2 gate
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
state=$(gh api "repos/${{ github.repository }}/commits/${{ github.sha }}/status" \
--jq '.statuses[] | select(.context=="continuous-integration/jenkins/branch") | .state')
if [[ "${state}" != "success" ]]; then
echo "::error::Jenkins status on ${{ github.sha }} is '${state:-missing}'; required 'success'"
exit 1
fi
echo "Jenkins 'continuous-integration/jenkins/branch' status is 'success' on ${{ github.sha }}."
build-pack:
name: Build, pack, and upload NuGet packages
needs: verify-gate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
10.0.x
- name: Restore
run: dotnet restore Source/DotNetWorkQueueNoTests.sln
- name: Build
run: dotnet build Source/DotNetWorkQueueNoTests.sln -c Release -p:CI=true --no-restore
- name: Pack (solution)
run: dotnet pack Source/DotNetWorkQueueNoTests.sln -c Release -p:CI=true --no-build -o deploy/
- name: Pack (Dashboard.Ui -- Web SDK not auto-packed by solution)
run: dotnet pack Source/DotNetWorkQueue.Dashboard.Ui/DotNetWorkQueue.Dashboard.Ui.csproj -c Release -p:CI=true --no-build -o deploy/
- name: Assert package counts (12 nupkg + 12 snupkg)
run: |
set -euo pipefail
nupkg_count=$(ls deploy/*.nupkg 2>/dev/null | wc -l)
snupkg_count=$(ls deploy/*.snupkg 2>/dev/null | wc -l)
echo "nupkg_count=${nupkg_count} snupkg_count=${snupkg_count}"
if [[ "${nupkg_count}" -ne 12 ]]; then
echo "::error::Expected 12 .nupkg files in deploy/, got ${nupkg_count}"
ls -la deploy/ || true
exit 1
fi
if [[ "${snupkg_count}" -ne 12 ]]; then
echo "::error::Expected 12 .snupkg files in deploy/, got ${snupkg_count}"
ls -la deploy/ || true
exit 1
fi
- name: Job summary
run: |
{
echo "## Build-pack summary"
echo ""
echo "- Tag/ref: ${{ github.ref_name }}"
echo "- SHA: ${{ github.sha }}"
echo "- Packages: 12 .nupkg + 12 .snupkg"
echo ""
echo "### Packed files"
echo ""
echo '```'
ls -la deploy/ | sed 's/^/ /'
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload artifact
uses: actions/upload-artifact@v5
with:
name: nuget-packages
path: deploy/*
retention-days: 90
if-no-files-found: error
publish:
name: Push to NuGet.org and create GitHub Release
needs: build-pack
if: ${{ github.event_name == 'push' || inputs.dry_run == false }}
runs-on: ubuntu-latest
# Elevated permission scoped to this job only (contents:write is needed
# by gh release create; verify-gate and build-pack run with contents:read).
permissions:
contents: write
steps:
- name: Checkout (for gh release create)
uses: actions/checkout@v5
- name: Download artifact
uses: actions/download-artifact@v5
with:
name: nuget-packages
path: deploy/
# The nupkg and snupkg pushes are deliberately split into two commands.
# The dotnet CLI's auto-match of .snupkg alongside .nupkg is unreliable
# on Windows (CLAUDE.md lesson). Splitting is also easier to diagnose
# if one half fails — the failing step is immediately obvious.
# The ubuntu-latest runner has dotnet preinstalled so no setup-dotnet
# action is needed for `dotnet nuget push`.
- name: Push .nupkg to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push "deploy/*.nupkg" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
- name: Push .snupkg to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push "deploy/*.snupkg" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ github.ref_name }}" \
deploy/*.nupkg deploy/*.snupkg \
--title "DotNetWorkQueue ${{ github.ref_name }}" \
--generate-notes
- name: Job summary
run: |
{
echo "## Publish summary"
echo ""
echo "- Tag: ${{ github.ref_name }}"
echo "- NuGet feed: https://api.nuget.org/v3/index.json"
echo "- Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}"
} >> "$GITHUB_STEP_SUMMARY"
docker-publish:
name: Build and push dashboard Docker image
needs: publish
# Same dry-run semantics as the NuGet publish job: skipped entirely when
# workflow_dispatch is invoked with dry_run=true.
if: ${{ github.event_name == 'push' || inputs.dry_run == false }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Resolve version from tag
id: ver
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: docker/dashboard/Dockerfile
platforms: linux/amd64
push: true
tags: |
blehnen74/dotnetworkqueue-dashboard:${{ steps.ver.outputs.version }}
blehnen74/dotnetworkqueue-dashboard:latest
- name: Job summary
run: |
{
echo "## Docker publish summary"
echo ""
echo "- Image: blehnen74/dotnetworkqueue-dashboard"
echo "- Tags pushed: ${{ steps.ver.outputs.version }}, latest"
echo "- Platforms: linux/amd64"
} >> "$GITHUB_STEP_SUMMARY"