-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathinfrastructure-download-external.yml
More file actions
938 lines (811 loc) · 37 KB
/
infrastructure-download-external.yml
File metadata and controls
938 lines (811 loc) · 37 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
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
name: "Composite: Sync 3rd party packages"
on:
workflow_call:
inputs:
ENABLED:
required: false
type: boolean
default: true
ACCESS_NAME:
required: false
type: string
default: ${{ github.repository_owner }}
BUILD_BRANCH:
required: false
type: string
default: 'main'
BUILD_RUNNER:
required: false
type: string
default: "ubuntu-latest"
HOST_DEPLOY:
required: false
type: string
default: "repo.armbian.com"
HOST_USER:
required: false
type: string
default: "upload"
REFERENCE:
required: false
type: string
default: "main"
HIDE_NO_UPDATE:
required: false
type: boolean
default: false
PURGE:
required: false
type: boolean
default: false
SKIP_VERSION_CHECK:
required: false
type: boolean
default: false
CHUNK_INDEX:
# Which slice of the matrix this invocation processes (0..CHUNK_COUNT-1).
# Used to keep strategy.matrix under GitHub Actions' 256-entry cap when
# the number of packages × arches × releases grows past that. Defaults
# to 0/1 so the workflow still works when called un-chunked.
required: false
type: number
default: 0
CHUNK_COUNT:
required: false
type: number
default: 1
secrets:
GPG_KEY1:
required: true
GPG_KEY2:
required: true
ACCESS_TOKEN:
required: true
KEY_UPLOAD:
required: false
HOST_UPLOAD:
required: true
HOST_UPLOAD_USER:
required: true
HOST_UPLOAD_PORT:
required: true
KNOWN_HOSTS_ARMBIAN_UPLOAD:
required: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
PACKAGES_URL: "https://fi.mirror.armbian.de/apt"
UPLOAD_PATH: "storage/incoming/external"
jobs:
perm:
name: "Restore permissions"
runs-on: repository-sync
if: ${{ inputs.ENABLED == true }}
steps:
- name: "Restore permissions"
run: |
sudo chown -R ${{ secrets.HOST_UPLOAD_USER }}:gha-runners /armbian/openssh-server/storage/{debs,debs-beta,artifacts}
preclean:
name: "Purge"
needs: perm
if: ${{ inputs.PURGE == true }}
runs-on: ubuntu-latest
outputs:
matrix: ${{steps.json.outputs.JSON_CONTENT}}
steps:
- name: "Checkout Armbian build Framework"
uses: actions/checkout@v6
with:
repository: armbian/build
ref: ${{ inputs.REFERENCE || inputs.branch || 'main' }}
clean: false
fetch-depth: 1
path: build
- name: "Make JSON"
id: json
run: |
pkg="code,codium,google-chrome-stable,anubis,armbian-config,box64,box64-android,gh,min,microsoft-edge-stable,zoom,armbian-firmware,armbian-firmware-full"
echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
releases=($(grep "supported\|csc" build/config/distributions/*/support | cut -d"/" -f4))
for i in ${releases[@]}; do
packages=($(echo "$pkg" | tr ',' '\n'))
for j in ${packages[@]}; do
echo "{\"release\":\"${i}\",\"package\":\"$j\"}"
done
done | jq -s >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
postclean:
needs: preclean
if: ${{ inputs.PURGE == true }}
strategy:
fail-fast: false
max-parallel: 1
matrix:
include: ${{ fromJson(needs.preclean.outputs.matrix) }}
name: "Purge old ${{ matrix.package }} from ${{ matrix.release }}"
timeout-minutes: 60
runs-on: repository
steps:
- name: Checkout build repository
uses: actions/checkout@v6
with:
repository: armbian/build
fetch-depth: 1
clean: false
- name: Purge packages
run: |
# take ownership
sudo chown -R ${USER}:gha-runners /publishing/repository-debs
PKG="${{ matrix.package }}"
LIST=$(
tools/repository/repo.sh -i /incoming/debs -o /publishing/repository-debs -r ${{ matrix.release }} \
| sed 's/^[[:space:]]*//' \
| grep "^${PKG}_" || true
)
COUNT=$(printf "%s\n" "$LIST" | grep -c . || true)
if (( COUNT > 1 )); then
# Display & log header
echo "Found $COUNT packages for $PKG — deleting older versions" \
| tee -a "$GITHUB_STEP_SUMMARY" >/dev/null
# Determine newest version
LATEST=$(printf "%s\n" "$LIST" | sort -V | tail -n 1)
VERSION="${LATEST#${PKG}_}" # strip pkg_
VERSION="${VERSION%_*}" # strip _ARCH
echo "Newest version: $VERSION" \
| tee -a "$GITHUB_STEP_SUMMARY" >/dev/null
# Pretty print command in both outputs
{
echo '### 🧹 Delete package'
echo '```bash'
echo "tools/repository/repo.sh -o /publishing/repository-debs -r ${{ matrix.release }} -c delete -l 'Name (= $PKG), \$Version (<< $VERSION)'"
echo '```'
} | tee -a "$GITHUB_STEP_SUMMARY" >/dev/null
# === RUN DELETE OPERATION ===
tools/repository/repo.sh -i /incoming/debs -o /publishing/repository-debs -r ${{ matrix.release }} -c delete -l "Name (= $PKG), \$Version (<< $VERSION)"
else
echo "Only $COUNT package present — skipping delete" \
| tee -a "$GITHUB_STEP_SUMMARY" >/dev/null
fi
start:
runs-on: ${{ inputs.BUILD_RUNNER }}
if: ${{ inputs.ENABLED == true }}
needs: perm
name: "Mirror"
outputs:
matrix: ${{steps.lists.outputs.matrix}}
steps:
- name: Fix workspace ownership
if: always()
run: |
sudo chown -R "$(id -u)":"$(id -g)" "$GITHUB_WORKSPACE" || true
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.KEY_UPLOAD }}
known_hosts: ${{ secrets.KNOWN_HOSTS_ARMBIAN_UPLOAD }}
if_key_exists: replace
- name: Create a temporary artifact folder
run: |
mkdir -p downloads
cd downloads
echo "${{ inputs.HOST_DEPLOY }}/" > url.txt
echo "artifacts/${{ env.PR_NUMBER }}/" > path.txt
- name: Upload Artifact
uses: actions/upload-artifact@v7
with:
name: assets-for-download-${{ inputs.CHUNK_INDEX }}
path: downloads
overwrite: true
retention-days: 5
- name: Remove temporary repositories
run: |
# Note: StrictHostKeychecking=no is used here; consider using proper known_hosts in production
ssh -o StrictHostKeychecking=no -p ${{ secrets.HOST_UPLOAD_PORT }} \
${{ inputs.HOST_USER }}@${{ inputs.HOST_DEPLOY }} \
"rm -rf ${UPLOAD_PATH}/artifacts/*"
- name: Checkout Armbian OS repository
uses: actions/checkout@v6
with:
repository: armbian/os
path: os
fetch-depth: '2'
clean: false
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v47
with:
path: os
files: |
external/*.conf
- name: Build list
id: lists
run: |
# Install jq if not available
command -v jq >/dev/null 2>&1 || sudo apt-get install -y jq
echo "::debug::Changed files: ${{ steps.changed-files.outputs.all_changed_files }}" >&2
echo "::debug::REFERENCE input: ${{ inputs.REFERENCE }}" >&2
# Build list of conf files
if [[ "${{ inputs.REFERENCE }}" =~ ^(main|)$ ]]; then
# Get all conf files
MATRIX_LIST=()
while IFS= read -r -d '' conf_file; do
conf_name=$(basename "$conf_file" .conf)
MATRIX_LIST+=("$conf_name")
done < <(find os/external/*.conf -print0 | sort -z)
else
# Get only changed conf files
MATRIX_LIST=()
CHANGED="${{ steps.changed-files.outputs.all_changed_files }}"
if [[ -n "$CHANGED" ]]; then
while IFS= read -r conf_file; do
conf_name=$(echo "$conf_file" | cut -d"." -f1 | cut -d"/" -f2)
MATRIX_LIST+=("$conf_name")
done < <(echo "$CHANGED" | tr " " "\n")
fi
fi
echo "::debug::MATRIX content: ${MATRIX_LIST[*]}" >&2
# Build detailed matrix - expand each arch and release combination
echo "::notice::Building matrix..." >&2
MATRIX_JSON=$(
for conf_file in "${MATRIX_LIST[@]}"; do
echo "::debug::Processing conf file: ${conf_file}" >&2
[[ -f "os/external/${conf_file}.conf" ]] || continue
# Source the conf file to get variables
. "os/external/${conf_file}.conf"
echo "::debug::${conf_file} - ARCH: ${ARCH}, RELEASE: ${RELEASE}, TARGET: ${TARGET}" >&2
# Expand architectures (colon-separated)
archs=($(echo "$ARCH" | tr ':' ' '))
# Expand releases
if [[ "${RELEASE}" == "all" ]]; then
# Default releases for "all"
releases=("bookworm" "trixie" "forky" "jammy" "noble" "resolute")
elif [[ "${RELEASE}" == *":"* ]]; then
# Colon-separated releases
IFS=':' read -ra releases <<< "$RELEASE"
else
# Single release
releases=("$RELEASE")
fi
# Generate matrix entry for each arch x release combination
for arch in "${archs[@]}"; do
for release in "${releases[@]}"; do
# Determine if we need QEMU (non-amd64)
needs_qemu="false"
[[ "$arch" != "amd64" ]] && needs_qemu="true"
echo "::debug::Generating entry: package=${conf_file}, arch=${arch}, release=${release}, needs_qemu=${needs_qemu}" >&2
# Determine runner based on architecture and method
# Force amd64 runner for aptly method due to stability issues on ARM
if [[ "${METHOD:-aptly}" == "aptly" ]]; then
# Always use amd64 runner for aptly, use QEMU for other arches
runner='["docker", "X64"]'
image_arch="amd64"
else
# Use architecture-specific runners for other methods (gh, direct)
case "${arch}" in
amd64)
runner='["docker", "X64"]'
image_arch="${arch}"
;;
arm64)
runner='["docker", "ARM64"]'
image_arch="${arch}"
;;
armhf|riscv64)
runner='["ubuntu-latest"]'
runner='["docker", "X64"]'
image_arch="amd64" # Use amd64 image with QEMU emulation
;;
*)
runner='["ubuntu-latest"]'
image_arch="amd64"
;;
esac
fi
# Output JSON object for this combination - use pre-built Docker images
jq -n \
--arg name "${conf_file}" \
--arg arch "${arch}" \
--arg release "${release}" \
--arg target "${TARGET:-main}" \
--arg method "${METHOD:-aptly}" \
--arg install "${INSTALL:-}" \
--arg runner "${runner}" \
--arg image_arch "${image_arch}" \
--arg registry "ghcr.io/${{ github.repository_owner }}" \
--argjson needs_qemu "${needs_qemu}" \
'{name: $name, arch: $arch, release: $release, target: $target, method: $method, install: $install, runner: ($runner | fromjson), image_arch: $image_arch, registry: $registry, needs_qemu: $needs_qemu}'
done
done
done | jq -s '{"include": .}'
)
# Check if matrix is valid
MATRIX_COUNT=$(echo "${MATRIX_JSON}" | jq '.include | length')
# Handle empty matrix - add a dummy entry that will be skipped
if [[ "${MATRIX_COUNT}" -eq 0 ]]; then
echo "::warning::No matrix entries generated, adding placeholder" >&2
MATRIX_JSON_COMPACTED='{"include":[{"name":"none","arch":"amd64","release":"bookworm"}]}'
else
# Chunk the matrix so each invocation keeps strategy.matrix
# below GitHub Actions' 256-entry cap. Callers that don't
# know about chunking get CHUNK_COUNT=1 and pass the whole
# thing through (legacy behavior).
CHUNK_INDEX="${{ inputs.CHUNK_INDEX }}"
CHUNK_COUNT="${{ inputs.CHUNK_COUNT }}"
if [[ "${CHUNK_COUNT}" -lt 1 ]]; then CHUNK_COUNT=1; fi
if [[ "${CHUNK_INDEX}" -ge "${CHUNK_COUNT}" ]]; then
echo "::error::CHUNK_INDEX=${CHUNK_INDEX} must be < CHUNK_COUNT=${CHUNK_COUNT}" >&2
exit 1
fi
# Slice jq: split includes into CHUNK_COUNT roughly-equal
# groups by modular index (not contiguous ranges) so a
# slow package type doesn't cluster into one chunk.
SLICED=$(echo "${MATRIX_JSON}" | jq -c \
--argjson idx "${CHUNK_INDEX}" \
--argjson cnt "${CHUNK_COUNT}" \
'{include: [.include | to_entries[] | select(.key % $cnt == $idx) | .value]}')
SLICE_COUNT=$(echo "${SLICED}" | jq '.include | length')
echo "::notice::chunk ${CHUNK_INDEX}/${CHUNK_COUNT}: ${SLICE_COUNT} of ${MATRIX_COUNT} entries" >&2
# Empty slice needs a placeholder for the downstream job to
# run at all — it'll skip entries with name=none.
if [[ "${SLICE_COUNT}" -eq 0 ]]; then
MATRIX_JSON_COMPACTED='{"include":[{"name":"none","arch":"amd64","release":"bookworm"}]}'
else
MATRIX_JSON_COMPACTED="${SLICED}"
fi
echo "::debug::Compacted matrix JSON: ${MATRIX_JSON_COMPACTED}" >&2
fi
echo "matrix=${MATRIX_JSON_COMPACTED}" >> $GITHUB_OUTPUT
download:
needs: [start]
outputs:
project: ${{steps.make.outputs.project}}
strategy:
fail-fast: false
max-parallel: 180
matrix: ${{fromJson(needs.start.outputs.matrix)}}
name: "${{ matrix.name }}:${{ matrix.release }}:${{ matrix.arch }}"
runs-on: ${{ matrix.runner }}
container:
image: ${{ matrix.registry }}/repository-update:${{ matrix.release }}-${{ matrix.image_arch }}
options: --user root
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.KEY_UPLOAD }}
known_hosts: ${{ secrets.KNOWN_HOSTS_ARMBIAN_UPLOAD }}
if_key_exists: replace
- name: Import GPG key 1
uses: crazy-max/ghaction-import-gpg@v7
env:
HOME: /root
GNUPGHOME: /root/.gnupg
with:
gpg_private_key: ${{ secrets.GPG_KEY1 }}
- name: Import GPG key 2
uses: crazy-max/ghaction-import-gpg@v7
with:
gpg_private_key: ${{ secrets.GPG_KEY2 }}
- name: Checkout Armbian OS scripts
uses: actions/checkout@v6
with:
repository: armbian/os
path: os
ref: ${{ inputs.REFERENCE }}
fetch-depth: '1'
clean: false
- name: Checkout Armbian build script
uses: actions/checkout@v6
with:
repository: armbian/build
path: build
fetch-depth: '1'
clean: false
- name: Install GPG keys
shell: bash
run: |
# Import all GPG keys from the repository
find os/external/keys/ -type f -name "*.gpg" -exec gpg --import --no-default-keyring --keyring trustedkeys.gpg "{}" \;
# Install appropriate keyring based on container type
if grep -q "debian" /etc/os-release; then
apt-get -y install debian-keyring 2>&1 | grep -v "^gpg:" || true
elif grep -q "ubuntu" /etc/os-release; then
apt-get -y install ubuntu-keyring 2>&1 | grep -v "^gpg:" || true
fi
# Import additional keys with timeout and suppress verbose output
# Use timeout to prevent hanging on unavailable keyservers
if timeout 30 gpg --no-default-keyring --keyring trustedkeys.gpg \
--keyserver keyserver.ubuntu.com \
--recv-keys 648ACFD622F3D138 0E98404D386FA1D9 2>&1 | grep -v "not changed\|unchanged\|not checked" || true; then
echo "::notice::GPG keys imported successfully"
else
echo "::warning::Some GPG keys could not be imported from keyserver (non-critical)"
fi
- name: "Prepare machine"
id: preparing
shell: bash
run: |
# Load configuration
. os/external/${{ matrix.name }}.conf
echo "::debug::Config loaded - URL: ${URL}, KEY: ${KEY}, INSTALL: ${INSTALL}, ARCH: ${ARCH}, RELEASE: ${RELEASE}"
APTLY_CONF="-max-tries=3 "
[[ "${CHECKSUM}" == "ignore" ]] && APTLY_CONF+="-ignore-checksums "
[[ "${SIGNATURES}" == "ignore" ]] && APTLY_CONF+="-ignore-signatures "
# Read existing releases and create folder structure
rm -rf build/output/{debs,debs-beta}
ALL_RELEASES=($(grep -rw build/config/distributions/*/support -ve 'eos' | cut -d"/" -f4 ))
for i in ${ALL_RELEASES[@]}; do
mkdir -p build/output/{debs,debs-beta}/${i}
mkdir -p build/output/{debs,debs-beta}/extra/${i}-utils
mkdir -p build/output/{debs,debs-beta}/extra/${i}-desktop
# Add example.deb to each subfolder to ensure empty repos are published
for repo_root in build/output/debs build/output/debs-beta; do
cp build/tools/repository/example.deb ${repo_root}/${i}/
cp build/tools/repository/example.deb ${repo_root}/extra/${i}-utils/
cp build/tools/repository/example.deb ${repo_root}/extra/${i}-desktop/
done
done
needs_qemu='${{ matrix.needs_qemu }}'
arch='${{ matrix.arch }}'
release='${{ matrix.release }}'
# Configure Ubuntu foreign architecture sources (only needed for aptly method)
if [[ -r /etc/os-release ]]; then
. /etc/os-release
if [[ "${ID:-}" == "ubuntu" ]]; then
# Only add foreign arch sources when needed
if [[ "$needs_qemu" == "true" && "$arch" != "amd64" ]]; then
# Enable foreign architecture
dpkg --add-architecture "$arch"
SRC="/etc/apt/sources.list.d/ubuntu-${arch}.sources"
KEYRING="/usr/share/keyrings/ubuntu-archive-keyring.gpg"
# Create source only if it does not exist
if [[ ! -f "$SRC" ]]; then
printf '%s\n' \
"Types: deb" \
"URIs: http://ports.ubuntu.com/ubuntu-ports" \
"Suites: ${release} ${release}-updates ${release}-backports" \
"Components: main restricted universe multiverse" \
"Architectures: ${arch}" \
"Signed-By: ${KEYRING}" \
> "$SRC"
fi
fi
fi
fi
- name: "Download method: ${{ matrix.method }}"
id: calculate
shell: bash
run: |
# Load configuration
. os/external/${{ matrix.name }}.conf
SOURCE="temp/"
rm -rf ${SOURCE}
mkdir -p ${SOURCE}
# Get current version from Armbian repository
PKG="${INSTALL%% *}"
# Determine the repository component based on TARGET
if [[ "${TARGET}" == "main" ]]; then
COMPONENT="main"
else
COMPONENT="extra/${{ matrix.release }}-${TARGET}"
fi
# Get version from main repository
BEFORE_VERSION=""
# Try main component, desktop component, then extra component
for repo_component in "main" "${{ matrix.release }}-desktop" "${{ matrix.release }}-utils"; do
# Build URL for Packages index
CURRENT_PACKAGES_URL="${PACKAGES_URL}/dists/${{ matrix.release }}/${repo_component}/binary-${{ matrix.arch }}/Packages.gz"
echo "::debug::Trying $CURRENT_PACKAGES_URL"
# Download and parse the package index
# Use || true to prevent SIGPIPE when wget fails (404)
# shellcheck disable=SC2002
BEFORE_VERSION="$(wget --timeout=10 --tries=3 -qO- "$CURRENT_PACKAGES_URL" 2>/dev/null | \
gunzip 2>/dev/null | \
awk -v pkg="$PKG" '
/^Package: / { pkg_name = $2 }
/^Version: / { if (pkg_name == pkg) { print $2; exit } }
')" || true
if [[ -n "$BEFORE_VERSION" ]]; then
echo "::notice::Found $PKG version $BEFORE_VERSION in ${repo_component}"
break
fi
done
if [[ -z "$BEFORE_VERSION" ]]; then
echo "::warning::Could not find version for $PKG in repository, assuming new package"
BEFORE_VERSION="0"
fi
echo "BEFORE_VERSION=${BEFORE_VERSION}" >> $GITHUB_OUTPUT
# Download packages based on method
if [[ ${METHOD} == gh ]]; then
# GitHub release download method
case "${{ matrix.arch }}" in
amd64)
PATTERNS+=('*amd64*.deb' '*x86_64*.deb' '*x64*.deb')
;;
arm64)
PATTERNS+=('*arm64*.deb' '*aarch64*.deb')
;;
armhf)
PATTERNS+=('*armhf*.deb' '*armv7*.deb' '*armv7l*.deb' '*armv6*.deb')
;;
riscv64)
PATTERNS+=('*riscv64*.deb')
;;
*)
echo "Unsupported arch: ${{ matrix.arch }}" >&2
exit 1
;;
esac
# exception
if [[ "${{ matrix.name }}" == "haos-supervised-installer" ]]; then
PATTERNS=('*.deb')
fi
echo "Downloading from GitHub release ${TAG}"
for p in "${PATTERNS[@]}"; do
echo " gh release download ${TAG} -p '$p' --repo ${URL}"
gh release download "${TAG}" \
-p "$p" \
--repo "${URL}" \
--dir "${SOURCE}" || true
done
# exception
if [[ "${{ matrix.name }}" == "fastfetch" ]]; then
rm -f "${SOURCE}"*polyfilled*
rm -f "${SOURCE}"*armv6l.deb
fi
# Check if any .deb files were downloaded
if ! ls "${SOURCE}"*.deb &> /dev/null; then
echo "::error::No .deb files were downloaded for ${{ matrix.name }} on ${{ matrix.arch }}" >&2
echo "Patterns tried: ${PATTERNS[*]}" >&2
exit 1
fi
elif [[ ${METHOD} == direct ]]; then
# Direct download method
wget -O ${SOURCE}${{ matrix.name }}.deb ${URL}
# Check if any .deb files were downloaded
if ! ls "${SOURCE}"*.deb &> /dev/null; then
echo "::error::No .deb files were downloaded for ${{ matrix.name }} on ${{ matrix.arch }}" >&2
exit 1
fi
else
# Aptly mirror method
# Pin aptly state (critical in GH Actions containers)
set -euo pipefail
export HOME=/root
APTLY_ROOT="/root/.aptly"
APTLY_CFG="/root/.aptly.conf"
mkdir -p "$APTLY_ROOT"
printf '{ "rootDir": "%s" }\n' "$APTLY_ROOT" > "$APTLY_CFG"
echo "::debug::APTLY_ROOT=$APTLY_ROOT"
echo "::debug::APTLY_CFG=$APTLY_CFG"
echo "::debug::Config file contents:"
cat "$APTLY_CFG" >&2
SOURCE="/root/.aptly/public/"
# Configure filtering
ADDITIONAL_FILTER=""
FILTER_ARGS=()
# Add -filter-with-deps only when filter does NOT include Name/Version
if [[ "${GLOB:-}" != *Name* && "${GLOB:-}" != *Version* ]]; then
ADDITIONAL_FILTER="-filter-with-deps"
fi
# Add filter only if GLOB is set/non-empty
if [[ -n "${GLOB:-}" ]]; then
FILTER_ARGS=(-filter="$GLOB")
fi
# Make mirror name unique per arch to avoid collisions
MIRROR="${{ matrix.name }}-${{ matrix.release }}-${{ matrix.arch }}"
echo "::debug::MIRROR_NAME=$MIRROR"
echo "::debug::Original KEY='${KEY:-}'"
# KEY may be:
# - "unstable contrib non-free" (suite + components)
# - "bookworm" (suite only)
# - "./" / "public" / "stable" (special/flat)
read -r DIST REST <<<"${KEY:-}"
COMPONENTS="$REST"
echo "::debug::DIST='$DIST'"
echo "::debug::REST='$REST'"
echo "::debug::COMPONENTS='$COMPONENTS'"
# Special/flat cases: do not pass components
case "${KEY:-}" in
"./"|"stable"|"public"|"stable non-free")
DIST="$KEY"
COMPONENTS=""
;;
esac
# If KEY did not include components, default to "main"
if [[ -z "$COMPONENTS" && "$DIST" != "./" && "$DIST" != "stable" && "$DIST" != "public" && "$DIST" != "stable non-free" ]]; then
COMPONENTS="main"
fi
echo "::debug::Final DIST='$DIST'"
echo "::debug::Final COMPONENTS='$COMPONENTS'"
# Prefer https (helps with EOF/proxy weirdness)
URL="${URL:-}"
URL="${URL/http:\/\//https:\/\/}"
echo "::debug::URL='$URL'"
echo "::debug::FILTER_ARGS='${FILTER_ARGS[*]}'"
echo "::debug::ADDITIONAL_FILTER='$ADDITIONAL_FILTER'"
echo "::debug::ARCH='${{ matrix.arch }}'"
# Drop mirror if it already exists from previous run
echo "::debug::Checking if mirror exists..."
if aptly -config="$APTLY_CFG" mirror show "$MIRROR" &>/dev/null; then
echo "::notice::Dropping existing mirror: $MIRROR"
aptly -config="$APTLY_CFG" mirror drop "$MIRROR" || true
else
echo "::debug::Mirror does not exist yet"
fi
# Create mirror (distribution + optional components)
echo "::debug::Creating mirror..."
if [[ -n "$COMPONENTS" ]]; then
echo "::debug::aptly -config="$APTLY_CFG" -ignore-signatures ${FILTER_ARGS[*]} ${ADDITIONAL_FILTER} -architectures="${{ matrix.arch }}" mirror create "$MIRROR" "$URL" "$DIST" $COMPONENTS"
# shellcheck disable=SC2086
aptly -config="$APTLY_CFG" -ignore-signatures "${FILTER_ARGS[@]}" $ADDITIONAL_FILTER -architectures="${{ matrix.arch }}" mirror create "$MIRROR" "$URL" "$DIST" $COMPONENTS
else
echo "::debug::aptly -config="$APTLY_CFG" -ignore-signatures ${FILTER_ARGS[*]} ${ADDITIONAL_FILTER} -architectures="${{ matrix.arch }}" mirror create "$MIRROR" "$URL" "$DIST""
# shellcheck disable=SC2086
aptly -config="$APTLY_CFG" -ignore-signatures "${FILTER_ARGS[@]}" $ADDITIONAL_FILTER -architectures="${{ matrix.arch }}" mirror create "$MIRROR" "$URL" "$DIST"
fi
echo "::debug::Mirror created successfully"
# Update mirror with retry logic for EOF errors
echo "::debug::Updating mirror..."
MAX_RETRIES=3
RETRY_COUNT=0
UPDATE_SUCCESS=false
while [[ $RETRY_COUNT -lt $MAX_RETRIES && "$UPDATE_SUCCESS" == "false" ]]; do
if aptly -config="$APTLY_CFG" -max-tries=20 -ignore-signatures mirror update "$MIRROR"; then
echo "::debug::Mirror updated successfully"
UPDATE_SUCCESS=true
else
RETRY_COUNT=$((RETRY_COUNT + 1))
if [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; then
echo "::warning::Mirror update failed (attempt $RETRY_COUNT/$MAX_RETRIES), retrying..."
sleep 2
# Recreate mirror if it got corrupted
echo "::debug::Recreating mirror after failure..."
aptly -config="$APTLY_CFG" mirror drop "$MIRROR" || true
if [[ -n "$COMPONENTS" ]]; then
# shellcheck disable=SC2086
aptly -config="$APTLY_CFG" -ignore-signatures "${FILTER_ARGS[@]}" $ADDITIONAL_FILTER -architectures="${{ matrix.arch }}" mirror create "$MIRROR" "$URL" "$DIST" $COMPONENTS
else
# shellcheck disable=SC2086
aptly -config="$APTLY_CFG" -ignore-signatures "${FILTER_ARGS[@]}" $ADDITIONAL_FILTER -architectures="${{ matrix.arch }}" mirror create "$MIRROR" "$URL" "$DIST"
fi
else
echo "::error::Mirror update failed after $MAX_RETRIES attempts"
exit 1
fi
fi
done
# Snapshot
echo "::debug::Creating snapshot..."
aptly -config="$APTLY_CFG" snapshot create "$MIRROR" from mirror "$MIRROR"
echo "::debug::Snapshot created successfully"
# Publish
echo "::debug::Publishing snapshot..."
aptly -config="$APTLY_CFG" publish -architectures="${{ matrix.arch }}" -batch=true snapshot "$MIRROR"
echo "::debug::Snapshot published successfully"
# Keep only latest version of each package
ROOTS=($SOURCE)
best_for_pkg_in_dir() {
local dir="$1" pkg="$2"
local best_ver="" best_file="" f ver
while IFS= read -r -d '' f; do
f="$(basename "$f")"
ver="${f#${pkg}_}"; ver="${ver%%_*}"
if [[ -z "$best_ver" ]] || dpkg --compare-versions "$ver" gt "$best_ver"; then
best_ver="$ver"
best_file="$f"
fi
done < <(find "$dir" -maxdepth 1 -type f -name "${pkg}_*.deb" -print0)
[[ -n "$best_file" ]] && printf '%s\n' "$best_file"
}
for root in "${ROOTS[@]}"; do
[[ -d "$root" ]] || continue
# Process each directory that contains .deb files
while IFS= read -r -d '' dir; do
# List unique package names in this dir
mapfile -t pkgs < <(find "$dir" -maxdepth 1 -type f -name '*.deb' -printf '%f\n' \
| sed -E 's/_.*//' | sort -u)
( cd "$dir"
for pkg in "${pkgs[@]}"; do
best="$(best_for_pkg_in_dir "$dir" "$pkg")"
[[ -n "$best" ]] || continue
# Delete all other versions of that package in this dir
while IFS= read -r -d '' f; do
b="$(basename "$f")"
[[ "$b" == "$best" ]] && continue
rm -f -- "$b"
done < <(find "$dir" -maxdepth 1 -type f -name "${pkg}_*.deb" -print0)
echo "[$dir] kept: $best"
done
)
done < <(find "$root" -type f -name '*.deb' -printf '%h\0' | sort -zu)
done
fi
# Repack deb files with Armbian version
if [[ "${{ matrix.name }}" == "firefox" ]]; then
apt-get install -y devscripts
DEBS=($(sudo find "${SOURCE}"* -type f -name '*firefox_*.deb'))
for d in "${DEBS[@]}"; do
BEFORE=$(deb-reversion -c ${d} -s armbian)
# Add epoch 9
AFTER=9:$(echo $BEFORE | cut -d":" -f2)
echo "$d : $BEFORE -> $AFTER"
DEBEMAIL=info@armbian.com deb-reversion -v $AFTER -s armbian $d
rm $d
mv *.deb ${SOURCE}
done
fi
# Store info to GitHub Actions
AFTER_VERSION=$(find "$SOURCE" -type f -name "${INSTALL%% *}*.deb" -exec dpkg-deb -f {} Version \; | sort | uniq | tail -n 1 | cut -d":" -f2)
if [[ -z $AFTER_VERSION ]]; then
AFTER_VERSION=$(find "$SOURCE" -type f -name "*.deb" -exec dpkg-deb -f {} Version \; | sort | uniq | tail -n 1 | cut -d":" -f2)
fi
PKG_LINES="$(find "$SOURCE" -type f -name "*.deb" -printf "%f\n" 2>/dev/null | sort | sed 's/$/<br>/')"
echo "AFTER_VERSION=${AFTER_VERSION}" >> $GITHUB_OUTPUT
# Determine if update is needed
UPDATE_NEEDED="false"
if dpkg --compare-versions "$AFTER_VERSION" gt "$BEFORE_VERSION"; then
UPDATE_NEEDED="true"
fi
echo "UPDATE_NEEDED=${UPDATE_NEEDED}" >> $GITHUB_OUTPUT
# Upload packages directly to remote storage to avoid race conditions
# This prevents parallel jobs from overwriting each other's packages
# Note: StrictHostKeychecking=no is used here; consider using proper known_hosts in production
# Always upload to debs-beta for external packages
if [[ ${TARGET} == main ]]; then
# Upload to main repository directory
find "$SOURCE" -type f -name "*.deb" -exec \
rsync -e "ssh -o StrictHostKeychecking=no -p ${{ secrets.HOST_UPLOAD_PORT }}" \
-arvc --mkpath --ignore-existing {} ${{ secrets.HOST_UPLOAD_USER }}@${{ secrets.HOST_UPLOAD }}:${UPLOAD_PATH}/debs-beta/ \;
# Upload to debs only if version is newer than what's in repository
# This is checked by comparing BEFORE_VERSION from the repository
if dpkg --compare-versions "$AFTER_VERSION" gt "$BEFORE_VERSION"; then
echo "::notice::Newer version $AFTER_VERSION found, uploading to debs"
find "$SOURCE" -type f -name "*.deb" -exec \
rsync -e "ssh -o StrictHostKeychecking=no -p ${{ secrets.HOST_UPLOAD_PORT }}" \
-arvc --mkpath --ignore-existing {} ${{ secrets.HOST_UPLOAD_USER }}@${{ secrets.HOST_UPLOAD }}:${UPLOAD_PATH}/debs/ \;
else
echo "::notice::Version $AFTER_VERSION already exists in debs (has $BEFORE_VERSION), skipping upload"
fi
else
# Upload to specific release directory in debs-beta
find "$SOURCE" -type f -name "*.deb" -exec \
rsync -e "ssh -o StrictHostKeychecking=no -p ${{ secrets.HOST_UPLOAD_PORT }}" \
-arvc --mkpath --ignore-existing {} ${{ secrets.HOST_UPLOAD_USER }}@${{ secrets.HOST_UPLOAD }}:${UPLOAD_PATH}/debs-beta/extra/${{ matrix.release }}-${TARGET}/ \;
# Upload to debs only if version is newer than what's in repository
if dpkg --compare-versions "$AFTER_VERSION" gt "$BEFORE_VERSION"; then
echo "::notice::Newer version $AFTER_VERSION found, uploading to debs/extra"
find "$SOURCE" -type f -name "*.deb" -exec \
rsync -e "ssh -o StrictHostKeychecking=no -p ${{ secrets.HOST_UPLOAD_PORT }}" \
-arvc --mkpath --ignore-existing {} ${{ secrets.HOST_UPLOAD_USER }}@${{ secrets.HOST_UPLOAD }}:${UPLOAD_PATH}/debs/extra/${{ matrix.release }}-${TARGET}/ \;
else
echo "::notice::Version $AFTER_VERSION already exists in debs (has $BEFORE_VERSION), skipping upload"
fi
fi
# Upload to repository if version changed
if dpkg --compare-versions "$AFTER_VERSION" gt "$BEFORE_VERSION"; then
# Generate summary table for updates
echo '| name | method | arch | release | needs_qemu | target | before | after | updating |' >> $GITHUB_STEP_SUMMARY
echo '|--------|-------|------|---------|------------|--------|--------|--------|----------|' >> $GITHUB_STEP_SUMMARY
echo "| ${{ matrix.name }} | ${{ matrix.method }} | ${{ matrix.arch }} | ${{ matrix.release }} | ${{ matrix.needs_qemu }} | ${{ matrix.target }} | $BEFORE_VERSION | $AFTER_VERSION | ✅ |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "packages: <br><code>$PKG_LINES</code>" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ inputs.HIDE_NO_UPDATE }}" == "true" ]]; then
# Exit if HIDE_NO_UPDATE is enabled and no update needed
echo "::notice::No update needed for ${{ matrix.name }} on ${{ matrix.arch }}, exiting early"
exit 0
fi
clean:
name: "Clean"
needs: [download,postclean]
if: ${{ always() }}
runs-on: ${{ inputs.BUILD_RUNNER }}
steps:
- name: Clean artifacts
uses: geekyeggo/delete-artifact@v6
with:
name: assets-for-download-${{ inputs.CHUNK_INDEX }}
failOnError: false