Skip to content

Refactor GitHub Actions workflows for Arch Linux builds: #33

Refactor GitHub Actions workflows for Arch Linux builds:

Refactor GitHub Actions workflows for Arch Linux builds: #33

Workflow file for this run

name: Build ISO
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Run the workflow every day at midnight
push:
branches:
- main
- dev
paths-ignore:
- '**.md'
- '.gitignore'
env:
DOCKER_BUILDKIT: 1
ISO_FILENAME: Arch.iso
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 120 # Set a timeout to prevent hung builds
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up environment variables
id: env
run: |
echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
echo "VERSION=$(date +'%Y.%m.%d')" >> $GITHUB_ENV
echo "CACHE_KEY=$(date +'%Y-%m')" >> $GITHUB_ENV
echo "WORKSPACE=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
- name: Create Cache Directories
run: |
sudo mkdir -p /tmp/pacman-cache
sudo chmod 777 /tmp/pacman-cache
- name: Cache Pacman packages
uses: actions/cache@v3
with:
path: /tmp/pacman-cache
key: pacman-${{ env.CACHE_KEY }}
restore-keys: |
pacman-
- name: Set up Arch Linux Container
run: |
docker run --privileged --name arch-container -d \
-v ${{ env.WORKSPACE }}:/workdir \
-v /tmp/pacman-cache:/var/cache/pacman/pkg \
archlinux:latest sleep infinity
- name: Initialize Container
run: |
docker exec arch-container bash -c "
set -euo pipefail
# Update package database
pacman -Sy --noconfirm
# Install required packages
pacman -S --noconfirm --needed \
git \
archiso \
grub \
curl \
jq \
gnupg \
make \
sudo
# Verify installation
command -v mkarchiso >/dev/null 2>&1 || {
echo 'Error: mkarchiso not found'
exit 1
}
"
- name: Build ISO
id: build
run: |
docker exec arch-container bash -c "
set -euo pipefail
cd /workdir
# Cleanup any previous builds
rm -rf workdir/ out/
mkdir -p out/
# Build the ISO with verbose output
mkarchiso -v -w workdir/ -o out/ . 2>&1 | tee build.log || {
echo 'Error: ISO build failed!'
tail -n 50 build.log
exit 1
}
# Verify ISO was created
[ -f out/*.iso ] || {
echo 'Error: ISO file not found after build'
exit 1
}
"
- name: Generate Checksums
run: |
docker exec arch-container bash -c "
set -euo pipefail
cd /workdir/out
# Generate checksums
for iso in *.iso; do
sha256sum \"\$iso\" > \"\${iso}.sha256sum\"
sha512sum \"\$iso\" > \"\${iso}.sha512sum\"
done
"
- name: Rename and Move ISO
run: |
docker exec arch-container bash -c "
set -euo pipefail
cd /workdir/out
for f in *.iso; do
newname=\"arch-linux-no-beeps-${{ env.VERSION }}.iso\"
mv \"\$f\" \"\$newname\"
mv \"\$f.sha256sum\" \"\$newname.sha256sum\"
mv \"\$f.sha512sum\" \"\$newname.sha512sum\"
done
"
- name: Upload ISO Artifact
uses: actions/upload-artifact@v3
with:
name: arch-linux-no-beeps-${{ env.VERSION }}
path: |
${{ env.WORKSPACE }}/out/*.iso
${{ env.WORKSPACE }}/out/*.sha*sum
retention-days: 5
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
if: github.ref == 'refs/heads/main'
with:
tag_name: v${{ env.VERSION }}
name: "Arch Linux No Beeps v${{ env.VERSION }}"
body: |
🚀 Arch Linux ISO without system beeps (build ${{ env.DATE }})
### Changes
- Automatic daily build
- System beeps disabled
- ISO SHA256 and SHA512 checksums added
### Download
- Download the ISO and verify checksums before use
### Checksums
SHA256 and SHA512 checksums are available in the uploaded files.
draft: false
prerelease: false
files: |
${{ env.WORKSPACE }}/out/*.iso
${{ env.WORKSPACE }}/out/*.sha*sum
- name: Clean Up
if: always()
run: |
docker stop arch-container || true
docker rm arch-container || true
sudo rm -rf workdir/ out/ /tmp/pacman-cache/*
- name: Upload Build Logs on Failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: build-logs
path: |
${{ env.WORKSPACE }}/build.log
retention-days: 5