-
Notifications
You must be signed in to change notification settings - Fork 11
252 lines (213 loc) · 8.41 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
name: Tyger
on:
push:
branches: [main]
tags: ["v*.*.*"]
pull_request: # all branches
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
jobs:
tyger-build-deploy:
runs-on: ["self-hosted", "1ES.Pool=tyger-gh-1es"]
container:
image: compimagdevcontainers.azurecr.io/tyger@sha256:3bb5632271f0f5361b39f22d1511ee7ffd59b736523726251d0bab974eadba02
options: -v /mnt/storage:/__w/tyger -v /mnt/storage:/workspaces
defaults:
run:
shell: bash
outputs:
TYGER_ENVIRONMENT_NAME: ${{ steps.set-variables.outputs.TYGER_ENVIRONMENT_NAME }}
TYGER_COMBINED_CONFIG: ${{ steps.set-variables.outputs.TYGER_COMBINED_CONFIG }}
steps:
- name: Login into Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set variables
id: set-variables
run: |
set -eo pipefail
event_name="${{ github.event_name }}"
if [ "$event_name" == "pull_request" ]; then
environment_name="tyger-gpr${{ github.event.pull_request.number }}"
else
environment_name="tygerwestus2"
fi
export TYGER_ENVIRONMENT_NAME="${environment_name}"
tyger_uri=$(make -s get-tyger-uri)
echo "TYGER_ENVIRONMENT_NAME=$environment_name" >> "$GITHUB_OUTPUT"
echo "TYGER_ENVIRONMENT_NAME=$environment_name" >> "$GITHUB_ENV"
combined_config=$(scripts/get-context-environment-config.sh -e "" -o json | jq -c)
echo "TYGER_COMBINED_CONFIG=$combined_config" >> "$GITHUB_OUTPUT"
echo "TYGER_COMBINED_CONFIG=$combined_config" >> "$GITHUB_ENV"
- name: Verify devcontainer
shell: bash
env:
DEVCONTAINER_IMAGE: compimagdevcontainers.azurecr.io/tyger@sha256:3bb5632271f0f5361b39f22d1511ee7ffd59b736523726251d0bab974eadba02
run: |
set -euo pipefail
if [[ "$(.devcontainer/get-devcontainer-image.sh)" != "${DEVCONTAINER_IMAGE}" ]]; then
echo "The devcontainer image in azure-pipelines.yml and devcontainer.json must be the same"
fi
docker build -f .devcontainer/Dockerfile --target devcontainer -t devcontainer --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ${DEVCONTAINER_IMAGE} .
if ! .devcontainer/diff-container-images.sh "${DEVCONTAINER_IMAGE}" devcontainer; then
echo 'Error: the "image" field in devcontainer.json does not reflect the current "devcontainer" target of the Dockerfile. Run .devcontainer/update-devcontainer-image.sh to correct this.'
exit 1
fi
# - name: Build and verify format
# run: |
# set -eo pipefail
# source /opt/conda/etc/profile.d/conda.sh
# conda activate /opt/conda/envs/tyger
# make restore
# make verify-format
# - name: Deploy and test
# run: |
# set -eo pipefail
# source /opt/conda/etc/profile.d/conda.sh
# conda activate /opt/conda/envs/tyger
# export TYGER_ENVIRONMENT_CONFIG_DIR="${GITHUB_WORKSPACE}/deploy/config/microsoft/ci"
# echo "TYGER_ENVIRONMENT_CONFIG_DIR=$TYGER_ENVIRONMENT_CONFIG_DIR"
# # We have mounted this location in the container, it is identical to the checkout location
# # We need to run the testdata generation from this path to make sure the testdata is generated in the right place.
# # Otherwise, checksums will change and dirty the path and that will cause publishing to fail.
# cd /workspaces/tyger
# set -euo pipefail
# make -s -j 8
# - name: Publish official images
# run: |
# source /opt/conda/etc/profile.d/conda.sh
# conda activate /opt/conda/envs/tyger
# set -euo pipefail
# cd /workspaces/tyger
# make publish-official-images
- name: Cleanup
if: ${{ always() }}
run: |
set -eo pipefail
source /opt/conda/etc/profile.d/conda.sh
conda activate /opt/conda/envs/tyger
# Point to scale-to-zero config
export TYGER_ENVIRONMENT_CONFIG_DIR="${GITHUB_WORKSPACE}/deploy/config/microsoft"
echo "scaling cluster back down"
make ensure-environment
windows-smoke-tests:
runs-on: windows-latest
needs:
- tyger-build-deploy
- publish-binaries
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Login into Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Run smoke tests
env:
TYGER_COMBINED_CONFIG: ${{ needs.tyger-build-deploy.outputs.TYGER_COMBINED_CONFIG }}
shell: pwsh
run: |
$env:PATH = "$env:GITHUB_WORKSPACE\dist\tyger_windows_amd64_v1;" + $env:PATH
$combinedConfig = $env:TYGER_COMBINED_CONFIG | ConvertFrom-Json
$tygerUri = "https://" + $combinedConfig.config.api.domainName
$servicePrincipal = $combinedConfig.developerConfig.testAppUri
$keyVaultName = $combinedConfig.developerConfig.keyVault
$certificateName = $combinedConfig.developerConfig.pkcs12CertSecret.name
$certificateVersion = $combinedConfig.developerConfig.pkcs12CertSecret.version
# Run tests
.\scripts\Test-CertificateLoginOnWindows.ps1 \
-ServerUri $tygerUri \
-ServicePrincipal $servicePrincipal \
-KeyVaultName $keyVaultName \
-CertificateName $certificateName \
-CertificateVersion $certificateVersion
codeQL:
name: CodeQL
runs-on: ubuntu-latest
if: github.repository == 'microsoft/tyger'
container:
image: compimagdevcontainers.azurecr.io/tyger@sha256:3bb5632271f0f5361b39f22d1511ee7ffd59b736523726251d0bab974eadba02
options: -v /mnt/storage:/__w/tyger -v /mnt/storage:/workspaces
defaults:
run:
shell: bash
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: csharp, go
- name: "Build"
run: |
set -eo pipefail
source /opt/conda/etc/profile.d/conda.sh
conda activate /opt/conda/envs/tyger
cd /workspaces/tyger
TYGER_ENVIRONMENT_NAME="noenv" make -s build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
publish-binaries:
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'
- uses: cue-lang/[email protected]
with:
version: v0.6.0
name: install CUE
- name: get container registry
run: |
set -euo pipefail
official_container_registry=$(scripts/get-context-environment-config.sh -e developerConfig.officialContainerRegistry.fqdn)
echo "OFFICIAL_CONTAINER_REGISTRY=$(echo $official_container_registry)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
env:
# If this is a tag push, create a release
ARGS: ${{ startsWith(github.ref, 'refs/tags/') && 'release --clean' || 'release --clean --snapshot' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: v1.21.2
workdir: cli
args: ${{ env.ARGS }}
- name: Upload binaries
uses: actions/upload-artifact@v3
with:
name: dist
path: cli/dist