-
Notifications
You must be signed in to change notification settings - Fork 268
190 lines (167 loc) · 5.95 KB
/
Copy pathnix-build.yml
File metadata and controls
190 lines (167 loc) · 5.95 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
name: Nix Build
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: read
pull-requests: write
jobs:
check-workspace-sync:
name: Check flake.nix workspace sync
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Check workspace sync
id: check
run: |
set -euo pipefail
if node scripts/check-nix-workspace.mjs; then
echo "SYNC_OK=true" >> "$GITHUB_OUTPUT"
else
echo "SYNC_OK=false" >> "$GITHUB_OUTPUT"
fi
- name: Extract missing items
if: steps.check.outputs.SYNC_OK == 'false' && github.event_name == 'pull_request'
id: missing
run: |
{
echo "body<<EOF"
echo "<!-- nix-workspace-sync-bot -->"
echo "❌ flake.nix workspace lists out of sync"
echo ""
echo "The recursive workspace dependencies of \`apps/kimi-code\` do not match \`flake.nix\`. Please run \`node scripts/check-nix-workspace.mjs\` locally for details."
echo ""
echo "Typical fix: add the missing package name to \`workspaceNames\` and its path to \`workspacePaths\` in \`flake.nix\`."
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Post or update PR comment
if: steps.check.outputs.SYNC_OK == 'false' && github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
COMMENT_BODY: ${{ steps.missing.outputs.body }}
with:
script: |
const marker = '<!-- nix-workspace-sync-bot -->';
const body = process.env.COMMENT_BODY;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c =>
c.user.login === 'github-actions[bot]' && c.body.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Fail if workspace sync failed
if: steps.check.outputs.SYNC_OK == 'false'
run: exit 1
nix-build:
name: nix build .#kimi-code
needs: check-workspace-sync
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix-path: nixpkgs=channel:nixos-unstable
- name: Build
id: build
run: |
set -euo pipefail
LOG_FILE="$(mktemp)"
if nix build .#kimi-code --print-build-logs 2>&1 | tee "$LOG_FILE"; then
echo "BUILD_FAILED=false" >> "$GITHUB_OUTPUT"
else
echo "BUILD_FAILED=true" >> "$GITHUB_OUTPUT"
echo "LOG_FILE=$LOG_FILE" >> "$GITHUB_OUTPUT"
fi
- name: Extract error log
if: steps.build.outputs.BUILD_FAILED == 'true' && github.event_name == 'pull_request'
id: error
run: |
LOG_FILE="${{ steps.build.outputs.LOG_FILE }}"
# Extract hash mismatch info
SPECIFIED=$(grep -oP 'specified:\s+\K\S+' "$LOG_FILE" || true)
GOT=$(grep -oP 'got:\s+\K\S+' "$LOG_FILE" || true)
if [ -n "$SPECIFIED" ] && [ -n "$GOT" ]; then
{
echo "body<<EOF"
echo "❌ Nix build failed"
echo ""
echo "Hash mismatch in \`pnpmDeps\`:"
echo "| | Hash |"
echo "|---|---|"
echo "| **specified** | \`$SPECIFIED\` |"
echo "| **got** | \`$GOT\` |"
echo ""
echo "Please update \`flake.nix\` with the **got** hash."
echo "EOF"
} >> "$GITHUB_OUTPUT"
else
TAIL=$(tail -n 80 "$LOG_FILE" | sed 's/^/ /')
{
echo "body<<EOF"
echo "❌ Nix build failed"
echo ""
echo "\`\`\`"
echo "$TAIL"
echo "\`\`\`"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi
- name: Post or update PR comment
if: steps.build.outputs.BUILD_FAILED == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
COMMENT_BODY: ${{ steps.error.outputs.body }}
with:
script: |
const marker = '<!-- nix-build-bot -->';
const body = marker + '\n' + process.env.COMMENT_BODY;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c =>
c.user.login === 'github-actions[bot]' && c.body.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Fail the job if build failed
if: steps.build.outputs.BUILD_FAILED == 'true'
run: exit 1