-
Notifications
You must be signed in to change notification settings - Fork 40
196 lines (191 loc) · 8.19 KB
/
build.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
name: Build
on:
workflow_dispatch:
inputs:
nixpkgs-bump:
description: Set to true if this build was triggered by a nixpkgs bump
required: false
default: false
type: boolean
permissions:
contents: write
# requirements for docs:
pages: write
id-token: write
actions: read
concurrency:
group: nyx-main-build
cancel-in-progress: true
jobs:
build:
runs-on: nyxbuilder
timeout-minutes: 1440
outputs:
pushed: ${{ steps.push.outcome == 'success' }}
steps:
- name: Check if already cached
id: check
if: github.event_name == 'push'
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
try {
const valid = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'nyxpkgs-unstable',
head: context.sha
}).then((response) => response.data.status == "ahead" && response.data.ahead_by == 1)
// Needs to be ahead by 1 commit exactly, otherwise we don't consider this PR as being potentially cached
if (valid) {
const PARSED_MESSAGE = context.payload.head_commit.message.split('\n')[0].match(/\(#(\d+)\)$/)
const PR_NUMBER = PARSED_MESSAGE ? PARSED_MESSAGE[1] : null
if (PR_NUMBER) {
const response = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: PR_NUMBER
});
const OUTPUT = response.data;
const PR_LABELS = OUTPUT.labels.map((label) => label.name)
const BASE_COMMIT = OUTPUT.base.sha
const MERGE_COMMIT = OUTPUT.merge_commit_sha
if (PR_LABELS.includes('cached') && BASE_COMMIT === context.payload.before && MERGE_COMMIT === context.sha) {
// Exit with a non-zero exit code to skip the rest of the job
console.log("Potentially cached, verifying if cached...");
// Check if latest non skipped check is successful
const success = await github.rest.checks.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.payload.before,
check_name: 'build',
per_page: 100
}).then((response) => {
const latest = response.data.check_runs.find((check) => check.status == "completed" || check.status == "in_progress");
return latest && latest.conclusion == "success" && latest.status == "completed"
})
if (success) {
console.log("Previous build and PR build was successful, skipping.");
core.setOutput("cached", true)
} else {
console.log("Not cached, building.");
}
}
}
}
} catch (error) {
console.log("Github rest API error encountered, assuming not cached.")
}
- name: Install Nix
if: (success() && steps.check.outputs.cached != 'true')
uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
accept-flake-config = true
sandbox-fallback = false
system-features = big-parallel gccarch-x86-64-v3
install_options: --daemon
# Checkout the main branch
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true
- name: Configure sandboxing
if: (success() && steps.check.outputs.cached != 'true')
run: |
sed -i -e '/^build-users-group =/d' -e 's/max-jobs =.*/max-jobs = 8/g' /etc/nix/nix.conf
nix eval ./maintenance#_dev.nixConfig --json | jq -r 'to_entries[] | "\(.key) = \(.value | join(" "))"' >> /etc/nix/nix.conf
- name: Download cache list
if: (success() && steps.check.outputs.cached != 'true')
run: |
curl -vfo "${{ runner.temp }}/prev-cache.json" -H "Authorization: Bearer ${{ secrets.CACHIX_AUTH_TOKEN_SUPREME }}" \
'https://app.cachix.org/api/v1/cache/chaotic-nyx/contents'
- name: Build
if: (success() && steps.check.outputs.cached != 'true')
id: build
run: |
nix develop ./maintenance -c chaotic-nyx-build || [ $? -eq 42 ]
failed_builds="$(cat ${{ runner.temp }}/failures.txt | sed 's/^/ <li>/; s/$/<\/li>/')"
failed_builds_count="$(cat ${{ runner.temp }}/failures.txt | wc -l)"
unbuildable_count="$(cat ${{ runner.temp }}/eval-failures.txt | wc -l)"
echo "FAILED_BUILDS_COUNT=$failed_builds_count
UNBUILDABLE_COUNT=$unbuildable_count
FAILED_BUILDS<<EOF
$failed_builds
EOF" >> $GITHUB_OUTPUT
env:
NYX_WD: ${{ runner.temp }}
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Update nyxpkgs-unstable
if: (success() && (steps.check.outputs.cached == 'true' || steps.build.outputs.FAILED_BUILDS_COUNT == 0))
id: push
run: |
git push origin HEAD:nyxpkgs-unstable --force
if [ "$BUMP" = "true" ]; then
curl -X POST \
-F token="$GNS_CI_TOKEN" \
-F "ref=main" \
-F "variables[UPDATE]=true" \
https://gitlab.com/api/v4/projects/45677880/trigger/pipeline || true
fi
env:
GNS_CI_TOKEN: ${{ secrets.GNS_CI_TOKEN }}
BUMP: ${{ inputs.nixpkgs-bump }}
- name: Comment on commit
if: (success() && steps.check.outputs.cached != 'true')
uses: actions/github-script@v7
with:
script: |
if (process.env.FAILED_BUILDS_COUNT > 0) {
var extratext = "";
core.setFailed("Build failures found!")
// Check if github actions triggered the event
if (process.env.ACTOR == "github-actions[bot]")
extratext = `\nNew build failures found! Consider adding failed builds to devshells/failures.nix @chaotic-cx/nyxers`
else
extratext = `\nNew build failures found! Consider adding failed builds to devshells/failures.nix @${process.env.ACTOR}`
github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: `Failed to build ${process.env.FAILED_BUILDS_COUNT} packages:
<details>
<summary>${process.env.FAILED_BUILDS_COUNT} packages failed</summary>
<ul>
${process.env.FAILED_BUILDS}
</ul>
</details>${extratext}`
})
} else
github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: `All packages were built and cached successfully! (${process.env.UNBUILDABLE_COUNT} not suitable for building)`
})
env:
FAILED_BUILDS_COUNT: ${{ steps.build.outputs.FAILED_BUILDS_COUNT }}
UNBUILDABLE_COUNT: ${{ steps.build.outputs.UNBUILDABLE_COUNT }}
FAILED_BUILDS: ${{ steps.build.outputs.FAILED_BUILDS }}
ACTOR: ${{ github.actor }}
- name: Upload logs
if: ((success() || failure()) && steps.build.outcome != 'skipped')
uses: actions/upload-artifact@v4
with:
name: logs
path: |
${{ runner.temp }}/*.txt
${{ runner.temp }}/*.nix
docs:
needs: build
uses: ./.github/workflows/document.yml
if: needs.build.outputs.pushed == 'true'
flakehub:
needs: docs
uses: ./.github/workflows/flakehub-publish-rolling.yml
if: needs.build.outputs.pushed == 'true'
# flakestry:
# needs: docs
# uses: ./.github/workflows/flakestry-publish-rolling.yml
# if: needs.build.outputs.pushed == 'true'