Repository navigation
245 lines (230 loc) · 9.75 KB
/
Copy pathbuild-src.yml
File metadata and controls
245 lines (230 loc) · 9.75 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
name: Build source
on:
workflow_call:
inputs:
build-target:
description: "Target name as defined by inputs.sh"
required: true
type: string
container-path:
description: "Path to built container at registry"
required: true
type: string
depends-key:
description: "Key needed to access cached depends; empty builds against system libraries"
required: false
type: string
default: ""
depends-host:
description: "Host triplet from depends build"
required: false
type: string
default: ""
depends-dep-opts:
description: "DEP_OPTS used to build depends"
required: false
type: string
default: ""
depends-artifact:
description: "Artifact holding freshly built depends, used if the cache restore misses"
required: false
type: string
default: ""
runs-on:
description: "Runner label to use (e.g., ubuntu-24.04 or ubuntu-24.04-arm)"
required: true
type: string
secrets:
CCACHE_REMOTE_AUTH:
description: "user:password allowed to write to the remote ccache; empty means read-only"
required: false
outputs:
key:
description: "Key needed for restoring artifacts bundle"
value: ${{ jobs.build-src.outputs.key }}
freshness:
description: "current or superseded relative to develop's tip at the end of the build; empty if unknown"
value: ${{ jobs.build-src.outputs.freshness }}
jobs:
build-src:
name: Build source
runs-on: ${{ inputs.runs-on }}
outputs:
key: ${{ steps.bundle.outputs.key }}
freshness: ${{ steps.freshness.outputs.freshness }}
container:
image: ${{ inputs.container-path }} # zizmor: ignore[unpinned-images] built earlier in this run by build-container.yml
# SYS_PTRACE is required by LeakSanitizer's stop-the-world
# (https://github.com/google/sanitizers/issues/764)
options: --user root --cap-add SYS_PTRACE
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
persist-credentials: false
fetch-depth: 50
- name: Initial setup
id: setup
env:
BUILD_TARGET: ${{ inputs.build-target }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha || '' }}
run: |
git config --global --add safe.directory "$PWD"
git fetch -fu origin develop:develop
source ./ci/dash/matrix.sh
echo "HOST=${HOST}" >> $GITHUB_OUTPUT
echo "PR_BASE_SHA=${PR_BASE_SHA}" >> $GITHUB_OUTPUT
shell: bash
- name: Restore depends cache
id: depends-cache
if: inputs.depends-key != ''
uses: actions/cache/restore@v5
with:
path: depends/built/${{ inputs.depends-host }}
key: ${{ inputs.depends-key }}
- name: Download built depends
# Same-run handoff from build-depends.yml: pull_request_target runs
# have read-only cache tokens (GitHub change, June 2026), so freshly
# built depends arrive as an artifact instead of a cache entry. Also
# covers trusted runs whose cache save was denied (save only warns).
if: inputs.depends-key != '' && steps.depends-cache.outputs.cache-hit != 'true' && inputs.depends-artifact != ''
uses: actions/download-artifact@v8
with:
name: ${{ inputs.depends-artifact }}
path: depends/built/${{ inputs.depends-host }}
- name: Check built depends are present
if: inputs.depends-key != '' && steps.depends-cache.outputs.cache-hit != 'true' && inputs.depends-artifact == ''
run: |
echo "::error::Depends cache restore missed and no built depends artifact was provided"
exit 1
shell: bash
- name: Rebuild depends prefix
if: inputs.depends-key != ''
env:
DEPENDS_HOST: ${{ inputs.depends-host }}
DEP_OPTS: ${{ inputs.depends-dep-opts }}
run: |
# Use the HOST and DEP_OPTS from the depends build, not this build-target
# This ensures the build_id matches the cached packages
# DEP_OPTS may contain shell-quoted values, e.g. CXX='clang++-19 -stdlib=libc++'
eval "DEP_OPTS_ARGS=(${DEP_OPTS})"
make -j$(nproc) -C depends HOST="${DEPENDS_HOST}" "${DEP_OPTS_ARGS[@]}"
shell: bash
- name: Restore ccache cache
uses: actions/cache/restore@v5
with:
path: |
/cache/ccache
key: ccache-${{ hashFiles('contrib/containers/ci/ci.Dockerfile', 'depends/packages/*') }}-${{ inputs.build-target }}-${{ github.sha }}
restore-keys: |
ccache-${{ hashFiles('contrib/containers/ci/ci.Dockerfile', 'depends/packages/*') }}-${{ inputs.build-target }}-
- name: Configure remote ccache
# Second-level cache behind the GitHub one restored above. Every run
# reads from it; only runs given CCACHE_REMOTE_AUTH (see check-skip in
# build.yml) write. Any problem here leaves the build on the local
# cache alone rather than failing it.
if: vars.CCACHE_REMOTE_DISABLE == ''
env:
REMOTE_URL: ${{ vars.CCACHE_REMOTE_URL || 'https://cache.thepasta.org' }}
REMOTE_AUTH: ${{ secrets.CCACHE_REMOTE_AUTH }}
run: |
# Pull requests opened before the image gained ccache 4.14 still
# build with apt's 4.9, which rejects this configuration outright.
if ! command -v ccache-storage-https > /dev/null; then
echo "Remote ccache: off (this image has no HTTPS storage helper)"
exit 0
fi
if ! curl -fsS --max-time 5 -o /dev/null "${REMOTE_URL}/status"; then
echo "::warning::Remote ccache: off (${REMOTE_URL} is unreachable)"
exit 0
fi
mode="read-only"
options="read-only=true"
if [[ -n "${REMOTE_AUTH}" ]]; then
host="${REMOTE_URL#*://}"
host="${host%%/*}"
host="${host%%:*}"
netrc="${RUNNER_TEMP}/ccache-netrc"
(umask 077 && printf 'machine %s login %s password %s\n' \
"${host}" "${REMOTE_AUTH%%:*}" "${REMOTE_AUTH#*:}" > "${netrc}")
mode="read-write"
options="@netrc-file=${netrc}"
# Also upload local hits the remote lacks, so it refills after a wipe.
echo "CCACHE_RESHARE=true" >> "${GITHUB_ENV}"
fi
echo "CCACHE_REMOTE_STORAGE=${REMOTE_URL} @layout=bazel data-timeout=5s request-timeout=30s ${options}" >> "${GITHUB_ENV}"
echo "Remote ccache: ${mode} (${REMOTE_URL})"
shell: bash
- name: Build source
env:
BUILD_TARGET: ${{ inputs.build-target }}
run: |
# Nothing after this step needs to write to the remote cache, and the
# tests run code built from cached objects; drop the credential even
# if the compile fails.
trap 'rm -f "${RUNNER_TEMP}/ccache-netrc"' EXIT
CCACHE_MAXSIZE="300M"
CACHE_DIR="/cache"
mkdir /output
BASE_OUTDIR="/output"
source ./ci/dash/matrix.sh
./ci/dash/build_src.sh
{ echo "### ccache: ${BUILD_TARGET}"; echo '```'; ccache --show-stats; echo '```'; } >> "${GITHUB_STEP_SUMMARY}"
# Hits refresh mtime, so this keeps only what recent builds used
# and the saved cache stays near one build's working set.
ccache --evict-older-than 1d
ccache -c
du -hd0 "${BASE_OUTDIR}"
rm -rf "${BASE_OUTDIR}"
shell: bash
- name: Save ccache cache
if: |
github.event_name == 'push' &&
github.ref_name == github.event.repository.default_branch
uses: actions/cache/save@v5
with:
path: |
/cache/ccache
key: ccache-${{ hashFiles('contrib/containers/ci/ci.Dockerfile', 'depends/packages/*') }}-${{ inputs.build-target }}-${{ github.sha }}
- name: Run unit tests
env:
BUILD_TARGET: ${{ inputs.build-target }}
run: |
source ./ci/dash/matrix.sh
./ci/dash/test_unittests.sh
shell: bash
- name: Bundle artifacts
id: bundle
env:
BUILD_TARGET: ${{ inputs.build-target }}
run: |
export BUNDLE_KEY="build-${BUILD_TARGET}-$(git rev-parse --short=8 HEAD)"
find "build-ci/dashcore-${BUILD_TARGET}/src/" -name "*.a" -type f -delete
find "build-ci/dashcore-${BUILD_TARGET}/src/" -name "*.o" -type f -delete
./ci/dash/bundle-artifacts.sh create
echo "key=${BUNDLE_KEY}" >> "${GITHUB_OUTPUT}"
- name: Upload artifacts
uses: actions/upload-artifact@v6
with:
name: ${{ steps.bundle.outputs.key }}
path: |
${{ steps.bundle.outputs.key }}.tar.zst
compression-level: 0
overwrite: true
retention-days: 3
- name: Check whether develop has moved on
id: freshness
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
run: |
# Left unset when the lookup fails: tests still run, but only a
# verified-current run may cancel another run's tests.
tip="$(git ls-remote origin "refs/heads/${GITHUB_REF_NAME}" | cut -f1)" || true
if [[ "${tip}" == "${GITHUB_SHA}" ]]; then
echo "freshness=current" >> "${GITHUB_OUTPUT}"
elif [[ -n "${tip}" ]]; then
echo "freshness=superseded" >> "${GITHUB_OUTPUT}"
echo "Superseded by ${tip}: this run's tests will be skipped"
fi
shell: bash