Repository navigation
184 lines (173 loc) · 7.45 KB
/
Copy pathbuild-depends.yml
File metadata and controls
184 lines (173 loc) · 7.45 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
name: Build depends
on:
workflow_call:
inputs:
build-target:
description: "Target name as defined by matrix.sh"
required: true
type: string
container-path:
description: "Path to built container at registry"
required: true
type: string
base-image-digest:
description: "Short hash of the CI base image manifest for cache busting"
required: true
type: string
runs-on:
description: "Runner label to use (e.g., ubuntu-24.04 or ubuntu-24.04-arm)"
required: true
type: string
runs-on-check:
description: "Runner label for the check-cache job; any arch, see runs-on-arch"
required: true
type: string
runs-on-arch:
description: "Machine arch (uname -m) of the runs-on runner, so check-cache (which may run on another arch) computes the same HOST the build runner would"
required: false
default: x86_64
type: string
runs-on-build:
description: "Runner label for the build job if not runs-on; runs-on still names the cache key, so either one saves the entry every consumer of this target restores"
required: false
default: ""
type: string
outputs:
key:
description: "Key needed for restoring depends cache"
value: ${{ jobs.check-cache.outputs.cache-key }}
host:
description: "Host triplet for this build target"
value: ${{ jobs.check-cache.outputs.host }}
dep-opts:
description: "DEP_OPTS used to build depends"
value: ${{ jobs.check-cache.outputs.dep-opts }}
built-artifact:
description: "Artifact holding freshly built depends (empty when restored from cache)"
value: ${{ jobs.build.outputs.built-artifact }}
jobs:
check-cache:
name: Check cache
runs-on: ${{ inputs.runs-on-check }}
outputs:
cache-hit: ${{ steps.cache-check.outputs.cache-hit }}
cache-key: ${{ steps.setup.outputs.cache-key }}
cache-key-prefix: ${{ steps.setup.outputs.cache-key-prefix }}
host: ${{ steps.setup.outputs.HOST }}
dep-opts: ${{ steps.setup.outputs.DEP_OPTS }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
persist-credentials: false
sparse-checkout: |
ci/dash
ci/test
depends
contrib/containers/ci/ci.Dockerfile
contrib/containers/ci/ci-slim.Dockerfile
- name: Compute cache key
id: setup
env:
BUILD_TARGET: ${{ inputs.build-target }}
BASE_IMAGE_DIGEST: ${{ inputs.base-image-digest }}
RUNS_ON: ${{ inputs.runs-on }}
# This job may not run on the build runner's arch, so name that arch
# for the targets whose HOST follows the machine (see ci/test).
DEPENDS_ARCH: ${{ inputs.runs-on-arch }}
run: |
source ./ci/dash/matrix.sh
echo "DEP_OPTS=${DEP_OPTS}" >> "${GITHUB_OUTPUT}"
echo "HOST=${HOST}" >> "${GITHUB_OUTPUT}"
echo "RUNNER_ARCH=$(uname -m)" >> "${GITHUB_OUTPUT}"
DEP_HASH="$(echo -n "${BUILD_TARGET}" "${DEP_OPTS}" "${HOST}" | sha256sum | head -c 64)"
echo "DEP_HASH=${DEP_HASH}" >> "${GITHUB_OUTPUT}"
DOCKERFILE_HASH="${{ hashFiles('contrib/containers/ci/ci.Dockerfile', 'contrib/containers/ci/ci-slim.Dockerfile') }}"
DEPENDS_INPUTS_HASH="${{ hashFiles('depends/Makefile', 'depends/funcs.mk', 'depends/gen_id', 'depends/config.guess', 'depends/config.sub', 'depends/config.site.in', 'depends/builders/**', 'depends/hosts/**', 'depends/packages/**', 'depends/patches/**') }}"
CACHE_KEY_PREFIX="depends-${DOCKERFILE_HASH}-${BASE_IMAGE_DIGEST}-${RUNS_ON}-${BUILD_TARGET}"
CACHE_KEY="${CACHE_KEY_PREFIX}-${DEP_HASH}-${DEPENDS_INPUTS_HASH}"
echo "cache-key-prefix=${CACHE_KEY_PREFIX}" >> "${GITHUB_OUTPUT}"
echo "cache-key=${CACHE_KEY}" >> "${GITHUB_OUTPUT}"
echo "Cache key: ${CACHE_KEY}"
shell: bash
- name: Check for cached depends
id: cache-check
uses: actions/cache@v5
with:
path: depends/built/${{ steps.setup.outputs.HOST }}
key: ${{ steps.setup.outputs.cache-key }}
lookup-only: true
build:
name: Build depends
needs: [check-cache]
if: needs.check-cache.outputs.cache-hit != 'true'
runs-on: ${{ inputs.runs-on-build || inputs.runs-on }}
outputs:
built-artifact: depends-built-${{ inputs.build-target }}
container:
image: ${{ inputs.container-path }} # zizmor: ignore[unpinned-images] built earlier in this run by build-container.yml
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
persist-credentials: false
- name: Check depends host matches this runner
# check-cache computed HOST from runs-on-arch; fail loudly if the
# runner that builds disagrees instead of caching for the wrong host.
env:
BUILD_TARGET: ${{ inputs.build-target }}
EXPECTED_HOST: ${{ needs.check-cache.outputs.host }}
run: |
source ./ci/dash/matrix.sh
if [ "${HOST}" != "${EXPECTED_HOST}" ]; then
echo "::error::Build runner computes HOST=${HOST} but check-cache used ${EXPECTED_HOST}; fix runs-on-arch for ${BUILD_TARGET}"
exit 1
fi
shell: bash
- name: Restore depends sources
uses: actions/cache/restore@v5
with:
path: depends/sources
key: depends-sources-${{ hashFiles('depends/packages/*') }}
restore-keys: depends-sources-
- name: Restore cached depends
uses: actions/cache/restore@v5
with:
path: depends/built/${{ needs.check-cache.outputs.host }}
key: ${{ needs.check-cache.outputs.cache-key }}
restore-keys: |
${{ needs.check-cache.outputs.cache-key-prefix }}-
- name: Build depends
env:
HOST: ${{ needs.check-cache.outputs.host }}
DEP_OPTS: ${{ needs.check-cache.outputs.dep-opts }}
run: |
# DEP_OPTS may contain shell-quoted values, e.g. CXX='clang++-19 -stdlib=libc++'
eval "DEP_OPTS_ARGS=(${DEP_OPTS})"
env "${DEP_OPTS_ARGS[@]}" make -j$(nproc) -C depends
shell: bash
- name: Save depends cache
# Cache tokens on untrusted triggers are read-only (GitHub change,
# June 2026), so only trusted events can save the persistent cache
# for later read-only restores.
if: github.event_name != 'pull_request_target'
uses: actions/cache/save@v5
with:
path: depends/built/${{ needs.check-cache.outputs.host }}
key: ${{ needs.check-cache.outputs.cache-key }}
- name: Upload built depends
# Same-run handoff to build-src.yml for runs that cannot save the
# cache. Uploaded on every fresh build (cache/save only warns when
# the write is denied), so src jobs never depend on a save landing.
uses: actions/upload-artifact@v6
with:
name: depends-built-${{ inputs.build-target }}
path: depends/built/${{ needs.check-cache.outputs.host }}
compression-level: 0
retention-days: 1
overwrite: true