-
-
Notifications
You must be signed in to change notification settings - Fork 49
175 lines (175 loc) · 7.63 KB
/
Copy pathtest.yml
File metadata and controls
175 lines (175 loc) · 7.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
name: test
on:
push:
branches: [main]
paths: ["**/*.nix"]
pull_request:
types: [labeled, opened, synchronize, reopened, review_requested, ready_for_review]
paths: ["**/*.nix"]
pull_request_review:
types: [submitted]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# never cancel main builds: back-to-back merges would leave main untested
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
NIX_PATH: "nixpkgs=https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"
jobs:
non-draft:
runs-on: ubuntu-latest
# review events: only approvals re-trigger CI; comment reviews would
# otherwise produce skipped check runs that overwrite real test results
if: ${{github.ref == 'refs/heads/main' || (github.event.pull_request.draft == false && (github.event_name != 'pull_request_review' || github.event.review.state == 'approved'))}}
outputs:
nix-changed: ${{ steps.diff.outputs.nix-changed }}
steps:
- uses: actions/checkout@v6
- id: diff
# pull_request_review has no paths filter, so docs-only PRs reach here;
# downstream jobs skip on nix-changed=false (skipped required checks
# count as passing, which is what lets docs-only PRs merge)
run: |
if [[ "${{github.ref}}" == "refs/heads/main" ]]; then
echo "nix-changed=true" >> "$GITHUB_OUTPUT"
else
git fetch --depth 1 origin refs/heads/main
if git diff --name-only origin/main..${{github.sha}} -- | grep -q '\.nix$'; then
echo "nix-changed=true" >> "$GITHUB_OUTPUT"
else
echo "nix-changed=false" >> "$GITHUB_OUTPUT"
fi
fi
allow-ci:
needs: [non-draft]
name: allow-ci
runs-on: ubuntu-latest
steps:
- name: Check access
if: ${{github.event_name == 'pull_request' || github.event_name == 'pull_request_review'}}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# labels are queried live, not from github.event: re-runs reuse the
# payload frozen at trigger time, so a label added after a failure
# would never be seen. auto-allow-ci's GITHUB_TOKEN labeling also does
# not re-trigger workflows, hence the permission-check fallback.
run: |
if gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name' | grep -qx 'allow-ci'; then
exit 0
fi
perm=$(gh api repos/${{ github.repository }}/collaborators/${{ github.event.pull_request.user.login }}/permission --jq '.permission') || perm=none
if [[ "$perm" != "admin" && "$perm" != "write" ]]; then
echo "::error::PR author does not have write access and PR is missing allow-ci label"
exit 1
fi
ci-deep:
needs: [non-draft, allow-ci]
# runs even when allow-ci fails so the required check goes red instead of
# skipped (skipped required checks count as passing and would allow merge)
if: ${{!cancelled() && needs.non-draft.result == 'success' && needs.non-draft.outputs.nix-changed == 'true'}}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
name: Tests ${{matrix.os}}
runs-on: ${{matrix.os}}
steps:
- name: Require allow-ci
run: test "${{needs.allow-ci.result}}" == "success"
- uses: wimpysworld/nothing-but-nix@v10
- uses: cachix/install-nix-action@v31
- uses: DeterminateSystems/magic-nix-cache-action@v13
- uses: actions/checkout@v6
- run: nix-shell --run 'just ci-deep'
flake-check:
needs: [non-draft, allow-ci]
if: ${{!cancelled() && needs.non-draft.result == 'success' && needs.non-draft.outputs.nix-changed == 'true'}}
name: nix flake check
runs-on: ubuntu-latest
steps:
- name: Require allow-ci
run: test "${{needs.allow-ci.result}}" == "success"
- uses: cachix/install-nix-action@v31
- run: nix flake check -L github:vic/checkmate --override-input target github:$GITHUB_REPOSITORY/$GITHUB_SHA
noflake:
needs: [non-draft, allow-ci]
if: ${{needs.non-draft.outputs.nix-changed == 'true'}}
name: noflake
runs-on: ubuntu-latest
steps:
- uses: wimpysworld/nothing-but-nix@v10
- uses: cachix/install-nix-action@v31
- uses: DeterminateSystems/magic-nix-cache-action@v13
- uses: actions/checkout@v6
- run: sed -i 's@# den.outPath@den.outPath@' templates/noflake/default.nix
- run: |
cat <<-EOF > templates/noflake/modules/ci-runtime.nix
{
_module.args.CI = true;
}
EOF
git add templates/noflake/modules/ci-runtime.nix
- run: (cd templates/noflake && nix-build ./default.nix -A flake.nixosConfigurations.igloo.config.system.build.toplevel)
- run: (cd templates/noflake && nix-shell ./default.nix -A den.sh --run 'igloo build --offline')
template:
needs: [non-draft, allow-ci]
if: ${{needs.non-draft.outputs.nix-changed == 'true'}}
# max-parallel: 2
strategy:
matrix:
template: [bogus, minimal, microvm, nvf-standalone, flake-parts-modules]
os: [ubuntu-latest]
name: Check template ${{matrix.template}} ${{matrix.os}}
runs-on: ${{matrix.os}}
steps:
- uses: wimpysworld/nothing-but-nix@v10
- uses: cachix/install-nix-action@v31
- uses: DeterminateSystems/magic-nix-cache-action@v13
- uses: actions/checkout@v6
- run: |
cat <<-EOF > templates/${{matrix.template}}/modules/ci-runtime.nix
{
_module.args.CI = true;
}
EOF
git add templates/${{matrix.template}}/modules/ci-runtime.nix
- run: nix flake check -L ./templates/${{matrix.template}} --override-input den github:$GITHUB_REPOSITORY/$GITHUB_SHA
- run: (cd templates/nvf-standalone && nix build .#my-neovim --override-input den github:$GITHUB_REPOSITORY/$GITHUB_SHA)
if: matrix.template == 'nvf-standalone'
- run: (cd templates/minimal && nix build .#.nixosConfigurations.igloo.config.system.build.toplevel --override-input den github:$GITHUB_REPOSITORY/$GITHUB_SHA)
if: matrix.template == 'minimal'
- run: |
cd templates/minimal
sed -i "s#github:$GITHUB_REPOSITORY#github:$GITHUB_REPOSITORY/$GITHUB_SHA#" flake.nix
nix flake update den
nix run .#igloo -- build --offline
if: matrix.template == 'minimal'
- run: (cd templates/flake-parts-modules && nix develop .# --override-input den github:$GITHUB_REPOSITORY/$GITHUB_SHA --command cowsay)
if: matrix.template == 'flake-parts-modules'
flake-file-template:
needs: [non-draft, allow-ci]
if: ${{needs.non-draft.outputs.nix-changed == 'true'}}
strategy:
matrix:
os: [ubuntu-latest]
template: [default, example]
name: Check template ${{matrix.template}} ${{matrix.os}}
runs-on: ${{matrix.os}}
steps:
- uses: wimpysworld/nothing-but-nix@v10
if: matrix.os == 'ubuntu-latest'
- uses: cachix/install-nix-action@v31
- uses: DeterminateSystems/magic-nix-cache-action@v13
- run: nix flake init -t github:$GITHUB_REPOSITORY/$GITHUB_SHA#${{matrix.template}}
- run: |
cat <<-EOF > modules/ci-runtime.nix
{ lib, ... }:
{
flake-file.inputs.den.url = lib.mkForce "github:$GITHUB_REPOSITORY/$GITHUB_SHA";
_module.args.CI = true;
}
EOF
- run: nix run .#write-flake --override-input den "github:$GITHUB_REPOSITORY/$GITHUB_SHA"
- run: nix flake update den
- run: nix run .#write-flake
- run: nix flake metadata
- run: nix flake check -L --no-build