Tests / tests (push) Successful in 2m15s
Use -- to separate flags from profile path, preventing mkarchiso from misinterpreting the -w argument as the profile directory. Also make rm -rf fail-safe with || true.
100 lines
3.6 KiB
YAML
100 lines
3.6 KiB
YAML
name: Automated Arch ISO Build
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 0 1 * *" # Runs monthly on the 1st day of the month
|
|
workflow_dispatch: # Allows manual triggers (multiple times a month)
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: archlinux
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup local AUR repo
|
|
run: |
|
|
mkdir -p /tmp/localrepo
|
|
cp localrepo/*.pkg.tar.zst localrepo/local-aur.db* /tmp/localrepo/
|
|
sed -i 's|file:///home/alvin/alvinarch/localrepo|file:///tmp/localrepo|' pacman.conf
|
|
|
|
- name: Install archiso and dependencies
|
|
run: |
|
|
pacman -Syu --noconfirm --needed archiso jq
|
|
|
|
- name: Build Arch ISO
|
|
run: |
|
|
rm -rf "${PWD}/work" || true
|
|
mkarchiso -v -c -w "${PWD}/work" -o "${PWD}/out" -- "${PWD}"
|
|
|
|
- name: Generate Unique Dynamic Tag
|
|
id: tag
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
SERVER_URL: ${{ github.server_url }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
run: |
|
|
BASE_DATE=$(date -u +'%Y.%m.%d')
|
|
REVISION=1
|
|
TAG_NAME="iso-${BASE_DATE}-r${REVISION}"
|
|
|
|
# Check if the tag already exists via Gitea API, increment revision loop if it does
|
|
while curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" \
|
|
"$SERVER_URL/api/v1/repos/$REPOSITORY/releases/tags/$TAG_NAME" | grep -q "200"; do
|
|
REVISION=$((REVISION + 1))
|
|
TAG_NAME="iso-${BASE_DATE}-r${REVISION}"
|
|
done
|
|
|
|
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
|
|
echo "release_name=Arch Linux ISO (${BASE_DATE} Rev ${REVISION})" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create Release and Upload ISO
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
SERVER_URL: ${{ github.server_url }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
TAG_NAME: ${{ steps.tag.outputs.tag_name }}
|
|
RELEASE_NAME: ${{ steps.tag.outputs.release_name }}
|
|
run: |
|
|
# Create the release via Gitea API
|
|
RELEASE_ID=$(curl -s -X POST \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
"$SERVER_URL/api/v1/repos/$REPOSITORY/releases" \
|
|
-d "{\"tag_name\": \"$TAG_NAME\", \"name\": \"$RELEASE_NAME\"}" \
|
|
| jq -r '.id')
|
|
|
|
echo "Created release ID: $RELEASE_ID"
|
|
|
|
# Upload each ISO as a release asset
|
|
for iso in out/*.iso; do
|
|
echo "Uploading $iso..."
|
|
curl -s -X POST \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-F "attachment=@$iso" \
|
|
"$SERVER_URL/api/v1/repos/$REPOSITORY/releases/$RELEASE_ID/assets"
|
|
done
|
|
|
|
echo "Release $TAG_NAME created and ISOs uploaded."
|
|
|
|
- name: Keep only latest 3 releases
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
SERVER_URL: ${{ github.server_url }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
run: |
|
|
# Fetch all releases
|
|
releases=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
|
"$SERVER_URL/api/v1/repos/$REPOSITORY/releases")
|
|
|
|
# Sort by creation date and delete old ones, keeping only the 3 newest releases
|
|
echo "$releases" | jq -r 'sort_by(.created_at) | .[].id' | head -n -3 | while read -r id; do
|
|
if [ -n "$id" ]; then
|
|
echo "Deleting old release ID: $id"
|
|
curl -s -X DELETE -H "Authorization: token $GITEA_TOKEN" \
|
|
"$SERVER_URL/api/v1/repos/$REPOSITORY/releases/$id"
|
|
fi
|
|
done |