-
Notifications
You must be signed in to change notification settings - Fork 31
263 lines (242 loc) · 10.5 KB
/
build-os.yml
File metadata and controls
263 lines (242 loc) · 10.5 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
name: build-os
on:
workflow_call:
inputs:
name:
description: 'The name of the OS image to build'
required: true
type: string
base_release_name:
description: 'The release name of the RPi OS base image (bullseye, bookworm)'
required: true
type: string
base_image_variant:
description: 'The name of the RPi OS base image variant (lite, desktop, or full)'
required: true
type: string
base_release_date:
description: 'The release date of the RPi OS base image'
required: true
type: string
base_file_release_date:
description: 'The release date of the RPi OS base image file, if different from the group release date'
required: false
type: string
arch:
description: 'The CPU architecture of the OS (armhf, arm64)'
required: true
type: string
jobs:
build-os-image:
name: Build image
runs-on: ubuntu-24.04-arm
env:
SETUP_USER: pi
permissions:
contents: read
packages: write
id-token: write
timeout-minutes: 30
steps:
- name: Get actual repo & commit SHA
run: |
# Get the actual repo name on PRs from external forks of the repo:
if [ -n "${{ github.event.pull_request.head.repo.full_name }}" ]; then
echo "REPO=${{ github.event.pull_request.head.repo.full_name }}" >> $GITHUB_ENV
else
echo "REPO=${{ github.repository }}" >> $GITHUB_ENV
fi
# Get the SHA of the actual commit (not the fake merge commit) on PR-triggered runs
# (refer to https://stackoverflow.com/a/68068674/23202949):
if [ -n "${{ github.event.pull_request.head.sha }}" ]; then
echo "ACTUAL_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
else
# Note: we want to have a SHA to check out even in merge queues, so we always fall back
# to a SHA even if it's a fictional SHA detached from any branches:
echo "ACTUAL_SHA=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Checkout repository
uses: actions/checkout@v5
with:
# PR-triggered workflow runs have a merge commit which is detached from existing
# branches and messes up pseudoversion determination when we record installer versioning
# information, so instead we check out the actual commit (and fetch all tags so we can
# determine a pseudoversion string):
repository: ${{ env.REPO }}
ref: ${{ env.ACTUAL_SHA }}
fetch-depth: 0
fetch-tags: true
filter: 'blob:none'
submodules: recursive
# GET BASE IMAGE
- name: Determine Raspberry Pi OS base image URL
id: rpi-os-image
run: |
case '${{ inputs.base_release_name }}' in
'bookworm')
IMAGE_RELEASE_CHANNEL='raspios'
;;
'bullseye')
IMAGE_RELEASE_CHANNEL='raspios_oldstable'
;;
*)
echo "Unknown release name: ${{ inputs.base_release_name }}"
exit 1
;;
esac
IMAGE_REPO_GROUP="$IMAGE_RELEASE_CHANNEL"
if [[ "${{ inputs.base_image_variant }}" != "desktop" ]]; then
IMAGE_REPO_GROUP="${IMAGE_REPO_GROUP}_${{ inputs.base_image_variant }}"
fi
IMAGE_REPO_GROUP="${IMAGE_REPO_GROUP}_${{ inputs.arch }}"
if [[ -z "${{ inputs.base_file_release_date }}" ]]; then
BASE_FILE_RELEASE_DATE="${{ inputs.base_release_date }}"
else
BASE_FILE_RELEASE_DATE="${{ inputs.base_file_release_date }}"
fi
IMAGE_FILENAME="$BASE_FILE_RELEASE_DATE-raspios-${{ inputs.base_release_name }}-${{ inputs.arch }}"
if [[ "${{ inputs.base_image_variant }}" != "desktop" ]]; then
IMAGE_FILENAME="${IMAGE_FILENAME}-${{ inputs.base_image_variant }}"
fi
IMAGE_FILENAME="${IMAGE_FILENAME}.img.xz"
IMAGE_URL="https://downloads.raspberrypi.com/$IMAGE_REPO_GROUP/images/$IMAGE_REPO_GROUP-${{ inputs.base_release_date }}/$IMAGE_FILENAME"
echo "RPi OS image filename: $IMAGE_FILENAME"
echo "image_filename=$IMAGE_FILENAME" >> $GITHUB_OUTPUT
echo "RPi OS image URL: $IMAGE_URL"
echo "image_url=$IMAGE_URL" >> $GITHUB_OUTPUT
- name: Download and cache base image
id: download-base
uses: ethanjli/cached-download-action@v0.1.3
with:
url: ${{ steps.rpi-os-image.outputs.image_url }}
destination: /tmp/${{ steps.rpi-os-image.outputs.image_filename }}
- name: Decompress & grow base image
id: expand-image
uses: ethanjli/pigrow-action@v0.1.1
with:
image: ${{ steps.download-base.outputs.destination }}
mode: to
size: 16G
# If we don't do this, then the post-job cleanup for the actions/checkout step will emit a
# warning:
- name: Reset owner of Git repo
run: |
sudo chown -R $USER .
# Note: the following step isn't strictly necessary, but it's nice to separate the GitHub
# Actions log outputs for setting up pinspawn-action for the first time from the logs for
# pre-downloading container images
- name: Install pinspawn-action dependencies
uses: ethanjli/pinspawn-action@v0.1.5
with:
image: ${{ steps.expand-image.outputs.destination }}
run: echo "Done!"
# RUN OS SETUP SCRIPTS
- name: Run OS setup scripts in an unbooted container
uses: ethanjli/pinspawn-action@v0.1.5
with:
image: ${{ steps.expand-image.outputs.destination }}
user: ${{ env.SETUP_USER }}
# Note: CAP_NET_ADMIN is needed for iptables, which is needed for Docker (at least in an
# unbooted container). Setting the machine ID (and therefore hostname) to `raspberrypi`
# resolves noisy (but harmless) error messages from sudo.
args: >-
--bind "$(pwd)":/run/os-setup
--capability=CAP_NET_ADMIN
--machine=raspberrypi
run: |
echo "Running setup scripts..."
export DEBIAN_FRONTEND=noninteractive
/run/os-setup/os/setup-ci.sh
echo "Done!"
- name: Prepare for a headless first boot on bare metal
uses: ethanjli/pinspawn-action@v0.1.5
env:
DEFAULT_PASSWORD: copepode
DEFAULT_KEYBOARD_LAYOUT: us
with:
image: ${{ steps.expand-image.outputs.destination }}
args: --machine=raspberrypi
run: |
# Change default settings for the SD card to enable headless & keyboardless first boot
# Note: we could change the username by making a `userconf.txt` file with the new
# username and an encrypted representation of the password (and un-disabling and
# unmasking `userconfig.service`), but we don't need to do that for now.
# See https://github.com/RPi-Distro/userconf-pi/blob/bookworm/userconf-service and
# https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-a-user
# and the "firstrun"-related and "cloudinit"-related lines of
# https://github.com/raspberrypi/rpi-imager/blob/qml/src/OptionsPopup.qml and
# the RPi SD card image's `/usr/lib/raspberrypi-sys-mods/firstboot` and
# `/usr/lib/raspberrypi-sys-mods/imager_custom` scripts
echo "pi:${{ env.DEFAULT_PASSWORD }}" | chpasswd
sed -i \
-e "s~^XKBLAYOUT=.*~XKBLAYOUT=\"${{ env.DEFAULT_KEYBOARD_LAYOUT }}\"~" \
/etc/default/keyboard
systemctl disable userconfig.service
# This is needed to have the login prompt on tty1 (so that a user with a keyboard can
# log in without switching away from the default tty), because we disabled
# userconfig.service. See
# https://forums.raspberrypi.com/viewtopic.php?p=2032694#p2032694
systemctl enable getty@tty1
# RUN TESTS
- name: Run tests
uses: ethanjli/pinspawn-action@v0.1.5
with:
image: ${{ steps.expand-image.outputs.destination }}
user: pi
run: |
export DEBIAN_FRONTEND=noninteractive
cd /opt/PlanktoScope
just ci
# UPLOAD OS IMAGE
- name: Determine output image name
env:
TAG_PREFIX: 'software/v'
run: |
# Determine the version for the image name
if [[ -n "${{ github.event.pull_request.head.sha }}" ]]; then
# We're in a pull request
version="$(\
printf "pr-%s-%.7s" \
"${{ github.event.pull_request.number }}" \
"${{ github.event.pull_request.head.sha }}" \
)"
elif [[ "${{ github.ref_type }}" == "tag" && "${{ github.ref }}" == refs/tags/$TAG_PREFIX* ]]; then
version="${{ github.ref }}"
version="v${version#"refs/tags/$TAG_PREFIX"}"
else
version="$(printf "%.7s" "${{ github.sha }}")"
fi
variant=""
if [[ "${{ inputs.base_release_name }}" != "bookworm" ]]; then
variant="${{ inputs.base_release_name }}"
fi
if [[ "${{ inputs.arch }}" != "arm64" ]]; then
variant="$variant.${{ inputs.arch }}"
fi
if [[ "${{ inputs.base_image_variant }}" != "lite" ]]; then
variant="$variant.${{ inputs.base_image_variant }}"
fi
# Assemble the image name
output_name="${{ inputs.name }}-$version"
if [[ $variant != "" ]]; then
output_name="$output_name.$variant"
fi
echo "OUTPUT_IMAGE_NAME=$output_name" >> $GITHUB_ENV
- name: Shrink the OS image
uses: ethanjli/pishrink-action@v0.1.4
env:
PISHRINK_XZ: -T0 ${{ github.ref_type == 'tag' && '-9' || '-1' }}
with:
image: ${{ steps.expand-image.outputs.destination }}
destination: ${{ env.OUTPUT_IMAGE_NAME }}.img
compress: xz
compress-parallel: true
- name: Upload image to Job Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUTPUT_IMAGE_NAME }}
path: ${{ env.OUTPUT_IMAGE_NAME }}.img.xz
if-no-files-found: error
retention-days: 0
compression-level: 0
overwrite: true