-
Notifications
You must be signed in to change notification settings - Fork 11
540 lines (454 loc) · 15.5 KB
/
pr-ci.yml
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
name: Tyger
on:
push:
branches: [main]
tags: ["v*.*.*"]
pull_request: # all branches
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
AZURE_CLIENT_ID: 789b8572-1fae-4a5f-b376-6d9d14651245
AZURE_TENANT_ID: 72f988bf-86f1-41af-91ab-2d7cd011db47
AZURE_SUBSCRIPTION_ID: 87d8acb3-5176-4651-b457-6ab9cefd8e3d
CAN_ACCESS_SECRETS: ${{ secrets.CAN_ACCESS_SECRETS }}
jobs:
# If this is running a Dependabot PR or PR from a fork, it we won't have access to secrets
# nor will be be able to obtain a federated token to access Azure resources.
# Therefore, in those cases, we use hosted runners with managed identity to access Azure resources.
# We only want to use those when necessary since they are a lot slower to come up, so this job
# determines what we should pass in to `runs-on` for jobs that access Azure resources.
# Also, this repo is configured to require approvals for all workflowd external contributors, and we
# should inspect the code in the PR before approving the run.
test-azure-needs-hosted-runner:
runs-on: ubuntu-latest
outputs:
AZURE_RUNS_ON_JSON: ${{ steps.set-vars.outputs.AZURE_RUNS_ON_JSON }}
AZURE_RUNS_ON_WINDOWS_JSON: ${{ steps.set-vars.outputs.AZURE_RUNS_ON_WINDOWS_JSON }}
steps:
- id: set-vars
run: |
if [[ -n "${CAN_ACCESS_SECRETS:-}" ]]; then
AZURE_RUNS_ON_JSON='"ubuntu-latest"'
AZURE_RUNS_ON_WINDOWS_JSON='"windows-latest"'
else
AZURE_RUNS_ON_JSON='["self-hosted", "1ES.Pool=tyger-gh-1es"]'
AZURE_RUNS_ON_WINDOWS_JSON='["self-hosted", "1ES.Pool=tyger-gh-1es-windows"]'
fi
echo "AZURE_RUNS_ON_JSON=$AZURE_RUNS_ON_JSON" >> "$GITHUB_OUTPUT"
echo "AZURE_RUNS_ON_WINDOWS_JSON=$AZURE_RUNS_ON_WINDOWS_JSON" >> "$GITHUB_OUTPUT"
unit-tests-and-format:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
env:
TYGER_MIN_NODE_COUNT: "1"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- uses: actions/setup-dotnet@v3
with:
global-json-file: server/global.json
- name: Build and Verify format
run: |
set -euo pipefail
make restore
make verify-format
make install-cli
- name: Run unit tests
run: |
set -euo pipefail
make unit-test
- name: Generate NOTICE.txt
run: |
set -euo pipefail
scripts/generate-notice.sh
if [[ `git status --porcelain` ]]; then
git diff
echo "ERROR: NOTICE.txt needs to be regenerated using scripts/generate-notice.sh"
exit 1
fi
- name: Check copyright headers
run: |
set -euo pipefail
scripts/add-copyright-headers.sh
if [[ `git status --porcelain` ]]; then
git diff
echo "ERROR: update copyright headers using scripts/add-cpopyright-headers.sh"
exit 1
fi
- name: Build docs
run: |
set -euo pipefail
cd docs
npm install
npm run docs:build
build-images:
needs:
- test-azure-needs-hosted-runner
- get-config
runs-on: ${{ fromJson(needs.test-azure-needs-hosted-runner.outputs.AZURE_RUNS_ON_JSON)}}
env:
EXPLICIT_IMAGE_TAG: ${{ needs.get-config.outputs.IMAGE_TAG }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log in to Azure
uses: ./.github/actions/login-azure
- name: build images
run: |
set -eo pipefail
make -j 4 docker-build
get-config:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
outputs:
IMAGE_TAG: ${{ steps.tag.outputs.IMAGE_TAG }}
TYGER_ENVIRONMENT_NAME: ${{ steps.set-variables.outputs.TYGER_ENVIRONMENT_NAME }}
TYGER_URI: ${{ steps.set-variables.outputs.TYGER_URI }}
DEVELOPER_CONFIG_BASE64: ${{ steps.set-variables.outputs.DEVELOPER_CONFIG_BASE64 }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Generate tag
id: tag
run: |
echo "IMAGE_TAG=$(date +'%Y%m%d%H%M%S')-$GITHUB_SHA" >> "$GITHUB_OUTPUT"
- name: Set variables
id: set-variables
run: |
set -eo pipefail
event_name="${{ github.event_name }}"
if [ "$event_name" == "pull_request" ]; then
# Reuse environment names so that we are not creating new Let's Encrypt certificate requests for each PR
environment_name="tyger-gpr$(( (${{ github.event.pull_request.number }} % 15) + 38 ))"
else
environment_name="tygerwestus2"
fi
export TYGER_ENVIRONMENT_NAME="${environment_name}"
tyger_uri=$(make -s get-tyger-uri)
echo "TYGER_URI=$tyger_uri" >> "$GITHUB_OUTPUT"
echo "TYGER_ENVIRONMENT_NAME=$environment_name" >> "$GITHUB_OUTPUT"
echo "TYGER_ENVIRONMENT_NAME=$environment_name" >> "$GITHUB_ENV"
# GitHub Actions thinks this holds a secret, which prevents us from using
# it as an output variable. So we base64 encode it as a workaround.
# There is no secret in this value.
developer_config_base64=$(scripts/get-config.sh --dev -o json | jq -c | base64 -w 0)
echo "DEVELOPER_CONFIG_BASE64=$developer_config_base64" >> "$GITHUB_OUTPUT"
echo "DEVELOPER_CONFIG_BASE64=$developer_config_base64" >> "$GITHUB_ENV"
up:
needs:
- test-azure-needs-hosted-runner
- get-config
runs-on: ${{ fromJson(needs.test-azure-needs-hosted-runner.outputs.AZURE_RUNS_ON_JSON)}}
defaults:
run:
shell: bash
env:
TYGER_MIN_NODE_COUNT: "1"
DO_NOT_BUILD_IMAGES: "true"
EXPLICIT_IMAGE_TAG: ${{ needs.get-config.outputs.IMAGE_TAG }}-amd64
TYGER_ENVIRONMENT_NAME: ${{ needs.get-config.outputs.TYGER_ENVIRONMENT_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log in to Azure
uses: ./.github/actions/login-azure
- name: Log in to ACR
run: |
make login-wip-acr
- uses: actions/setup-go@v4
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- name: up
run: |
set -euo pipefail
make -s up INSTALL_CLOUD=true
make -s migrate
restore-scale-to-zero:
needs:
- test-azure-needs-hosted-runner
- up
- get-config
runs-on: ${{ fromJson(needs.test-azure-needs-hosted-runner.outputs.AZURE_RUNS_ON_JSON)}}
defaults:
run:
shell: bash
env:
TYGER_ENVIRONMENT_NAME: ${{ needs.get-config.outputs.TYGER_ENVIRONMENT_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log in to Azure
uses: ./.github/actions/login-azure
- uses: actions/setup-go@v4
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- name: restore-scale-to-zero
run: |
set -euo pipefail
make -s ensure-environment
integration-tests:
needs:
- test-azure-needs-hosted-runner
- get-config
- up
runs-on: ${{ fromJson(needs.test-azure-needs-hosted-runner.outputs.AZURE_RUNS_ON_JSON)}}
env:
TYGER_MIN_NODE_COUNT: "1"
DO_NOT_BUILD_IMAGES: "true"
EXPLICIT_IMAGE_TAG: ${{ needs.get-config.outputs.IMAGE_TAG }}-amd64
TYGER_ENVIRONMENT_NAME: ${{ needs.get-config.outputs.TYGER_ENVIRONMENT_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log in to Azure
uses: ./.github/actions/login-azure
- uses: actions/setup-go@v4
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- name: Deploy and test
run: |
set -euo pipefail
make -s integration-test-no-up
build-windows-binaries:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version-file: cli/go.mod
# use a different cache key for windows builds
cache-dependency-path: |
cli/go.sum
cli/go.mod
- name: Build Windows Binaries
run: |
set -eo pipefail
export CGO_ENABLED=1
export GOOS=windows
export GOARCH=amd64
make install-cli
destination="${GITHUB_WORKSPACE}/windows-cli-tools"
mkdir -p "$destination"
cp -a "$(go env GOPATH)/bin/$(go env GOOS)_$(go env GOARCH)/." "$destination"
- name: Archive windows-cli-tools
uses: actions/upload-artifact@v4
with:
name: windows-cli-tools
path: windows-cli-tools
windows-smoke-tests:
needs:
- test-azure-needs-hosted-runner
- get-config
- build-windows-binaries
- up
runs-on: ${{ fromJson(needs.test-azure-needs-hosted-runner.outputs.AZURE_RUNS_ON_WINDOWS_JSON)}}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: windows-cli-tools
path: windows-cli-tools
- name: Log in to Azure
uses: ./.github/actions/login-azure
- name: Run smoke tests
env:
DEVELOPER_CONFIG_BASE64: ${{ needs.get-config.outputs.DEVELOPER_CONFIG_BASE64 }}
TYGER_URI: ${{ needs.get-config.outputs.TYGER_URI }}
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$env:PATH = "$env:GITHUB_WORKSPACE\windows-cli-tools;" + $env:PATH
$developerConfig = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:DEVELOPER_CONFIG_BASE64)) | ConvertFrom-Json
$servicePrincipal = $developerConfig.testAppUri
$keyVaultName = $developerConfig.keyVault
$certificateName = $developerConfig.pkcs12CertSecret.name
$certificateVersion = $developerConfig.pkcs12CertSecret.version
# Run tests
.\scripts\Test-CertificateLoginOnWindows.ps1 `
-ServerUri $env:TYGER_URI `
-ServicePrincipal $servicePrincipal `
-KeyVaultName $keyVaultName `
-CertificateName $certificateName `
-CertificateVersion $certificateVersion
verify-docker:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
env:
TYGER_ENVIRONMENT_TYPE: docker
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- uses: actions/setup-dotnet@v3
with:
global-json-file: server/global.json
- name: "Build and test"
run: |
set -euo pipefail
make -s -j 4
codeql:
runs-on: ubuntu-latest
if: github.repository == 'microsoft/tyger'
defaults:
run:
shell: bash
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'csharp', 'go' ]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
if: matrix.language == 'go'
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- uses: actions/setup-dotnet@v3
with:
global-json-file: server/global.json
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: "Build"
run: |
set -euo pipefail
make -s build-${{ matrix.language }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
publishDocs:
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'microsoft/tyger'
needs:
- unit-tests-and-format
- integration-tests
- get-config
- verify-docker
- windows-smoke-tests
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build static page
run: |
cd docs
npm install
npm run docs:build
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
# Upload entire repository
path: 'docs/.vitepress/dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
release:
if: startsWith(github.ref, 'refs/tags/')
needs:
- unit-tests-and-format
- integration-tests
- get-config
- verify-docker
- windows-smoke-tests
environment:
name: publish-container-images
env:
DEVELOPER_CONFIG_BASE64: ${{ needs.get-config.outputs.DEVELOPER_CONFIG_BASE64 }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- name: get container registry
run: |
set -euo pipefail
official_pull_container_registry=$(echo "$DEVELOPER_CONFIG_BASE64" | base64 -d | jq -r '.officialPullContainerRegistry.fqdn')
echo "OFFICIAL_PULL_CONTAINER_REGISTRY=$(echo $official_pull_container_registry)" >> $GITHUB_ENV
official_pull_container_registry_directory=$(echo "$DEVELOPER_CONFIG_BASE64" | base64 -d | jq -r '.officialPullContainerRegistry.directory // ""')
echo "OFFICIAL_PULL_CONTAINER_REGISTRY_DIRECTORY=$(echo $official_pull_container_registry_directory)" >> $GITHUB_ENV
- name: test image published
run: |
set -euo pipefail
docker pull "${OFFICIAL_PULL_CONTAINER_REGISTRY}${OFFICIAL_PULL_CONTAINER_REGISTRY_DIRECTORY}/tyger-server:$(git describe --tags)"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: v1.21.2
workdir: cli
args: release --clean