-
Notifications
You must be signed in to change notification settings - Fork 0
254 lines (224 loc) · 8.63 KB
/
Copy pathpublish.yml
File metadata and controls
254 lines (224 loc) · 8.63 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
254
name: Upload Amazon Images
permissions:
contents: read
on:
pull_request:
merge_group:
push:
branches: [main]
jobs:
nix-checks:
name: Basic Nix checks
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/flake-checker-action@main
with:
fail-mode: false
- uses: DeterminateSystems/determinate-nix-action@main
- uses: DeterminateSystems/flakehub-cache-action@main
- name: Check Nix formatting
run: |
nix develop --command git ls-files -z '*.nix' | xargs -0 -r nix develop --command nixfmt --check
- name: nix flake check
run: |
nix flake check --all-systems
- name: Check external links in README
continue-on-error: true
run: |
nix develop --command \
lychee README.md
- name: check image label
run: |
label="$(nix eval --raw .#nixosConfigurations.x86_64-linux.config.system.nixos.label)"
echo "checking label '$label'..."
set -x
echo "${label}" | grep -E '^[0-9][0-9]\.[0-9][0-9]\..*';
build-ami:
name: Upload NixOS AMI
runs-on: ${{ matrix.system.runner }}
environment: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && 'production' || '' }}
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
system:
- nix-system: x86_64-linux
runner: ubuntu-latest
- nix-system: aarch64-linux
runner: UbuntuLatest32Cores128GArm
partition:
- role: arn:aws:iam::535002876703:role/upload-ami
region: us-east-2
bucket: detsys-nixos-images-20240916205705854200000001
- role: arn:aws-us-gov:iam::579351485434:role/upload-ami
region: us-gov-west-1
bucket: detsys-nixos-images-20260303190747195900000001
- role: arn:aws-eusc:iam::129194717446:role/upload-ami
region: eusc-de-east-1
bucket: detsys-nixos-images-20260409030044091900000001
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
with:
determinate: true
extra-conf: |
extra-system-features = kvm
# note: no magic-nix-cache. The build is nearly trivial, except for the gigantic disk image at the end.
# No need to cache that monstrosity.
- id: build-disk-image
run: |
nix build -L .#"diskImages.${{ matrix.system.nix-system }}.aws"
suffix=$(readlink ./result | cut -d'/' -f4 | cut -d'-' -f1)
echo "suffix=$suffix" >> "$GITHUB_OUTPUT"
- uses: aws-actions/configure-aws-credentials@v4
if: github.event_name == 'merge_group' || github.event_name == 'push'
with:
role-to-assume: ${{ matrix.partition.role }}
aws-region: ${{ matrix.partition.region }}
- name: Upload Smoke test AMI
if: github.event_name == 'merge_group' || github.event_name == 'push'
id: upload-smoke-test-ami
run: |
epoch="$(nix eval --raw .#epoch)"
prefix="smoketest/epoch-${epoch}/"
image_ids=$(nix develop --command upload-ami \
--image-info "./result/nix-support/image-info.json" \
--prefix "${prefix}" \
--s3-bucket "${{ matrix.partition.bucket }}" \
--run-id '${{ steps.build-disk-image.outputs.suffix }}')
echo "image_ids=$image_ids" >> "$GITHUB_OUTPUT"
- name: Smoke test
if: github.event_name == 'merge_group' || github.event_name == 'push'
id: smoke-test
# NOTE: make sure smoke test isn't cancelled so that the instance gets cleaned up
run: |
image_ids='${{ steps.upload-smoke-test-ami.outputs.image_ids }}'
image_id=$(echo "$image_ids" | jq -r '.["${{ matrix.partition.region }}"]')
nix run .#smoke-test -- \
--image-id "$image_id" \
--run-id "${{ github.run_id }}-${{ github.run_attempt }}" \
--no-spot
- name: Clean up smoke test
# NOTE(colemickens): NixOS/amis#smoke-test has a finally to teardown instance, this is workflow-cancellation protection
if: ${{ cancelled() && (github.event_name == 'merge_group' || github.event_name == 'push') }}
run: |
image_ids='${{ steps.upload-smoke-test-ami.outputs.image_ids }}'
image_id=$(echo "$image_ids" | jq -r '.["${{ matrix.partition.region }}"]')
nix run .#smoke-test -- \
--image-id "$image_id" \
--run-id "${{ github.run_id }}-${{ github.run_attempt }}" \
--no-spot \
--cancel
- name: Upload AMIs to all available regions
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
epoch="$(nix eval --raw .#epoch)"
prefix="determinate/nixos/epoch-${epoch}/"
nix develop --command upload-ami \
--image-info "./result/nix-support/image-info.json" \
--prefix "${prefix}" \
--s3-bucket "${{ matrix.partition.bucket }}" \
--run-id "${{ github.run_id }}-${{ github.run_attempt }}" \
--copy-to-regions \
--public \
--best-effort-region me-central-1 \
--best-effort-region me-south-1
prune-old-amis:
name: Prune old AMIs
runs-on: ubuntu-latest
environment: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && 'production' || '' }}
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
partition:
- role: arn:aws:iam::535002876703:role/upload-ami
region: us-east-2
- role: arn:aws-us-gov:iam::579351485434:role/upload-ami
region: us-gov-west-1
- role: arn:aws-eusc:iam::129194717446:role/upload-ami
region: eusc-de-east-1
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: aws-actions/configure-aws-credentials@v4
if: github.event_name == 'merge_group' || github.event_name == 'push'
with:
role-to-assume: ${{ matrix.partition.role }}
aws-region: ${{ matrix.partition.region }}
- name: Delete old AMIs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
nix develop --command delete-deprecated-images --grace-period 90
cache-dev-environment:
name: Cache Nix development environment in FlakeHub Cache
runs-on: ${{ matrix.system.runner }}
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
system:
- nix-system: x86_64-linux
runner: ubuntu-latest
- nix-system: aarch64-linux
runner: UbuntuLatest32Cores128GArm
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
with:
determinate: true
- uses: DeterminateSystems/flakehub-cache-action@main
- run: |
nix build .#devShells.${{ matrix.system.nix-system }}.default
notify-for-update-prs:
name: Notify Discord for update_flake_lock_action PRs
runs-on: ubuntu-latest
needs:
- nix-checks
- build-ami
if: always() && github.head_ref == 'update_flake_lock_action'
steps:
- name: Notify Discord
uses: rjstone/discord-webhook-notify@v1
with:
severity: info
details: NixOS AMIs Update - ${{ needs.build-ami.result }}
webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Notify Slack
uses: slackapi/slack-github-action@v2.1.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "*NixOS AMI Update*: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
success:
runs-on: ubuntu-latest
needs:
- nix-checks
- build-ami
- prune-old-amis
- cache-dev-environment
if: ${{ always() }}
steps:
- run: "true"
- run: |
echo "A dependent in the build matrix failed."
exit 1
if: |
contains(needs.*.result, 'failure') ||
contains(needs.*.result, 'cancelled')