-
Notifications
You must be signed in to change notification settings - Fork 9
253 lines (219 loc) · 8.74 KB
/
Copy pathci-cd.yml
File metadata and controls
253 lines (219 loc) · 8.74 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
name: "CI/CD Pipeline"
on:
push:
paths-ignore:
- "**.md"
- LICENSE
branches:
- "master"
pull_request:
paths-ignore:
- "**.md"
- LICENSE
branches:
- master
- "feature/*"
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
permissions:
contents: read
jobs:
build-and-test:
name: "Build & Test (${{ matrix.name }})"
runs-on: ${{ matrix.os }}
env:
NUGET_PACKAGES: ${{ contains(matrix.os, 'windows') && format('{0}\.nuget\packages', github.workspace) || format('{0}/.nuget/packages', github.workspace) }}
BADGE_GIST_ID: "472c59b7c2a1898c48a29f3c88897c5a"
# dorny/test-reporter publishes a check run. The badge step authenticates with its own
# PAT (secrets.GIST_SECRET), so it needs nothing from GITHUB_TOKEN.
permissions:
contents: read
actions: read
checks: write
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
name: "Windows"
script: "./build.ps1"
filename: "test-results-windows.json"
- os: ubuntu-22.04
name: "Linux"
script: "./build.sh"
filename: "test-results-linux.json"
- os: macos-latest
name: "macOS"
script: "./build.sh"
filename: "test-results-macos.json"
steps:
- name: "Checkout"
uses: actions/checkout@v7
with:
fetch-depth: 0 # Full history for better caching
- name: "Setup .NET SDK"
uses: actions/setup-dotnet@v6
with:
dotnet-version: |
8.0.x
9.0.x
global-json-file: global.json
# The macOS runner image no longer ships Mono, and VSTest needs the real 'mono' host
# on the PATH to execute the net472 test assemblies.
- name: "Install Mono (macOS)"
if: runner.os == 'macOS'
run: |
if command -v mono >/dev/null 2>&1; then
echo "✅ Mono already present: $(mono --version | head -1)"
else
brew install mono
echo "✅ Installed: $(mono --version | head -1)"
fi
- name: "Cache NuGet packages"
uses: actions/cache@v6
with:
path: ${{ runner.os == 'Windows' && format('{0}\.nuget\packages', github.workspace) || format('{0}/.nuget/packages', github.workspace) }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json', '**/*.csproj', '**/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: "Build"
run: ${{ matrix.script }} --target build
- name: "Run Tests"
run: ${{ matrix.script }} --target tests --skipFunctionalTest ${{ runner.os == 'Linux' && 'false' || 'true' }} --exclusive
- name: "Publish Test Results"
id: test-results
uses: dorny/test-reporter@v3
if: success() || failure()
with:
name: "Test Results (${{ matrix.name }})"
path: "**/TestResults/*.trx"
reporter: "dotnet-trx"
fail-on-error: true
max-annotations: 50
- name: "Update Test Results Badge"
if: always() # Run even if tests failed or were skipped
continue-on-error: true # Don't fail workflow if badge update fails
uses: ./.github/actions/update-test-badge
with:
platform: ${{ matrix.name }}
gist_id: ${{ env.BADGE_GIST_ID }}
filename: ${{ matrix.filename }}
gist_token: ${{ secrets.GIST_SECRET }}
test_passed: ${{ steps.test-results.outputs.passed || 0 }}
test_failed: ${{ steps.test-results.outputs.failed || 0 }}
test_skipped: ${{ steps.test-results.outputs.skipped || 0 }}
test_url_html: ${{ steps.test-results.outputs.url_html || '' }}
commit_sha: ${{ github.sha }}
run_id: ${{ github.run_id }}
repository: ${{ github.repository }}
server_url: ${{ github.server_url }}
- name: "Upload Test Artifacts"
uses: actions/upload-artifact@v7
if: failure()
with:
name: test-results-${{ matrix.name }}
path: |
**/*.trx
**/TestResults/**/*
retention-days: 7
continuous-deployment:
name: "Continuous Deployment"
runs-on: ubuntu-22.04
needs: [build-and-test]
if: |
github.repository == 'localstack-dotnet/localstack-dotnet-client' &&
((github.event_name == 'push' && github.ref == 'refs/heads/master') ||
(github.event_name == 'pull_request' && startsWith(github.head_ref, 'feature/')))
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
permissions:
contents: read
packages: write
steps:
- name: "Checkout"
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: "Setup .NET SDK"
uses: actions/setup-dotnet@v6
with:
dotnet-version: |
8.0.x
9.0.x
global-json-file: global.json
- name: "Cache NuGet packages"
uses: actions/cache@v6
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json', '**/*.csproj', '**/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
# Upload-artifact rejects '/' in artifact names, and every deploy from this job runs on a
# feature/* branch. Mirrors the sanitising BuildContext already applies to the package version.
- name: "Compute artifact-safe branch name"
run: |
RAW_REF="${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}"
echo "SAFE_REF=${RAW_REF//\//-}" >> "$GITHUB_ENV"
- name: "Setup GitHub Packages Configuration"
run: |
echo "🔐 Adding GitHub Packages authentication..."
dotnet nuget add source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json \
--name github-packages \
--username ${{ github.actor }} \
--password ${{ secrets.GITHUB_TOKEN }} \
--store-password-in-clear-text
echo "🔧 Original nuget.config..."
cat nuget.config
echo "📝 Backing up original nuget.config..."
cp nuget.config nuget.config.backup
echo "🔧 Using GitHub-optimized nuget.config..."
cp .github/nuget.config nuget.config
echo "🔧 Replaced nuget.config..."
cat nuget.config
- name: "Pack & Publish LocalStack.Client"
id: pack-client
run: |
echo "🔨 Building and publishing LocalStack.Client package..."
./build.sh --target nuget-pack-and-publish \
--package-source github \
--package-id LocalStack.Client \
--use-directory-props-version true \
--branch-name ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} \
--package-secret ${{ secrets.GITHUB_TOKEN }}
- name: "Prepare Extensions Project"
run: |
echo "🔧 Preparing Extensions project to use LocalStack.Client package..."
./build.sh --target nuget-prepare-extensions \
--package-source github \
--package-id LocalStack.Client.Extensions \
--client-version ${{ steps.pack-client.outputs.client-version }}
- name: "Pack & Publish LocalStack.Client.Extensions"
run: |
echo "🔨 Building and publishing LocalStack.Client.Extensions package..."
./build.sh --target nuget-pack-and-publish \
--package-source github \
--package-id LocalStack.Client.Extensions \
--use-directory-props-version true \
--branch-name ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} \
--package-secret ${{ secrets.GITHUB_TOKEN }}
- name: "Upload Package Artifacts"
uses: actions/upload-artifact@v7
with:
name: "packages-${{ env.SAFE_REF }}-${{ github.run_number }}"
path: |
artifacts/*.nupkg
artifacts/*.snupkg
retention-days: 7
- name: "Generate Build Summary"
run: |
echo "📦 Generating build summary..."
./build.sh --target workflow-summary \
--use-directory-props-version true \
--branch-name ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}
- name: "Cleanup Configuration"
if: always()
run: |
echo "🧹 Restoring original nuget.config..."
mv nuget.config.backup nuget.config || echo "⚠️ Original config not found, skipping restore"