Skip to content

Commit c2a77c0

Browse files
Enhance GitHub Actions workflow for Arch Linux ISO builds:
- Introduce new environment variables for improved directory management. - Add validation for the existence of the package list file. - Streamline package installation and update commands with error handling. - Improve ISO verification process with checks for file existence, size, and checksum validation. - Refactor cleanup steps to ensure proper removal of temporary directories and containers.
1 parent d39c389 commit c2a77c0

File tree

1 file changed

+53
-23
lines changed

1 file changed

+53
-23
lines changed

.github/workflows/build-check.yaml

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111

1212
env:
1313
DOCKER_BUILDKIT: 1
14+
PACMAN_CACHE: /tmp/pacman-cache
15+
WORKSPACE: /workdir
16+
BUILD_DIR: /workdir/workdir
17+
OUTPUT_DIR: /workdir/out
1418

1519
jobs:
1620
validate:
@@ -21,6 +25,12 @@ jobs:
2125

2226
- name: Validate package list
2327
run: |
28+
# Check if package list exists
29+
if [ ! -f packages.x86_64 ]; then
30+
echo "::error::packages.x86_64 file not found"
31+
exit 1
32+
fi
33+
2434
# Check for duplicate packages
2535
sort packages.x86_64 | uniq -d > duplicates.txt
2636
if [ -s duplicates.txt ]; then
@@ -31,14 +41,15 @@ jobs:
3141
3242
# Validate package names exist in Arch repos
3343
docker run --rm archlinux:latest bash -c "
34-
pacman -Sy
44+
set -euo pipefail
45+
pacman -Syu --noconfirm
3546
while read -r pkg; do
3647
[[ \$pkg =~ ^# ]] && continue
3748
[[ -z \$pkg ]] && continue
38-
pacman -Si \$pkg >/dev/null 2>&1 || {
49+
if ! pacman -Si \$pkg >/dev/null 2>&1; then
3950
echo \"::error::Package not found: \$pkg\"
4051
exit 1
41-
}
52+
fi
4253
done < packages.x86_64
4354
"
4455
@@ -75,24 +86,24 @@ jobs:
7586
- name: Cache Pacman packages
7687
uses: actions/cache@v3
7788
with:
78-
path: /tmp/pacman-cache
79-
key: pacman-test-${{ github.sha }}
89+
path: ${{ env.PACMAN_CACHE }}
90+
key: pacman-${{ runner.os }}-${{ github.sha }}
8091
restore-keys: |
81-
pacman-test-
92+
pacman-${{ runner.os }}-
8293
8394
- name: Set up Arch Linux Container
8495
run: |
85-
mkdir -p /tmp/pacman-cache
96+
mkdir -p ${{ env.PACMAN_CACHE }}
8697
docker run --privileged --name arch-container -d \
87-
-v ${{ github.workspace }}:/workdir \
88-
-v /tmp/pacman-cache:/var/cache/pacman/pkg \
98+
-v ${{ github.workspace }}:${{ env.WORKSPACE }} \
99+
-v ${{ env.PACMAN_CACHE }}:/var/cache/pacman/pkg \
89100
archlinux:latest sleep infinity
90101
91102
- name: Install Dependencies
92103
run: |
93104
docker exec arch-container bash -c "
94105
set -euo pipefail
95-
pacman -Sy --noconfirm
106+
pacman -Syu --noconfirm
96107
pacman -S --noconfirm --needed git archiso grub
97108
"
98109
@@ -101,34 +112,53 @@ jobs:
101112
run: |
102113
docker exec arch-container bash -c "
103114
set -euo pipefail
104-
cd /workdir
105-
rm -rf workdir/ out/
106-
mkarchiso -v -w workdir/ -o out/ .
115+
cd ${{ env.WORKSPACE }}
116+
rm -rf ${{ env.BUILD_DIR }} ${{ env.OUTPUT_DIR }}
117+
mkdir -p ${{ env.BUILD_DIR }} ${{ env.OUTPUT_DIR }}
118+
mkarchiso -v -w ${{ env.BUILD_DIR }} -o ${{ env.OUTPUT_DIR }} .
107119
"
108120
109121
- name: Verify ISO
110122
run: |
111123
docker exec arch-container bash -c "
112-
cd /workdir/out
124+
set -euo pipefail
125+
cd ${{ env.OUTPUT_DIR }}
126+
113127
# Check if ISO exists
114-
[ -f *.iso ] || {
115-
echo '::error::ISO file not found'
128+
iso_count=\$(ls -1 *.iso 2>/dev/null | wc -l)
129+
if [ \$iso_count -eq 0 ]; then
130+
echo '::error::No ISO file found'
116131
exit 1
117-
}
132+
elif [ \$iso_count -gt 1 ]; then
133+
echo '::error::Multiple ISO files found'
134+
exit 1
135+
fi
136+
137+
iso_file=\$(ls *.iso)
138+
118139
# Check ISO size (minimum 500MB)
119-
size=\$(stat -c%s *.iso)
120-
[ \$size -gt 524288000 ] || {
121-
echo '::error::ISO file too small'
140+
size=\$(stat -c%s \"\$iso_file\")
141+
if [ \$size -lt 524288000 ]; then
142+
echo \"::error::ISO file too small: \$((\$size / 1024 / 1024))MB\"
143+
exit 1
144+
fi
145+
146+
# Verify ISO checksum
147+
sha256sum \"\$iso_file\" > checksum.sha256
148+
sha256sum -c checksum.sha256 || {
149+
echo '::error::ISO checksum verification failed'
122150
exit 1
123151
}
124152
"
125153
126154
- name: Clean Up
127155
if: always()
128156
run: |
129-
docker stop arch-container || true
130-
docker rm arch-container || true
131-
rm -rf workdir/ out/
157+
if docker ps -a | grep -q arch-container; then
158+
docker stop arch-container || true
159+
docker rm -f arch-container || true
160+
fi
161+
sudo rm -rf ${{ env.BUILD_DIR }} ${{ env.OUTPUT_DIR }}
132162
133163
- name: Report Status
134164
if: always()

0 commit comments

Comments
 (0)