-
Notifications
You must be signed in to change notification settings - Fork 196
286 lines (250 loc) · 11.9 KB
/
pr-validation.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
name: Validate Pull Request
on:
# runs on pushes to main in order to update the baseline code coverage
# so that PRs have something to compare against
push:
branches:
- main
pull_request:
branches:
- main
merge_group:
branches:
- main
types: [checks_requested]
jobs:
test-go-get:
runs-on: ubuntu-latest
steps:
- name: '`go get` code'
run: |
# placeholder module so we can invoke go get
go mod init example.com/m
# note: cannot use github.sha here since that commit doesn't really exist
# however, since we require branches to always be up-to-date (GitHub setting),
# using the head of the PR branch should provide equivalent behaviour
sha='${{ github.event.pull_request.head.sha }}'
repo='${{ github.event.pull_request.head.repo.html_url}}'
repo=${repo#"https://"} # trim prefix
if [ "$repo" != "github.com/Azure/azure-service-operator" ]; then
echo "Skipping 'go get' check for fork…"
exit 0
fi
if [ -z "$sha" ]; then
# this means we were triggered by push to 'main',
# not a PR, so use the sha that triggered this
sha='${{ github.sha }}'
fi
# Give GitHub some time to make the commit available
sleep 10
# Sometimes it can take https://proxy.golang.org up to a minute for the latest commit to be available.
# See the FAQ at https://proxy.golang.org/
FAILED=1
for i in {1..5}; do
if go get "$repo/v2@$sha" ; then
FAILED=0
break
fi
echo "Failed to 'go get' $repo/v2@$sha, retrying in 60 seconds…"
sleep 60
done
exit $FAILED
test-generator:
runs-on: [self-hosted, 1ES.Pool=aso-1es-pool]
permissions:
packages: read
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # required to access tags
submodules: 'true'
- name: Force docker to SSD
run: sudo scripts/v2/linux-docker-use-ssd.sh --containerd true
- name: check-changes
id: check-changes
run: scripts/v2/check-changes.sh
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v2
with:
registry: docker.pkg.github.com # ghcr.io not yet enabled for Azure org
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
if: steps.check-changes.outputs.code-changed == 'true'
# Note: Changes to this step must also be mirrored into pr-validation-with-secrets.yaml
- name: Build devcontainer image
# We must issue a manual pull before the build so the image gets copied locally, because
# docker.pkg.github.com is not a valid Docker registry and doesn't work with --cache-from,
# however, `docker pull` will fall back to other methods that do work and get the image loaded.
#
# This message comes from "docker pull":
#
# Run docker pull docker.pkg.github.com/azure/azure-service-operator/aso-devcontainer:latest
# WARNING: ⚠️ Failed to pull manifest by the resolved digest. This registry does not
# appear to conform to the distribution registry specification; falling back to
# pull by tag. This fallback is DEPRECATED, and will be removed in a future
# release. Please contact admins of https://docker.pkg.github.com. ⚠️
#
# See: https://github.com/moby/moby/issues/41687#issuecomment-733826074 and related issues
run: |
docker pull docker.pkg.github.com/azure/azure-service-operator/aso-devcontainer:latest
docker build --cache-from docker.pkg.github.com/azure/azure-service-operator/aso-devcontainer:latest --tag devcontainer:latest .devcontainer
env:
DOCKER_BUILDKIT: 1
if: steps.check-changes.outputs.code-changed == 'true'
- name: Run devcontainer image
id: devcontainer
run: |
container_id=$(docker create -w /workspace -v $GITHUB_WORKSPACE:/workspace -v /var/run/docker.sock:/var/run/docker.sock --network=host devcontainer:latest)
docker start "$container_id"
echo "container_id=$container_id" >> $GITHUB_ENV
if: steps.check-changes.outputs.code-changed == 'true'
- name: Run CI tasks
run: |
container_id=${{ env.container_id }}
set +e # don't exit instantly on failure, we need to produce Markdown summary
docker exec "$container_id" task ci
EXIT_CODE=$?
set -e
# generate summary Markdown file for display in Actions
cat reports/*.md > $GITHUB_STEP_SUMMARY
exit $EXIT_CODE
if: steps.check-changes.outputs.code-changed == 'true'
- name: Save JSON logs on failure
if: ${{ failure() }}
uses: actions/upload-artifact@v3.1.2
with:
name: test-output
path: reports/*.json
- name: Build docker image & build configuration YAML
run: |
container_id=${{ env.container_id }}
docker exec "$container_id" task controller:docker-build-and-save
docker exec "$container_id" task controller:run-kustomize-for-envtest
if: steps.check-changes.outputs.code-changed == 'true'
- name: Archive outputs
uses: actions/upload-artifact@v3.1.2
with:
name: output
path: v2/bin/*
if-no-files-found: error
if: steps.check-changes.outputs.code-changed == 'true'
- name: Upload code coverage to Codecov
run: bash <(curl -s https://codecov.io/bash)
if: steps.check-changes.outputs.code-changed == 'true'
# TODO: Changing this name requires changing the github API calls in pr-validation-fork.yml
integration-tests:
runs-on: [self-hosted, 1ES.Pool=aso-1es-pool]
if:
# Run on pull requests in this repository that are not from @dependabot, and run for merge groups
github.event_name == 'merge_group' ||
( github.event_name == 'pull_request' &&
github.actor != 'dependabot[bot]' &&
github.event.pull_request.head.repo.full_name == github.repository )
permissions:
packages: read
checks: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # required to access tags
submodules: 'true'
- name: Force docker to SSD
run: sudo scripts/v2/linux-docker-use-ssd.sh --containerd true
- name: check-changes
id: check-changes
run: scripts/v2/check-changes.sh
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v2
with:
registry: docker.pkg.github.com # ghcr.io not yet enabled for Azure org
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
if: steps.check-changes.outputs.code-changed == 'true'
# Note: Changes to this step must also be mirror into pr-validation.yaml
- name: Build devcontainer image
# We must issue a manual pull before the build so the image gets copied locally, because
# docker.pkg.github.com is not a valid Docker registry and doesn't work with --cache-from,
# however, `docker pull` will fall back to other methods that do work and get the image loaded.
#
# This message comes from "docker pull":
#
# Run docker pull docker.pkg.github.com/azure/azure-service-operator/aso-devcontainer:latest
# WARNING: ⚠️ Failed to pull manifest by the resolved digest. This registry does not
# appear to conform to the distribution registry specification; falling back to
# pull by tag. This fallback is DEPRECATED, and will be removed in a future
# release. Please contact admins of https://docker.pkg.github.com. ⚠️
#
# See: https://github.com/moby/moby/issues/41687#issuecomment-733826074 and related issues
run: |
docker pull docker.pkg.github.com/azure/azure-service-operator/aso-devcontainer:latest
docker build --cache-from docker.pkg.github.com/azure/azure-service-operator/aso-devcontainer:latest --tag devcontainer:latest .devcontainer
env:
DOCKER_BUILDKIT: 1
if: steps.check-changes.outputs.code-changed == 'true'
- name: Run devcontainer image
id: devcontainer
run: |
container_id=$(docker create -w /workspace -v $GITHUB_WORKSPACE:/workspace -v /var/run/docker.sock:/var/run/docker.sock --network=host devcontainer:latest)
docker start "$container_id"
echo "container_id=$container_id" >> $GITHUB_ENV
if: steps.check-changes.outputs.code-changed == 'true'
- name: Run integration tests
run: |
container_id=${{ env.container_id }}
docker exec --env HOSTROOT=$GITHUB_WORKSPACE -e AZURE_TENANT_ID -e AZURE_CLIENT_ID -e AZURE_CLIENT_SECRET -e AZURE_SUBSCRIPTION_ID -e AZURE_CLIENT_SECRET_MULTITENANT -e AZURE_CLIENT_ID_MULTITENANT -e AZURE_CLIENT_ID_CERT_AUTH -e AZURE_CLIENT_SECRET_CERT_AUTH "$container_id" task controller:ci-integration-tests
env:
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_CLIENT_SECRET_MULTITENANT: ${{ secrets.AZURE_CLIENT_SECRET_MULTITENANT }}
AZURE_CLIENT_ID_MULTITENANT: ${{ secrets.AZURE_CLIENT_ID_MULTITENANT }}
AZURE_CLIENT_ID_CERT_AUTH: ${{ secrets.AZURE_CLIENT_ID_CERT_AUTH }}
AZURE_CLIENT_SECRET_CERT_AUTH: ${{ secrets.AZURE_CLIENT_SECRET_CERT_AUTH }}
if:
steps.check-changes.outputs.code-changed == 'true'
- name: Get Job ID from GH API
id: get-job-id
if: ${{ always() }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
jobs=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs)
job_id=$(echo $jobs | jq -r '.jobs[] | select(.runner_name=="${{ runner.name }}") | .id')
echo "job_id=$job_id" >> $GITHUB_ENV
# Update check run called "integration-tests-fork"
- name: update-integration-tests-result
uses: actions/github-script@v6
id: update-check-run
if: ${{ always() }}
env:
repo: ${{ github.repository }}
owner: ${{ github.repository_owner }}
run_id: ${{ env.job_id }}
server_url: ${{ github.server_url }}
integration_test_job: 'integration-tests-fork' # This is the name of the job defined in pr-validation-fork.yml
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get all the details of the check run that's currently executing
// This lets us get the SHA we're building regardless of WHY we're building it
const { data: check } = await github.rest.checks.get({
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: process.env.run_id
});
// update the check result for `integration-tests-fork`
const url = `${process.env.server_url}/${process.env.repo}/actions/runs/${process.env.run_id}`
const { data: result } = await github.rest.checks.create({
...context.repo,
name: process.env.integration_test_job,
head_sha: check.head_sha,
status: 'completed',
conclusion: process.env.conclusion,
details_url: url,
});
return result;