Skip to content

Commit e119c99

Browse files
Refactor GitHub Actions workflows for Arch Linux ISO build:
- Split build process into validate, security scan, and test build jobs. - Add package validation and security scanning steps. - Implement caching for Pacman packages and Docker layers. - Enhance error handling and reporting for ISO build process. - Update release process to include checksum generation and improved naming conventions for artifacts.
1 parent ad5ecde commit e119c99

File tree

4 files changed

+441
-107
lines changed

4 files changed

+441
-107
lines changed

.github/workflows/build-check.yaml

Lines changed: 109 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,141 @@
1-
name: Check if ISO can be built
1+
name: Validate and Test Build
22

33
on:
44
pull_request:
55
branches:
66
- main
7+
- dev
78
workflow_dispatch:
89
schedule:
910
- cron: '0 0 * * *'
1011

12+
env:
13+
DOCKER_BUILDKIT: 1
14+
1115
jobs:
12-
build:
16+
validate:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout Repository
20+
uses: actions/checkout@v4
21+
22+
- name: Validate package list
23+
run: |
24+
# Check for duplicate packages
25+
sort packages.x86_64 | uniq -d > duplicates.txt
26+
if [ -s duplicates.txt ]; then
27+
echo "::error::Duplicate packages found:"
28+
cat duplicates.txt
29+
exit 1
30+
fi
31+
32+
# Validate package names exist in Arch repos
33+
docker run --rm archlinux:latest bash -c "
34+
pacman -Sy
35+
while read -r pkg; do
36+
[[ \$pkg =~ ^# ]] && continue
37+
[[ -z \$pkg ]] && continue
38+
pacman -Si \$pkg >/dev/null 2>&1 || {
39+
echo \"::error::Package not found: \$pkg\"
40+
exit 1
41+
}
42+
done < packages.x86_64
43+
"
44+
45+
security-scan:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout Repository
49+
uses: actions/checkout@v4
50+
51+
- name: Run Security Scan
52+
uses: aquasecurity/trivy-action@master
53+
with:
54+
scan-type: 'fs'
55+
ignore-unfixed: true
56+
format: 'sarif'
57+
output: 'trivy-results.sarif'
58+
severity: 'CRITICAL,HIGH'
59+
60+
- name: Upload Scan Results
61+
uses: github/codeql-action/upload-sarif@v2
62+
if: always()
63+
with:
64+
sarif_file: 'trivy-results.sarif'
65+
66+
test-build:
67+
needs: [validate, security-scan]
1368
runs-on: ubuntu-latest
69+
timeout-minutes: 120
1470

1571
steps:
1672
- name: Checkout Repository
1773
uses: actions/checkout@v4
1874

75+
- name: Cache Pacman packages
76+
uses: actions/cache@v3
77+
with:
78+
path: /tmp/pacman-cache
79+
key: pacman-test-${{ github.sha }}
80+
restore-keys: |
81+
pacman-test-
82+
1983
- name: Set up Arch Linux Container
2084
run: |
21-
docker run --privileged --name arch-container -d -v ${{ github.workspace }}:/workdir archlinux:latest sleep infinity
85+
mkdir -p /tmp/pacman-cache
86+
docker run --privileged --name arch-container -d \
87+
-v ${{ github.workspace }}:/workdir \
88+
-v /tmp/pacman-cache:/var/cache/pacman/pkg \
89+
archlinux:latest sleep infinity
2290
23-
- name: Build ISO in Arch Container
91+
- name: Install Dependencies
2492
run: |
2593
docker exec arch-container bash -c "
26-
pacman -Syu --noconfirm &&
27-
pacman -S --noconfirm git archiso grub &&
28-
cd /workdir &&
29-
mkarchiso -v -w workdir/ -o out/ .
94+
set -euo pipefail
95+
pacman -Sy --noconfirm
96+
pacman -S --noconfirm --needed git archiso grub
3097
"
3198
32-
- name: Rename ISO to Arch.iso
99+
- name: Test Build
100+
id: build
33101
run: |
34102
docker exec arch-container bash -c "
35-
iso_file=\$(ls /workdir/out/*.iso 2>/dev/null | head -n 1) &&
36-
[ -n \"\$iso_file\" ] && mv \$iso_file /workdir/out/Arch.iso || echo 'No ISO file found.'
103+
set -euo pipefail
104+
cd /workdir
105+
rm -rf workdir/ out/
106+
mkarchiso -v -w workdir/ -o out/ .
37107
"
38108
39-
- name: Copy ISO to Host
109+
- name: Verify ISO
40110
run: |
41-
docker cp arch-container:/workdir/out/Arch.iso ${{ github.workspace }}/ || echo 'Failed to copy ISO to host.'
42-
43-
- name: Get current date
44-
id: date
45-
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
111+
docker exec arch-container bash -c "
112+
cd /workdir/out
113+
# Check if ISO exists
114+
[ -f *.iso ] || {
115+
echo '::error::ISO file not found'
116+
exit 1
117+
}
118+
# Check ISO size (minimum 500MB)
119+
size=\$(stat -c%s *.iso)
120+
[ \$size -gt 524288000 ] || {
121+
echo '::error::ISO file too small'
122+
exit 1
123+
}
124+
"
46125
47-
- name: Create GitHub Release
48-
id: create_release
49-
uses: actions/[email protected]
50-
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
with:
53-
tag_name: v${{ github.run_id }}-release
54-
release_name: "Arch Linux Release"
55-
body: "Arch Linux ISO built on ${{ steps.date.outputs.date }}"
56-
draft: false
57-
prerelease: false
58-
59-
- name: Upload ISO to GitHub Release
60-
uses: actions/upload-release-asset@v1
61-
env:
62-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63-
with:
64-
upload_url: ${{ steps.create_release.outputs.upload_url }}
65-
asset_path: ${{ github.workspace }}/Arch.iso
66-
asset_name: Arch.iso
67-
asset_content_type: application/octet-stream
68-
69-
- name: Delete GitHub Release
70-
env:
71-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72-
run: |
73-
release_id=$(curl -s \
74-
-H "Authorization: token $GITHUB_TOKEN" \
75-
-H "Accept: application/vnd.github.v3+json" \
76-
https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ github.run_id }}-release | jq -r .id) &&
77-
curl -X DELETE \
78-
-H "Authorization: token $GITHUB_TOKEN" \
79-
-H "Accept: application/vnd.github.v3+json" \
80-
https://api.github.com/repos/${{ github.repository }}/releases/$release_id
81-
82-
- name: Delete Git Tag
83-
env:
84-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
- name: Clean Up
127+
if: always()
85128
run: |
86-
curl -X DELETE \
87-
-H "Authorization: token $GITHUB_TOKEN" \
88-
-H "Accept: application/vnd.github.v3+json" \
89-
https://api.github.com/repos/${{ github.repository }}/git/refs/tags/v${{ github.run_id }}-release
129+
docker stop arch-container || true
130+
docker rm arch-container || true
131+
rm -rf workdir/ out/
90132
91-
- name: Clean Up
133+
- name: Report Status
134+
if: always()
92135
run: |
93-
docker stop arch-container || echo 'Failed to stop the container.'
94-
docker rm arch-container || echo 'Failed to remove the container.'
136+
if [ "${{ job.status }}" = "success" ]; then
137+
echo "✅ Build check passed successfully"
138+
else
139+
echo "❌ Build check failed"
140+
exit 1
141+
fi

.github/workflows/build.yaml

Lines changed: 110 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,146 @@ on:
44
workflow_dispatch:
55
schedule:
66
- cron: '0 0 * * *' # Run the workflow every day at midnight
7+
push:
8+
branches:
9+
- main
10+
- dev
11+
paths-ignore:
12+
- '**.md'
13+
- '.gitignore'
14+
15+
env:
16+
DOCKER_BUILDKIT: 1
17+
ISO_FILENAME: Arch.iso
718

819
jobs:
920
build:
10-
runs-on: ubuntu-latest # Use a standard runner
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 120 # Set a timeout to prevent hung builds
1123

1224
steps:
1325
- name: Checkout Repository
1426
uses: actions/checkout@v4
1527

28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
with:
31+
buildkitd-flags: --debug
32+
33+
- name: Cache Docker layers
34+
uses: actions/cache@v3
35+
with:
36+
path: /tmp/.buildx-cache
37+
key: ${{ runner.os }}-buildx-${{ github.sha }}
38+
restore-keys: |
39+
${{ runner.os }}-buildx-
40+
41+
- name: Set up environment variables
42+
id: env
43+
run: |
44+
echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
45+
echo "VERSION=$(date +'%Y.%m.%d')" >> $GITHUB_ENV
46+
echo "CACHE_KEY=$(date +'%Y-%m')" >> $GITHUB_ENV
47+
48+
- name: Cache Pacman packages
49+
uses: actions/cache@v3
50+
with:
51+
path: /tmp/pacman-cache
52+
key: pacman-${{ env.CACHE_KEY }}
53+
restore-keys: |
54+
pacman-
55+
1656
- name: Set up Arch Linux Container
1757
run: |
18-
docker run --privileged --name arch-container -d -v ${{ github.workspace }}:/workdir archlinux:latest sleep infinity
58+
mkdir -p /tmp/pacman-cache
59+
docker run --privileged --name arch-container -d \
60+
-v ${{ github.workspace }}:/workdir \
61+
-v /tmp/pacman-cache:/var/cache/pacman/pkg \
62+
archlinux:latest sleep infinity
1963
20-
- name: Build ISO in Arch Container
64+
- name: Update and Install Dependencies
2165
run: |
22-
set -e
2366
docker exec arch-container bash -c "
24-
pacman -Syu --noconfirm &&
25-
pacman -S --noconfirm git archiso grub &&
26-
cd /workdir &&
27-
mkarchiso -v -w workdir/ -o out/ .
67+
set -euo pipefail
68+
pacman -Sy --noconfirm
69+
pacman -S --noconfirm --needed git archiso grub curl jq gnupg
2870
"
2971
30-
- name: Rename ISO to Arch.iso
72+
- name: Build ISO
73+
id: build
3174
run: |
32-
set -e
3375
docker exec arch-container bash -c "
34-
iso_file=\$(ls /workdir/out/*.iso 2>/dev/null | head -n 1) &&
35-
[ -n \"\$iso_file\" ] && mv \$iso_file /workdir/out/Arch.iso || echo 'No ISO file found.'
76+
set -euo pipefail
77+
cd /workdir
78+
# Cleanup any previous builds
79+
rm -rf workdir/ out/
80+
# Build the ISO with verbose output
81+
mkarchiso -v -w workdir/ -o out/ . || {
82+
echo 'ISO build failed!'
83+
exit 1
84+
}
3685
"
3786
38-
- name: List ISO files
87+
- name: Generate Checksums
3988
run: |
40-
docker exec arch-container bash -c "ls -l /workdir/out/" || echo 'Failed to list files.'
89+
docker exec arch-container bash -c "
90+
cd /workdir/out
91+
sha256sum *.iso > sha256sums.txt
92+
sha512sum *.iso > sha512sums.txt
93+
"
4194
42-
- name: Copy ISO to Host
95+
- name: Rename and Move ISO
4396
run: |
44-
docker cp arch-container:/workdir/out/Arch.iso ${{ github.workspace }}/ || echo 'Failed to copy ISO to host.'
97+
docker exec arch-container bash -c "
98+
cd /workdir/out
99+
for f in *.iso; do
100+
mv \"\$f\" \"arch-linux-no-beeps-${{ env.VERSION }}.iso\"
101+
done
102+
"
45103
46104
- name: Upload ISO Artifact
47105
uses: actions/upload-artifact@v3
48106
with:
49-
name: Arch.iso
50-
path: ${{ github.workspace }}/Arch.iso
51-
52-
- name: Get current date
53-
id: date
54-
run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
55-
56-
# Create a release on GitHub using GITHUB_TOKEN
57-
- name: Create GitHub Release
58-
id: create_release # Adding an ID to reference the release step
59-
uses: actions/[email protected]
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
name: arch-linux-no-beeps-${{ env.VERSION }}
108+
path: |
109+
${{ github.workspace }}/out/*.iso
110+
${{ github.workspace }}/out/sha*sums.txt
111+
retention-days: 5
112+
113+
- name: Create Release
114+
id: create_release
115+
uses: softprops/action-gh-release@v1
116+
if: github.ref == 'refs/heads/main'
62117
with:
63-
tag_name: "v${{ github.run_id }}-release"
64-
release_name: "Arch Linux Release"
118+
tag_name: v${{ env.VERSION }}
119+
name: "Arch Linux No Beeps v${{ env.VERSION }}"
65120
body: |
66-
This release contains the Arch Linux ISO built on ${{ steps.date.outputs.DATE }}.
121+
🚀 Arch Linux ISO without system beeps (build ${{ env.DATE }})
122+
123+
### Changes
124+
- Automatic daily build
125+
- System beeps disabled
126+
- ISO SHA256 and SHA512 checksums added
127+
128+
### Download
129+
- Download the ISO and verify checksums before use
130+
131+
### Checksums
132+
SHA256 and SHA512 checksums are available in the uploaded files.
67133
draft: false
68134
prerelease: false
69-
70-
# Upload the ISO to the GitHub release with a specific, predictable name
71-
- name: Upload ISO to GitHub Release
72-
uses: actions/upload-release-asset@v1
73-
env:
74-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75-
with:
76-
upload_url: ${{ steps.create_release.outputs.upload_url }}
77-
asset_path: ${{ github.workspace }}/Arch.iso
78-
asset_name: Arch.iso
79-
asset_content_type: application/octet-stream
135+
files: |
136+
${{ github.workspace }}/out/*.iso
137+
${{ github.workspace }}/out/sha*sums.txt
80138
81139
- name: Clean Up
140+
if: always()
141+
run: |
142+
docker stop arch-container || true
143+
docker rm arch-container || true
144+
rm -rf workdir/ out/
145+
146+
- name: Notify on Failure
147+
if: failure()
82148
run: |
83-
docker stop arch-container || echo 'Failed to stop the container.'
84-
docker rm arch-container || echo 'Failed to remove the container.'
149+
echo "::error::ISO build failed! Check the logs for more details."

0 commit comments

Comments
 (0)