-
Notifications
You must be signed in to change notification settings - Fork 0
349 lines (298 loc) · 12.1 KB
/
pr-build-test.yaml
File metadata and controls
349 lines (298 loc) · 12.1 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
name: PR Build Test
on:
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to build'
type: number
required: true
host:
description: 'Target host'
type: choice
options:
- x86_64-Linux
- aarch64-Linux
- riscv64-Linux
- ALL
default: x86_64-Linux
permissions:
attestations: write
contents: write
id-token: write
packages: write
pull-requests: write
concurrency:
group: pr-build-${{ inputs.pr_number }}
cancel-in-progress: true
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
changed_recipes: ${{ steps.detect.outputs.changed_recipes }}
has_changes: ${{ steps.detect.outputs.has_changes }}
pr_head_sha: ${{ steps.pr-info.outputs.head_sha }}
steps:
- name: Get PR info
id: pr-info
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_DATA=$(gh api repos/${{ github.repository }}/pulls/${{ inputs.pr_number }})
HEAD_SHA=$(echo "$PR_DATA" | jq -r '.head.sha')
BASE_SHA=$(echo "$PR_DATA" | jq -r '.base.sha')
HEAD_REF=$(echo "$PR_DATA" | jq -r '.head.ref')
echo "head_sha=${HEAD_SHA}" >> $GITHUB_OUTPUT
echo "base_sha=${BASE_SHA}" >> $GITHUB_OUTPUT
echo "head_ref=${HEAD_REF}" >> $GITHUB_OUTPUT
echo "::notice::PR #${{ inputs.pr_number }}: ${HEAD_REF} (${HEAD_SHA})"
- name: Checkout PR
uses: actions/checkout@v6
with:
ref: ${{ steps.pr-info.outputs.head_sha }}
fetch-depth: 0
- name: Detect changed recipes
id: detect
env:
BASE_SHA: ${{ steps.pr-info.outputs.base_sha }}
run: |
# Get changed files between base and PR head
CHANGED_FILES=$(git diff --name-only "${BASE_SHA}" HEAD -- 'binaries/**/*.yaml' 'packages/**/*.yaml' 2>/dev/null || true)
echo "Changed recipe files:"
echo "$CHANGED_FILES"
CHANGED_RECIPES="[]"
for file in $CHANGED_FILES; do
if [ -f "$file" ]; then
CHANGED_RECIPES=$(echo "$CHANGED_RECIPES" | jq --arg path "$file" '. + [{"path": $path}]')
fi
done
RECIPE_COUNT=$(echo "$CHANGED_RECIPES" | jq 'length')
echo "::notice::Found ${RECIPE_COUNT} changed recipes"
echo "changed_recipes=$(echo "$CHANGED_RECIPES" | jq -c .)" >> $GITHUB_OUTPUT
if [ "$RECIPE_COUNT" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
build:
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true'
strategy:
fail-fast: false
max-parallel: 2
matrix:
recipe: ${{ fromJson(needs.detect-changes.outputs.changed_recipes) }}
uses: ./.github/workflows/matrix_builds.yaml
with:
host: ${{ inputs.host }}
sbuild-url: "https://raw.githubusercontent.com/${{ github.repository }}/${{ needs.detect-changes.outputs.pr_head_sha }}/${{ matrix.recipe.path }}"
ghcr-url: ${{ format('ghcr.io/{0}', github.repository_owner) }}
pkg-family: ${{ github.event.repository.name }}
rebuild: true
logs: true
metadata-release: false
secrets: inherit
update-cache:
needs: [detect-changes, build]
if: always() && needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v6
with:
ref: ${{ needs.detect-changes.outputs.pr_head_sha }}
- name: Download sbuild-linter (for hash)
run: |
curl -fsSL "https://github.com/pkgforge/sbuilder/releases/download/latest/sbuild-linter-x86_64-linux" \
-o /usr/local/bin/sbuild-linter || exit 0
chmod +x /usr/local/bin/sbuild-linter
- name: Download sbuild-cache
run: |
curl -fsSL "https://github.com/pkgforge/sbuilder/releases/download/latest/sbuild-cache-x86_64-linux" \
-o /usr/local/bin/sbuild-cache || exit 0
chmod +x /usr/local/bin/sbuild-cache
- name: Download existing cache
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release download build-cache -p build_cache.sdb -D /tmp/ --repo "${{ github.repository }}" || \
sbuild-cache --cache /tmp/build_cache.sdb init
- name: Update cache with recipe hashes
run: |
RECIPES='${{ needs.detect-changes.outputs.changed_recipes }}'
BUILD_RESULT="${{ needs.build.result }}"
echo "$RECIPES" | jq -c '.[]' | while read -r recipe; do
path=$(echo "$recipe" | jq -r '.path')
pkg_name=$(basename "$(dirname "$path")")
# Extract version from recipe's pkgver field
pkg_version="unknown"
if [ -f "$path" ]; then
pkg_version=$(grep -E "^pkgver:" "$path" | head -1 | sed 's/pkgver:[[:space:]]*//; s/^["'"'"']//; s/["'"'"']$//' || echo "unknown")
[ -z "$pkg_version" ] && pkg_version="unknown"
fi
# Compute recipe hash (excluding version for consistency)
if [ -f "$path" ]; then
recipe_hash=$(sbuild-linter hash --exclude-version "$path" 2>/dev/null || sha256sum "$path" | cut -d' ' -f1)
else
recipe_hash="unknown"
fi
status="success"
if [ "$BUILD_RESULT" != "success" ]; then
status="failure"
fi
echo "Caching: $pkg_name v${pkg_version} (hash: ${recipe_hash:0:16}..., status: $status)"
sbuild-cache --cache /tmp/build_cache.sdb update \
--package "$pkg_name" \
--version "$pkg_version" \
--hash "$recipe_hash" \
--status "$status" || true
done
- name: Upload updated cache
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ -f "/tmp/build_cache.sdb" ]; then
gh release upload build-cache /tmp/build_cache.sdb --clobber --repo "${{ github.repository }}" || {
gh release create build-cache \
--title "Build Cache" \
--notes "Build cache for CI" \
--prerelease \
--repo "${{ github.repository }}" \
/tmp/build_cache.sdb
}
fi
comment-result:
needs: [detect-changes, build]
if: always() && needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
permissions:
pull-requests: write
actions: read
steps:
- name: Download build status artifacts
uses: actions/download-artifact@v7
with:
pattern: build-status-*
path: /tmp/build-status
merge-multiple: false
continue-on-error: true
- name: Generate detailed comment
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
BUILD_STATUS="${{ needs.build.result }}"
RECIPES='${{ needs.detect-changes.outputs.changed_recipes }}'
HOST="${{ inputs.host }}"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
REPO_OWNER="${{ github.repository_owner }}"
# Build results table header
echo "| Recipe | Host | Status | Package |" > /tmp/results_table.md
echo "|--------|------|--------|---------|" >> /tmp/results_table.md
# Process build status artifacts
SUCCESS_COUNT=0
FAILURE_COUNT=0
SKIPPED_COUNT=0
if [ -d "/tmp/build-status" ]; then
for status_dir in /tmp/build-status/build-status-*/; do
[ -d "$status_dir" ] || continue
status_file="${status_dir}build-status.json"
[ -f "$status_file" ] || continue
host=$(jq -r '.host // "unknown"' "$status_file")
status=$(jq -r '.status // "unknown"' "$status_file")
recipe_url=$(jq -r '.recipe_url // ""' "$status_file")
ghcr_url=$(jq -r '.ghcr_url // ""' "$status_file")
# Extract recipe path from URL
recipe_path=$(echo "$recipe_url" | grep -oE '(binaries|packages)/[^"]+\.yaml' || echo "unknown")
pkg_family=$(echo "$recipe_path" | cut -d'/' -f2)
recipe_name=$(basename "$recipe_path" .yaml 2>/dev/null || echo "unknown")
# Determine cache type from pkg_type (first part of recipe name)
pkg_type=$(echo "$recipe_name" | cut -d'.' -f1)
if [ "$pkg_type" = "static" ] || [ "$pkg_type" = "dynamic" ]; then
CACHE_TYPE="bincache"
else
CACHE_TYPE="pkgcache"
fi
case "$status" in
success)
STATUS_ICON="✅"
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
if [ -n "$ghcr_url" ] && [ "$ghcr_url" != "null" ] && [ "$ghcr_url" != "" ]; then
# Show GHCR URLs directly (more useful for pulling)
PKG_COUNT=$(echo "$ghcr_url" | tr ',' '\n' | wc -l)
if [ "$PKG_COUNT" -gt 1 ]; then
# Multiple packages - show as code block with all URLs
PKG_LINK=$(echo "$ghcr_url" | tr ',' '\n' | sed 's/^/`/; s/$/`/' | tr '\n' ' ')
else
PKG_LINK="\`${ghcr_url}\`"
fi
else
PKG_LINK="-"
fi
;;
failure)
STATUS_ICON="❌"
FAILURE_COUNT=$((FAILURE_COUNT + 1))
PKG_LINK="-"
;;
skipped)
STATUS_ICON="⏭️"
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
PKG_LINK="-"
;;
*)
STATUS_ICON="⚠️"
PKG_LINK="-"
;;
esac
echo "| \`${recipe_path}\` | \`${host}\` | ${STATUS_ICON} ${status} | ${PKG_LINK} |" >> /tmp/results_table.md
done
fi
RESULTS_TABLE=$(cat /tmp/results_table.md)
TOTAL=$((SUCCESS_COUNT + FAILURE_COUNT + SKIPPED_COUNT))
# Overall status header
if [ "$BUILD_STATUS" == "success" ]; then
HEADER_EMOJI="✅"
HEADER_TEXT="Build Test Passed"
elif [ "$BUILD_STATUS" == "failure" ]; then
HEADER_EMOJI="❌"
HEADER_TEXT="Build Test Failed"
elif [ "$BUILD_STATUS" == "skipped" ]; then
HEADER_EMOJI="⏭️"
HEADER_TEXT="Build Test Skipped"
else
HEADER_EMOJI="⚠️"
HEADER_TEXT="Build Test: ${BUILD_STATUS}"
fi
# Summary line
SUMMARY="**${SUCCESS_COUNT}** passed"
[ "$FAILURE_COUNT" -gt 0 ] && SUMMARY="${SUMMARY}, **${FAILURE_COUNT}** failed"
[ "$SKIPPED_COUNT" -gt 0 ] && SUMMARY="${SUMMARY}, **${SKIPPED_COUNT}** skipped"
# Build the comment using heredoc for proper formatting
cat > /tmp/comment.md << EOF
## ${HEADER_EMOJI} ${HEADER_TEXT}
| | |
|---|---|
| **Target** | \`${HOST}\` |
| **Commit** | \`${{ needs.detect-changes.outputs.pr_head_sha }}\` |
| **Summary** | ${SUMMARY} |
### Build Results
${RESULTS_TABLE}
<details>
<summary>📋 View workflow logs</summary>
**Workflow Run:** [${RUN_URL}](${RUN_URL})
</details>
---
<sub>🤖 Triggered via workflow_dispatch by @${{ github.actor }}</sub>
EOF
gh pr comment "${{ inputs.pr_number }}" \
--repo "${{ github.repository }}" \
--body-file /tmp/comment.md
no-changes:
needs: detect-changes
if: needs.detect-changes.outputs.has_changes != 'true'
runs-on: ubuntu-latest
steps:
- name: No recipes to build
run: |
echo "::warning::No recipe changes detected in PR #${{ inputs.pr_number }}"