-
Notifications
You must be signed in to change notification settings - Fork 10
349 lines (332 loc) · 12.8 KB
/
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
name: CI
on:
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- master
workflow_dispatch:
env:
AWS_REGION: "eu-central-1"
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
permissions:
id-token: write
contents: write
jobs:
build:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && (github.event.pull_request.merged || github.event.action != 'closed'))
outputs:
sha: ${{ steps.get_sha.outputs.sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Get current commit SHA
id: get_sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Setup Earthly
uses: ./.github/earthly-setup
with:
ssh_key: ${{ secrets.SUBSTRATE_REPO_SSH_KEY }}
config_tar: ${{ secrets.EARTHLY_TAR }}
- name: Acquire AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_SECRET }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.ECR_REGISTRY_SECRET }}
- name: Build and Artifacts and Push Image
env:
EARTHLY_CI: true
EARTHLY_OUTPUT: true
EARTHLY_PUSH: true
run: |
earthly -P +ci --image=${{ secrets.ECR_REGISTRY_SECRET }}/substrate-node
- name: Upload partner-chains-cli artifact
uses: actions/upload-artifact@v4
with:
name: partner-chains-cli-artifact
path: partner-chains-cli-artifact
- name: Upload partner-chains-node artifact
uses: actions/upload-artifact@v4
with:
name: partner-chains-node-artifact
path: partner-chains-node-artifact
- name: Upload chain spec artifacts
uses: actions/upload-artifact@v4
with:
name: chain-specs
path: |
./devnet_chain_spec.json
./staging_preview_chain_spec.json
./staging_preprod_chain_spec.json
local-environment-tests:
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == false)
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Deploy and test against local environment
uses: ./.github/actions/tests/local-environment-tests
with:
tag: CI
image: ${{ secrets.ECR_REGISTRY_SECRET }}/substrate-node:${{ needs.build.outputs.sha }}
sha: ${{ needs.build.outputs.sha }}
tests: premerge
env:
SUBSTRATE_REPO_SSH_KEY: ${{ secrets.SUBSTRATE_REPO_SSH_KEY }}
EARTHLY_TAR: ${{ secrets.EARTHLY_TAR }}
AWS_ROLE_ARN_SECRET: ${{ secrets.AWS_ROLE_ARN_SECRET }}
AWS_REGION: ${{ env.AWS_REGION }}
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
ECR_REGISTRY_SECRET: ${{ secrets.ECR_REGISTRY_SECRET }}
TEST_ENVIRONMENT: local
local-environment-tests-alert:
needs: local-environment-tests
if: always() && needs.local-environment-tests.result != 'skipped'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Download test report
uses: actions/download-artifact@v4
with:
name: test-results
- name: Report to slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
JIRA_URL: ${{ secrets.JIRA_URL }}
repository: ${{ github.repository }}
slack_ref_name: ${{ github.ref_name }}
job_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
github_actor_username: ${{ github.actor }}
env: local-pre-merge
run: |
mv .report.json E2E-tests/.report.json
cd E2E-tests
./report_slack.sh $repository $slack_ref_name $job_url $env $github_actor_username null
shell: bash
deploy-argocd:
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == false)
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Deploy ArgoCD Node
uses: ./.github/actions/deploy/argocd/deploy-argocd
with:
sha: ${{ needs.build.outputs.sha }}
env:
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
argocd-tests:
continue-on-error: true
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == false)
needs: [build, deploy-argocd]
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Run Tests
uses: ./.github/actions/tests/argocd-tests
with:
sha: ${{ needs.build.outputs.sha }}
node-host: sha-${{ needs.build.outputs.sha }}-service.integration-testing.svc.cluster.local
node-port: 9933
ssh_key_binary_host: ${{ secrets.SSH_KEY_BINARY_HOST }}
env:
AWS_ROLE_ARN_: ${{ secrets.AWS_ROLE_ARN_ }}
SSH_KEY_BINARY_HOST: ${{ secrets.SSH_KEY_BINARY_HOST }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
JIRA_URL: ${{ secrets.JIRA_URL }}
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
teardown-argocd:
needs: [build, argocd-tests]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Teardown ArgoCD Environment
uses: ./.github/actions/deploy/argocd/teardown-argocd
with:
sha: ${{ needs.build.outputs.sha }}
env:
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
devshell-tests:
needs: build
strategy:
matrix:
os: [nixos, macos]
runs-on:
- self-hosted
- ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Acquire AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_ }}
aws-region: ${{ env.AWS_REGION }}
- name: Add signing key for nix
run: echo "${{ secrets.NIX_SIGNING_KEY }}" > "${{ runner.temp }}/nix-key"
- name: Run nixci to build/test all outputs
run: |
nix run github:srid/nixci -- -v build -- --fallback > /tmp/outputs
- name: Copy nix scopes to nix cache
run: |
nix-store --stdin -q --deriver < /tmp/outputs | nix-store --stdin -qR --include-outputs \
| nix copy --stdin --to \
"s3://cache.sc.iog.io?secret-key=${{ runner.temp }}/nix-key®ion=$AWS_DEFAULT_REGION" \
&& rm /tmp/outputs
pre-merge-checks-complete:
if: ${{ always() && (github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == false)) }}
needs: [build, local-environment-tests, devshell-tests]
runs-on: ubuntu-latest
steps:
- name: Check if any needed job failed
run: |
if [[ "${{ needs.build.result }}" != "success" ||
"${{ needs.local-environment-tests.result }}" != "success" ||
"${{ needs.devshell-tests.result }}" != "success" ]]; then
echo "One or more needed jobs failed."
exit 1
else
echo "All needed jobs passed."
fi
upload-chain-specs:
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
needs: build
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Upload chain spec artifacts to Kubernetes
uses: ./.github/actions/deploy/upload-chain-specs
with:
sha: ${{ needs.build.outputs.sha }}
env:
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
deploy-rustdoc:
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Deploy Rust Docs
uses: ./.github/actions/deploy/deploy-rustdoc
with:
ssh_key: ${{ secrets.SUBSTRATE_REPO_SSH_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
local-environment-tests-post-merge:
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.merge_commit_sha || github.sha }}
- name: Deploy and test against local environment
uses: ./.github/actions/tests/local-environment-tests
with:
tag: CI
image: ${{ secrets.ECR_REGISTRY_SECRET }}/substrate-node:${{ needs.build.outputs.sha }}
sha: ${{ needs.build.outputs.sha }}
tests: postmerge
env:
SUBSTRATE_REPO_SSH_KEY: ${{ secrets.SUBSTRATE_REPO_SSH_KEY }}
EARTHLY_TAR: ${{ secrets.EARTHLY_TAR }}
AWS_ROLE_ARN_SECRET: ${{ secrets.AWS_ROLE_ARN_SECRET }}
AWS_REGION: ${{ env.AWS_REGION }}
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
ECR_REGISTRY_SECRET: ${{ secrets.ECR_REGISTRY_SECRET }}
TEST_ENVIRONMENT: local
local-environment-tests-post-merge-alert:
needs: local-environment-tests-post-merge
if: always() && needs.local-environment-tests-post-merge.result != 'skipped'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.merge_commit_sha || github.sha }}
- name: Download test report
uses: actions/download-artifact@v4
with:
name: test-results
- name: Report to slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
JIRA_URL: ${{ secrets.JIRA_URL }}
repository: ${{ github.repository }}
slack_ref_name: ${{ github.ref_name }}
job_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
github_actor_username: ${{ github.actor }}
env: local-post-merge
run: |
mv .report.json E2E-tests/.report.json
cd E2E-tests
./report_slack.sh $repository $slack_ref_name $job_url $env $github_actor_username null
shell: bash
post-merge-actions-complete:
if: ${{ always() && (github.event_name == 'pull_request' && github.event.pull_request.merged == true) }}
needs: [deploy-rustdoc, upload-chain-specs, local-environment-tests-post-merge]
runs-on: ubuntu-latest
steps:
- name: Check if any needed job failed
run: |
if [[ "${{ needs.deploy-rustdoc.result }}" != "success" ||
"${{ needs.upload-chain-specs.result }}" != "success" ||
"${{ needs.local-environment-tests-post-merge.result }}" != "success" ]]; then
echo "One or more needed jobs failed."
exit 1
else
echo "All needed jobs passed."
fi