-
Notifications
You must be signed in to change notification settings - Fork 1
218 lines (207 loc) · 7.81 KB
/
main.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
name: Build NixOS VM images
concurrency:
group: ${{ ( github.event_name == 'push' && 'test' ) || 'release' }}
cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
on:
workflow_dispatch:
schedule:
- cron: "0 4 * * *"
push:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions: write-all
outputs:
timestamp: ${{ steps.get-timestamp.outputs.time }}
tag_name: ${{ steps.generate_env_vars.outputs.tag_name }}
configs: ${{ steps.get-configs.outputs.configs }}
arches: ${{ steps.get-arches.outputs.arches }}
steps:
- uses: actions/checkout@v4
- name: Get configuration files
id: get-configs
run: |
cd ./configurations
echo "configs=$(ls *.nix | sed -e 's/\.nix$//' | jq -R -s -c 'split("\n")[:-1]')" >> "$GITHUB_OUTPUT"
- name: Get architectures
id: get-arches
run: |
arches=`cat ./architectures.json`
delimiter="$(openssl rand -hex 8)"
echo "arches<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "${arches}" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
- name: Get build timestamp
id: get-timestamp
run: |
echo "time=$(/bin/date -u "+%Y-%m-%d")" >> $GITHUB_OUTPUT
- name: Generate environmental variables
id: generate_env_vars
run: |
echo "tag_name=nixos-image-${{ ( github.event_name == 'push' && 'test' ) || steps.get-timestamp.outputs.time }}" >> $GITHUB_OUTPUT
echo "release_name=${{ ( github.event_name == 'push' && format('Test Build {0}', steps.get-timestamp.outputs.time) ) || format('Build {0}', steps.get-timestamp.outputs.time) }}" >> $GITHUB_OUTPUT
- name: Check for existing tag
id: check-tag
run: |
if gh release view "${{ steps.generate_env_vars.outputs.tag_name }}" -R ${{ github.repository }}; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Clear previous release
run: gh release delete ${{ steps.generate_env_vars.outputs.tag_name }} --yes --cleanup-tag -R ${{ github.repository }}
if: ${{ steps.check-tag.outputs.exists == 'true' }}
- name: Create new release
run: |
gh release create ${{ steps.generate_env_vars.outputs.tag_name }} --title "${{ steps.generate_env_vars.outputs.release_name }}" --generate-notes=false --draft=false --latest=false --prerelease=true
stage1-prebuild:
needs: release
uses: ./.github/workflows/prebuild.yml
with:
stage: stage1
architectures: ${{ needs.release.outputs.arches }}
stage2-prebuild:
needs: [release, stage1-prebuild]
uses: ./.github/workflows/prebuild.yml
with:
stage: stage2
architectures: ${{ needs.release.outputs.arches }}
stage3-prebuild:
needs: [release, stage2-prebuild]
uses: ./.github/workflows/prebuild.yml
with:
stage: stage3
architectures: ${{ needs.release.outputs.arches }}
stage4-prebuild:
needs: [release, stage3-prebuild]
uses: ./.github/workflows/prebuild.yml
with:
stage: stage4
architectures: ${{ needs.release.outputs.arches }}
final-prebuild:
needs: [release, stage4-prebuild]
uses: ./.github/workflows/prebuild.yml
with:
stage: final
architectures: ${{ needs.release.outputs.arches }}
stdenv-prebuild:
needs: [release, final-prebuild]
uses: ./.github/workflows/prebuild.yml
with:
stage: stdenv
architectures: ${{ needs.release.outputs.arches }}
builds:
needs: [release, stdenv-prebuild]
strategy:
fail-fast: false
matrix:
configuration: ${{ fromJson(needs.release.outputs.configs) }}
architecture: ${{ fromJson(needs.release.outputs.arches) }}
type:
- name: EC2
format: amazon
ext: vhd
- name: Azure
format: azure
ext: vhd
- name: Digital Ocean
format: do
ext: qcow2.gz
- name: Docker
format: docker
ext: tar.xz
- name: GCE
format: gce
ext: raw.tar.gz
- name: HyperV
format: hyperv
ext: vhdx
- name: ISO
format: iso
ext: iso
- name: KubeVirt
format: kubevirt
ext: qcow2
- name: Linode
format: linode
ext: img.gz
- name: Oracle Cloud
format: oracle
ext: qcow2
- name: Proxmox
format: proxmox
ext: vma.zst
- name: Proxmox LXC
format: proxmox-lxc
ext: tar.xz
- name: QEMU
format: qcow
ext: qcow2
- name: Raw BIOS Bootable
format: raw
ext: img
- name: Raw EFI Bootable
format: raw-efi
ext: img
- name: Vagrant
format: vagrant-virtualbox
ext: box
- name: Virtualbox
format: virtualbox
ext: ova
- name: VMWare
format: vmware
ext: vmdk
name: ${{ matrix.type.name }} Image (${{ matrix.configuration }}, ${{ matrix.architecture }})
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Binfmt
uses: docker/setup-qemu-action@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
with:
extra-conf: |
extra-platforms = ${{ matrix.architecture }}-linux
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 32
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Download Prebuilt stdenv
uses: actions/download-artifact@v4
with:
name: ${{ matrix.architecture }}-prebuild-cache
path: ${{ runner.temp }}/${{ matrix.architecture }}-prebuild-cache
- name: Build
run: |
relimit() { printf %s "$1" |sed 's/ /%20/g'; }
NIX_SUBSTITUTERS_ARGS=" \
--option require-sigs false \
--option extra-trusted-substituters file://$(relimit '${{ runner.temp }}/${{ matrix.architecture }}-prebuild-cache')?priority=100 \
--option extra-substituters file://$(relimit '${{ runner.temp }}/${{ matrix.architecture }}-prebuild-cache')?priority=100 \
"
cp -LR "$(nix build $NIX_SUBSTITUTERS_ARGS .#nixosConfigurations.nixos-${{ matrix.configuration }}-${{ matrix.architecture }}.config.formats.${{ matrix.type.format }} --print-out-paths)" '${{ runner.temp }}'
- name: Upload
run: |
filepath=$(find -L "${{ runner.temp }}" -type f -name '*.${{ matrix.type.ext }}' | head -n 1)
chmod 755 "$filepath"
newpath="nixos-${{ matrix.type.format }}${{ ( matrix.configuration != 'default' && format('-{0}', matrix.configuration) ) || '' }}${{ ( matrix.architecture != 'x86_64' && format('-{0}', matrix.architecture) ) || '' }}.7z"
7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=256m -ms=on "$newpath" "$filepath"
chmod 755 "$newpath"
gh release upload ${{ needs.release.outputs.tag_name }} "$newpath" --repo ${{ github.repository }}
publish:
needs: [release, builds]
name: Publish
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Set as latest
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
run: |
gh release edit ${{ needs.release.outputs.tag_name }} --draft=false --prerelease=false --latest=true --repo ${{ github.repository }}