Repository navigation
227 lines (203 loc) · 8.07 KB
/
Copy pathguix-build.yml
File metadata and controls
227 lines (203 loc) · 8.07 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
name: Guix Build
permissions: {}
on:
pull_request_target: # zizmor: ignore[dangerous-triggers] runs only when a maintainer applies the 'guix-build' label
types: [labeled]
push:
schedule:
# Run weekly at 3 AM UTC on Sunday on the default branch
- cron: '0 3 * * 0'
jobs:
build-image:
permissions:
packages: write
runs-on: ubuntu-24.04-arm
if: |
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || vars.RUN_GUIX_ON_ALL_PUSH == 'true')) ||
contains(github.event.pull_request.labels.*.name, 'guix-build') ||
github.event_name == 'schedule'
outputs:
image: ghcr.io/${{ steps.prepare.outputs.repo-name }}/dashcore-guix-builder@${{ steps.build.outputs.digest }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
persist-credentials: false
path: dash
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Commit variables
id: prepare
env:
TRUSTED: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
run: |
echo "hash=$(sha256sum ./dash/contrib/containers/guix/Dockerfile | cut -d ' ' -f1)" >> $GITHUB_OUTPUT
echo "host_user_id=$(id -u)" >> $GITHUB_OUTPUT
echo "host_group_id=$(id -g)" >> $GITHUB_OUTPUT
BRANCH_NAME=$(echo "${GITHUB_REF##*/}" | tr '[:upper:]' '[:lower:]')
REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
IMAGE="ghcr.io/${REPO_NAME}/dashcore-guix-builder"
# Only trusted events may write tags that other runs read
if [[ "$TRUSTED" == "true" ]]; then
echo "tags=${IMAGE}:${BRANCH_NAME},${IMAGE}:latest,${IMAGE}:trusted-latest" >> "$GITHUB_OUTPUT"
else
echo "tags=${IMAGE}:untrusted" >> "$GITHUB_OUTPUT"
fi
echo "repo-name=${REPO_NAME}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
id: build
uses: docker/build-push-action@v7
with:
context: ${{ github.workspace }}/dash
build-args: |
USER_ID=${{ steps.prepare.outputs.host_user_id }}
GROUP_ID=${{ steps.prepare.outputs.host_group_id }}
build-contexts: |
docker_root=${{ github.workspace }}/dash/contrib/containers/guix
file: ./dash/contrib/containers/guix/Dockerfile
push: true
tags: ${{ steps.prepare.outputs.tags }}
cache-from: type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo-name }}/dashcore-guix-builder:trusted-latest
cache-to: type=inline,mode=max
build:
needs: build-image
# runs-on: [ "self-hosted", "linux", "x64", "ubuntu-core" ]
runs-on: ubuntu-24.04-arm
permissions:
packages: read
id-token: write
attestations: write
strategy:
matrix:
build_target: [x86_64-linux-gnu, aarch64-linux-gnu, riscv64-linux-gnu, powerpc64-linux-gnu, x86_64-w64-mingw32, x86_64-apple-darwin, arm64-apple-darwin]
timeout-minutes: 480
steps:
- name: Disable apparmor user namespace restrictions
run: |
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
persist-credentials: false
path: dash
fetch-depth: 0
# Attested tag builds must not restore caches that labelled
# pull_request_target runs can write
- name: Cache depends sources
if: github.ref_type != 'tag'
uses: actions/cache@v5
with:
path: dash/depends/sources
key: depends-sources-${{ hashFiles('dash/depends/packages/*') }}
restore-keys: |
depends-sources-
- name: Cache Guix and depends
id: guix-cache-restore
if: github.ref_type != 'tag'
uses: actions/cache@v5
with:
path: |
${{ github.workspace }}/.cache
${{ github.workspace }}/dash/depends/built
${{ github.workspace }}/dash/depends/work
/gnu/store
key: ${{ runner.os }}-guix-${{ matrix.build_target }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-guix-${{ matrix.build_target }}
${{ runner.os }}-guix-
- name: Create .cache folder if missing
if: steps.guix-cache-restore.outputs.cache-hit != 'true'
run: mkdir -p .cache
- name: Run Guix build
timeout-minutes: 480
env:
IMAGE: ${{ needs.build-image.outputs.image }}
BUILD_TARGET: ${{ matrix.build_target }}
run: |
docker run --privileged -d --rm -t \
--name guix-daemon \
-v "${GITHUB_WORKSPACE}/dash:/src/dash" \
-v "${GITHUB_WORKSPACE}/.cache:/home/ubuntu/.cache" \
-w /src/dash \
"${IMAGE}" && \
docker exec -e HOSTS="${BUILD_TARGET}" guix-daemon bash -c '/usr/local/bin/guix-start /src/dash'
- name: Ensure build passes
run: |
if [[ $? != 0 ]]; then
echo "Guix build failed!"
exit 1
fi
- name: Compute SHA256 checksums
continue-on-error: true # It will complain on depending on only some hosts
env:
HOSTS: ${{ matrix.build_target }}
run: |
./dash/contrib/containers/guix/scripts/guix-check "${GITHUB_WORKSPACE}/dash"
- name: Upload build artifacts
uses: actions/upload-artifact@v6
with:
name: guix-artifacts-${{ matrix.build_target }}
path: |
${{ github.workspace }}/dash/guix-build*/output/${{ matrix.build_target }}/
compression-level: 0
- name: Attest build provenance
uses: actions/attest@v4
with:
subject-path: ${{ github.workspace }}/dash/guix-build*/output/${{ matrix.build_target }}/*
- name: Upload SHA256SUMS fragment
uses: actions/upload-artifact@v6
with:
name: guix-sha256sums-${{ matrix.build_target }}
path: ${{ github.workspace }}/dash/guix-build*/output/${{ matrix.build_target }}/SHA256SUMS.part
if-no-files-found: error
# Publish the release's guix.sigs-format noncodesigned.SHA256SUMS with a
# keyless (Sigstore) attestation tying it to this workflow and tag
attest:
needs: build
if: github.repository == 'dashpay/dash' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04
permissions:
id-token: write
attestations: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
path: dash
- name: Download SHA256SUMS fragments
uses: actions/download-artifact@v8
with:
pattern: guix-sha256sums-*
path: ${{ runner.temp }}/fragments
merge-multiple: true
- name: Create SHA256SUMS
working-directory: dash
run: |
VERSION="${GITHUB_REF_NAME#v}"
mkdir "${RUNNER_TEMP}/guix.sigs"
# Only finds the outputs of a build versioned exactly after the tag
env FORCE_VERSION="${VERSION}" \
OUTDIR_BASE="${RUNNER_TEMP}/fragments/guix-build-${VERSION}/output" \
GUIX_SIGS_REPO="${RUNNER_TEMP}/guix.sigs" SIGNER=dashcore-ci NO_SIGN=1 \
./contrib/guix/guix-attest
- name: Attest SHA256SUMS
uses: actions/attest@v4
with:
subject-path: ${{ runner.temp }}/guix.sigs/*/*/noncodesigned.SHA256SUMS
- name: Upload SHA256SUMS
uses: actions/upload-artifact@v6
with:
name: guix-sigs-${{ github.ref_name }}
path: ${{ runner.temp }}/guix.sigs/