-
Notifications
You must be signed in to change notification settings - Fork 6
417 lines (368 loc) · 17 KB
/
build-deb-v4.yml
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name: Package Builder Debian v4
run-name: Build ${{ inputs.stage }} Packages ${{ inputs.distro }} ${{ inputs.codename }} ${{ inputs.arch }}
on:
workflow_dispatch:
inputs:
stage:
description: "Stage to build"
type: choice
options:
- all
- experimental
- unstable
- testing
- release-3_0
- release-3_1
- release-3_2
required: true
default: "unstable"
distro:
description: "Distro to build (debian, ubuntu)"
type: choice
options:
- ""
- debian
- ubuntu
required: false
default: ""
codename:
description: "Codename to build (e.g. noble, bookworm)"
type: string
required: false
default: ""
arch:
description: "Architecture to build (amd64, arm64)"
type: choice
options:
- ""
- amd64
- arm64
required: false
default: ""
workflow_call:
inputs:
stage:
description: "Stage to build"
type: string
required: true
default: "unstable"
distro:
description: "Distro to build (debian, ubuntu)"
type: string
required: false
codename:
description: "Codename to build (e.g. noble, bookworm)"
type: string
required: false
arch:
description: "Architecture to build (amd64, arm64)"
type: string
required: false
concurrency:
group: debian_builder_v4
cancel-in-progress: true
jobs:
matrix-builder:
runs-on: ubuntu-24.04
outputs:
stages: ${{ steps.calc-matrix.outputs.stages }}
distros: ${{ steps.calc-matrix.outputs.distros }}
codenames: ${{ steps.calc-matrix.outputs.codenames }}
arches: ${{ steps.calc-matrix.outputs.arches }}
suites: ${{ steps.calc-matrix.outputs.suites }}
runners: ${{ steps.calc-matrix.outputs.runners }}
includes: ${{ steps.calc-matrix.outputs.includes }}
excludes: ${{ steps.calc-matrix.outputs.excludes }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Calculate Matrix
id: calc-matrix
run: |
if [ -n "${{ inputs.stage }}" ] && [ "${{ inputs.stage }}" != "all" ]; then
STAGES=(${{ inputs.stage }})
else
STAGES=(experimental testing unstable)
fi
DISTROS=()
CODENAMES=()
if [ -n "${{ inputs.arch }}" ]; then
ARCHES=(${{ inputs.arch }})
else
ARCHES=(amd64 arm64)
fi
INCLUDES=()
EXCLUDES=()
valid_distro_codenames=()
for stage in "${STAGES[@]}"; do
if [ ! -d "stage/${stage}" ]; then
echo "Package model for stage ${stage} not found!"
continue
fi
for dir in $(find stage/${stage}/ -mindepth 2 -maxdepth 2 -type d | sort); do
for arch in "${ARCHES[@]}"; do
distro=$(echo $dir | cut -d/ -f3)
if [ -n "${{ inputs.distro }}" ] && [ "${{ inputs.distro }}" != "$distro" ]; then
continue
fi
codename=$(echo $dir | cut -d/ -f4)
if [ -n "${{ inputs.codename }}" ] && [ "${{ inputs.codename }}" != "$codename" ]; then
continue
fi
if [[ ! " ${DISTROS[*]} " =~ [[:space:]]${distro}[[:space:]] ]]; then
DISTROS+=("${distro}")
fi
if [[ ! " ${CODENAMES[*]} " =~ [[:space:]]${codename}[[:space:]] ]]; then
CODENAMES+=("${codename}")
fi
if [[ ! " ${valid_distro_codenames[*]} " =~ [[:space:]]${distro}-${codename}[[:space:]] ]]; then
valid_distro_codenames+=("${distro}-${codename}")
fi
done
done
done
for distro in "${DISTROS[@]}"; do
for codename in "${CODENAMES[@]}"; do
if [[ ! " ${valid_distro_codenames[*]} " =~ [[:space:]]${distro}-${codename}[[:space:]] ]]; then
EXCLUDES+=($(jq -n -c --arg distro "$distro" --arg codename "$codename" '$ARGS.named'))
fi
done
done
if [[ "${{ inputs.stage }}" == "release-"* ]]; then
EXCLUDES+=($(jq -n -c --arg distro "debian" --arg codename "testing" '$ARGS.named'))
fi
SUITES=$(jq -n "$(jq -n -c \
--argjson experimental "$(jq -n -c --arg suite "experimental" --arg component "main" '$ARGS.named')" \
--argjson unstable "$(jq -n -c --arg suite "unstable" --arg component "main" '$ARGS.named')" \
--argjson testing "$(jq -n -c --arg suite "testing" --arg component "main" '$ARGS.named')" \
--argjson stable "$(jq -n -c --arg suite "stable" --arg component "main" '$ARGS.named')" \
--argjson release-3_0 "$(jq -n -c --arg suite "stable" --arg component "v3.0" '$ARGS.named')" \
--argjson release-3_1 "$(jq -n -c --arg suite "stable" --arg component "v3.1" '$ARGS.named')" \
--argjson release-3_2 "$(jq -n -c --arg suite "stable" --arg component "v3.2" '$ARGS.named')" \
'$ARGS.named'\
)" '$ARGS.named')
echo "stages=$(jq -n -c '$ARGS.positional' --args -- "${STAGES[@]}")" >> $GITHUB_OUTPUT
echo "distros=$(jq -n -c '$ARGS.positional' --args -- "${DISTROS[@]}")" >> $GITHUB_OUTPUT
echo "codenames=$(jq -n -c '$ARGS.positional' --args -- "${CODENAMES[@]}")" >> $GITHUB_OUTPUT
echo "arches=$(jq -n -c '$ARGS.positional' --args -- "${ARCHES[@]}")" >> $GITHUB_OUTPUT
echo "suites=$(jq -n -c "${SUITES}" '$ARGS.named')" >> $GITHUB_OUTPUT
echo "runners=$(jq -n -c "$(jq -n -c --arg amd64 "X64" --arg arm64 "arm64" '$ARGS.named')" '$ARGS.named')" >> $GITHUB_OUTPUT
echo "includes=$(jq -n -c "[$(printf '%s\n' "${INCLUDES[@]}" | paste -sd,)]" '$ARGS.named')" >> $GITHUB_OUTPUT
echo "excludes=$(jq -n -c "[$(printf '%s\n' "${EXCLUDES[@]}" | paste -sd,)]" '$ARGS.named')" >> $GITHUB_OUTPUT
# build packages and sources
build:
runs-on: [self-hosted, Linux, "${{ fromJSON(needs.matrix-builder.outputs.runners)[matrix.arch] }}", "${{ matrix.codename }}"]
needs: matrix-builder
strategy:
matrix:
stage: ${{ fromJSON(needs.matrix-builder.outputs.stages) }}
distro: ${{ fromJSON(needs.matrix-builder.outputs.distros) }}
codename: ${{ fromJSON(needs.matrix-builder.outputs.codenames) }}
arch: ${{ fromJSON(needs.matrix-builder.outputs.arches) }}
include: ${{ fromJSON(needs.matrix-builder.outputs.includes) }}
exclude: ${{ fromJSON(needs.matrix-builder.outputs.excludes) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Job Parameters
id: init
run: |
echo "gh-repo-path=${{ github.workspace }}" >> $GITHUB_OUTPUT
echo "changelogs-path=${{ github.workspace }}/changelogs" >> $GITHUB_OUTPUT
echo "manifest-path=${{ github.workspace }}/manifests" >> $GITHUB_OUTPUT
echo "package-build-path=${{ github.workspace }}/packages" >> $GITHUB_OUTPUT
echo "package-publish-path=${{ github.workspace }}/publish" >> $GITHUB_OUTPUT
echo "stage=${{ matrix.stage }}" >> $GITHUB_OUTPUT
echo "distro=${{ matrix.distro }}" >> $GITHUB_OUTPUT
echo "codename=${{ matrix.codename }}" >> $GITHUB_OUTPUT
echo "arch=${{ matrix.arch }}" >> $GITHUB_OUTPUT
echo "suite=${{ fromJSON(needs.matrix-builder.outputs.suites)[matrix.stage]['suite'] }}" >> $GITHUB_OUTPUT
echo "component=${{ fromJSON(needs.matrix-builder.outputs.suites)[matrix.stage]['component'] }}" >> $GITHUB_OUTPUT
echo "target=${{ matrix.stage }}-${{ matrix.distro }}-${{ matrix.codename }}-${{ matrix.arch }}" >> $GITHUB_OUTPUT
- name: Environment Setup
run: |
set -e
mkdir -p ${{ steps.init.outputs.changelogs-path }} || true
mkdir -p ${{ steps.init.outputs.manifest-path }} || true
sudo rm -rf /etc/apt/sources.list.d/regolith.list
sudo apt update
DEBIAN_FRONTEND=noninteractive sudo apt install -y --no-install-recommends jq git devscripts wget dput diffutils
- name: Pull Manifest
run: |
set -e
wget -P "${{ steps.init.outputs.manifest-path }}" "http://archive.regolith-desktop.com/manifests/${{ steps.init.outputs.distro }}/${{ steps.init.outputs.codename }}/${{ steps.init.outputs.suite }}-${{ steps.init.outputs.component }}/${{ steps.init.outputs.arch }}/manifest.txt" || true
echo "Current manifest:"
cat ${{ steps.init.outputs.manifest-path }}/manifest.txt || true
- name: Check for changes
id: changes
run: |
set -e
set -x
CHANGE_OUTPUT=$(${{ steps.init.outputs.gh-repo-path }}/.github/scripts/main.sh \
check \
--extension ${{ steps.init.outputs.gh-repo-path }}/.github/scripts/ext-debian.sh \
--git-repo-path ${{ steps.init.outputs.gh-repo-path }} \
--manifest-path ${{ steps.init.outputs.manifest-path }} \
--pkg-build-path ${{ steps.init.outputs.package-build-path }} \
--pkg-publish-path ${{ steps.init.outputs.package-publish-path }} \
--distro "${{ steps.init.outputs.distro }}" \
--codename "${{ steps.init.outputs.codename }}" \
--arch "${{ steps.init.outputs.arch }}" \
--stage "${{ steps.init.outputs.stage }}" \
--suite "${{ steps.init.outputs.suite }}" \
--component "${{ steps.init.outputs.component }}" | tail -n1)
if [ "$CHANGE_OUTPUT" == "No package changes found, exiting." ]; then
echo "changed=0" >> $GITHUB_OUTPUT
echo "No package changes to build"
else
echo "changed=1" >> $GITHUB_OUTPUT
echo "New Manifest: "
cat ${{ steps.init.outputs.manifest-path }}/next-manifest.txt
fi
- name: Setup SSH agent
uses: webfactory/[email protected]
if: steps.changes.outputs.changed == 1
with:
ssh-private-key: ${{ secrets.KAMATERA_SSH_KEY }}
- name: Build Packages
if: steps.changes.outputs.changed == 1
run: |
set -e
export DEBEMAIL="[email protected]"
export DEBFULLNAME="Regolith Linux"
export DEBIAN_FRONTEND=noninteractive
mkdir -p ~/.gnupg/
printf "${{ secrets.PACKAGE_PRIVATE_KEY2 }}" | base64 --decode > ~/.gnupg/private.key
gpg --batch --import ~/.gnupg/private.key
${{ steps.init.outputs.gh-repo-path }}/.github/scripts/main.sh \
build \
--extension ${{ steps.init.outputs.gh-repo-path }}/.github/scripts/ext-debian.sh \
--git-repo-path ${{ steps.init.outputs.gh-repo-path }} \
--manifest-path ${{ steps.init.outputs.manifest-path }} \
--pkg-build-path ${{ steps.init.outputs.package-build-path }} \
--pkg-publish-path ${{ steps.init.outputs.package-publish-path }} \
--distro "${{ steps.init.outputs.distro }}" \
--codename "${{ steps.init.outputs.codename }}" \
--arch "${{ steps.init.outputs.arch }}" \
--stage "${{ steps.init.outputs.stage }}" \
--suite "${{ steps.init.outputs.suite }}" \
--component "${{ steps.init.outputs.component }}" | tee -a ${{ steps.init.outputs.changelogs-path }}/CHANGELOG_${{ steps.init.outputs.target }}.raw.txt
if [ -f ${{ steps.init.outputs.manifest-path }}/next-manifest.txt ]; then
echo "Temp manifest not deleted by main.sh, build aborted/failed."
exit 1
fi
cat ${{ steps.init.outputs.changelogs-path }}/CHANGELOG_${{ steps.init.outputs.target }}.raw.txt | grep ^CHLOG: | cut -c 7- > ${{ steps.init.outputs.changelogs-path }}/CHANGELOG_${{ steps.init.outputs.target }}.txt
cat ${{ steps.init.outputs.changelogs-path }}/CHANGELOG_${{ steps.init.outputs.target }}.raw.txt | grep ^SRCLOG: | cut -c 8- > ${{ steps.init.outputs.changelogs-path }}/SOURCELOG_${{ steps.init.outputs.target }}.txt
if [ ! -s ${{ steps.init.outputs.changelogs-path }}/CHANGELOG_${{ steps.init.outputs.target }}.txt ] ; then
rm ${{ steps.init.outputs.changelogs-path }}/CHANGELOG_${{ steps.init.outputs.target }}.txt
fi
if [ ! -s ${{ steps.init.outputs.changelogs-path }}/SOURCELOG_${{ steps.init.outputs.target }}.txt ] ; then
rm ${{ steps.init.outputs.changelogs-path }}/SOURCELOG_${{ steps.init.outputs.target }}.txt
fi
- name: Deploy via rsync
if: steps.changes.outputs.changed == 1
run: |
set -e
set -x
ssh-keyscan -H ${{ secrets.KAMATERA_HOSTNAME2 }} >> ~/.ssh/known_hosts
for i in 1 2 3 4 5; do
echo "Attempt $i"
rsync \
-avzhH \
${{ steps.init.outputs.package-publish-path }}/* \
root@${{ secrets.KAMATERA_HOSTNAME2 }}:/opt/archives/packages/ && break || sleep 5
done
rsync --ignore-missing-args ${{ steps.init.outputs.changelogs-path }}/SOURCELOG_${{ steps.init.outputs.target }}.txt root@${{ secrets.KAMATERA_HOSTNAME2 }}:/opt/archives/workspace/
rsync --mkpath ${{ steps.init.outputs.manifest-path }}/manifest.txt root@${{ secrets.KAMATERA_HOSTNAME2 }}:/opt/archives/manifests/${{ steps.init.outputs.distro }}/${{ steps.init.outputs.codename }}/${{ steps.init.outputs.suite }}-${{ steps.init.outputs.component }}/${{ steps.init.outputs.arch }}/
- name: Log Build Output
if: steps.changes.outputs.changed == 1
run: |
cat ${{ steps.init.outputs.manifest-path }}/manifest.txt || true
echo "package-publish-path:"
find ${{ steps.init.outputs.package-publish-path }}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: steps.changes.outputs.changed == 1
with:
name: CHANGELOG_${{ steps.init.outputs.target }}
path: ${{ steps.init.outputs.changelogs-path }}/*${{ steps.init.outputs.target }}.txt
# calculate changelogs
changelogs:
runs-on: ubuntu-24.04
needs: build
outputs:
package-changed: ${{ steps.check.outputs.package-changed }}
source-changed: ${{ steps.check.outputs.source-changed }}
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: changelogs
pattern: CHANGELOG_*
merge-multiple: true
- name: Check Changelogs
id: check
run: |
set -e
if [ ! -d changelogs ]; then
echo "No package file found to publish!"
echo "No source file found to rebuild!"
echo "package-changed=0" >> $GITHUB_OUTPUT
echo "source-changed=0" >> $GITHUB_OUTPUT
else
ls -R changelogs/
echo "package-changed=$(find changelogs -name CHANGELOG_\*.txt | wc -l)" >> $GITHUB_OUTPUT
echo "source-changed=$(find changelogs -name SOURCELOG_\*.txt | wc -l)" >> $GITHUB_OUTPUT
fi
# rebuild sources
source:
needs: changelogs
if: ${{ !failure() && !cancelled() && needs.changelogs.outputs.source-changed != 0 }}
uses: ./.github/workflows/rebuild-sources.yml
with:
pull-from: /opt/archives/workspace/
push-to: /opt/archives/packages/
secrets: inherit
# publish archives
publish:
needs: [changelogs, source]
if: ${{ !failure() && !cancelled() && needs.changelogs.outputs.package-changed != 0 }}
uses: ./.github/workflows/publish-packages.yml
with:
packages-path: /opt/archives/packages/
secrets: inherit
# create a release with changlogs
release:
runs-on: ubuntu-24.04
needs: [changelogs, publish]
if: ${{ !failure() && !cancelled() && needs.changelogs.outputs.package-changed != 0 }}
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: changelogs
pattern: CHANGELOG_*
merge-multiple: true
- name: Prepare Release
id: prepare
run: |
echo "TIMESTAMP=$(date +%Y%m%d_%H%M%S)" >> $GITHUB_OUTPUT
find changelogs/ -name CHANGELOG_\*.txt -exec sh -c 'cat "$1" >> CHANGELOG.txt' -- {} \;
cat CHANGELOG.txt
- uses: softprops/action-gh-release@v2
with:
body: See CHANGELOG.txt for updates and manifests for current state of repos.
name: Package Build ${{ steps.prepare.outputs.TIMESTAMP }}
tag_name: pkgbuild-${{ steps.prepare.outputs.TIMESTAMP }}
files: |
*.txt
# run the tests
test:
needs: [changelogs, release]
if: ${{ !failure() && !cancelled() }}
uses: ./.github/workflows/test-desktop-installable2.yml
with:
stage: ${{ inputs.stage }}
distro: ${{ inputs.distro }}
codename: ${{ inputs.codename }}
arch: ${{ inputs.arch }}