-
Notifications
You must be signed in to change notification settings - Fork 13
219 lines (212 loc) · 6.18 KB
/
cicd.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
name: CI/CD
on:
pull_request:
push:
branches:
- master
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
strategy:
fail-fast: true
matrix:
os: [ubuntu-22.04, macos-13]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: ./
with:
nix_archives_url: https://github.com/nixbuild/nix-quick-install-action/releases/download/v28
nix_version: 2.21.0
- uses: cachix/cachix-action@v12
with:
name: nixbuild
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- name: Build nix archives
id: build-nix-archives
run: |
nix build .#nix-archives
echo "result=$(readlink result)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v3
with:
name: nix-archives-${{ runner.os }}
path: ${{ steps.build-nix-archives.outputs.result }}/
test:
needs: build
strategy:
fail-fast: true
matrix:
os:
- ubuntu-22.04
- macos-14
- macos-13
nix_version:
- 2.24.9
- 2.23.3
- 2.22.3
- 2.21.4
- 2.20.8
- 2.19.6
- 2.18.8
- 2.3.18
runs-on: ${{ matrix.os }}
steps:
- uses: divnix/[email protected]
with:
key: test-${{matrix.os}}-nix-${{matrix.nix_version}}-${{github.run_id}}-${{github.run_attempt}}
path: |
/nix
~/.cache/nix
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
id: nix-archives
with:
name: nix-archives-${{ runner.os }}
- uses: ./
with:
nix_archives_url: file://${{steps.nix-archives.outputs.download-path}}
nix_version: ${{ matrix.nix_version }}
nix_on_tmpfs: true
- name: Test nix
run: nix-build -v --version
- name: Add to store
run: |
file="$RANDOM"
echo "$RANDOM" > "$file"
path="$(nix-store --add "./$file")"
mkdir -p ~/.cache/nix
ln -s "$path" ~/.cache/nix/test-path
test-cachix:
needs: build
strategy:
fail-fast: true
matrix:
os:
- ubuntu-22.04
- macos-14
- macos-13
nix_version:
- 2.24.9
- 2.23.3
- 2.22.3
- 2.21.4
- 2.20.8
- 2.19.6
- 2.18.8
- 2.3.18
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
id: nix-archives
with:
name: nix-archives-${{ runner.os }}
- uses: ./
with:
nix_archives_url: file://${{steps.nix-archives.outputs.download-path}}
nix_version: ${{ matrix.nix_version }}
nix_conf: ${{ matrix.nix_conf }}
- uses: cachix/cachix-action@v12
with:
name: nixbuild
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
skipPush: true
- name: Verify nix config
run: |
if ! egrep -q "^substituters = https://cache.nixos.org https://nixbuild.cachix.org$" "$HOME/.config/nix/nix.conf"; then
echo "Invalid substituters config"
exit 1
fi
- name: Push to Cachix
if: github.event_name == 'push' && github.repository_owner == 'nixbuild'
run: |
dd if=/dev/urandom of=random count=1
cachix push nixbuild "$(nix add-to-store random)"
test-overwrite-nix-dir:
needs: test
strategy:
fail-fast: true
matrix:
os:
- ubuntu-22.04
- macos-14
- macos-13
nix_version:
- 2.24.9
- 2.23.3
- 2.22.3
- 2.21.4
- 2.20.8
- 2.19.6
- 2.18.8
- 2.3.18
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
id: nix-archives
with:
name: nix-archives-${{ runner.os }}
# For MacOS, we'll run our action before restoring the cache, in order
# to create the /nix directory, so the cache can be restored. Then we run
# the action again after the cache has been restored. I guess
# divnix/nix-cache-action could be changed to create the /nix directory
# on MacOS.
- name: Create /nix on MacOS
if: ${{ startsWith(matrix.os, 'macos-') }}
uses: ./
with:
nix_archives_url: file://${{steps.nix-archives.outputs.download-path}}
nix_version: ${{ matrix.nix_version }}
- name: Restore cache
uses: divnix/[email protected]
with:
key: test-${{matrix.os}}-nix-${{matrix.nix_version}}-${{github.run_id}}-${{github.run_attempt}}
path: |
/nix
~/.cache/nix
- uses: ./
with:
nix_archives_url: file://${{steps.nix-archives.outputs.download-path}}
nix_version: ${{ matrix.nix_version }}
nix_on_tmpfs: true
- name: Test nix
run: nix-build -v --version
- name: Verify store path
run: |
stat ~/.cache/nix/test-path
nix-store --verify-path ~/.cache/nix/test-path
release:
runs-on: ubuntu-latest
needs:
- build
- test
- test-cachix
- test-overwrite-nix-dir
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: nix-archives-Linux
path: /tmp/archives
- uses: actions/download-artifact@v3
with:
name: nix-archives-macOS
path: /tmp/archives
- uses: ./
with:
nix_archives_url: file:///tmp/archives
nix_version: 2.19.3
- uses: cachix/cachix-action@v12
with:
name: nixbuild
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- name: Build release script
run: nix build .#release
- name: Release if needed
run: ./result/bin/release /tmp/archives ./RELEASE
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}