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* localrepo/local-aur.files* /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 -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 }} # Use internal Gitea URL to bypass traefik proxy timeout on large uploads GITEA_API: http://192.168.1.168:3000/api/v1 REPOSITORY: ${{ github.repository }} TAG_NAME: ${{ steps.tag.outputs.tag_name }} RELEASE_NAME: ${{ steps.tag.outputs.release_name }} run: | # Create the release via Gitea API (internal, no traefik) RELEASE_ID=$(curl -sf -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ "$GITEA_API/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 (internal, no traefik) for iso in out/*.iso; do echo "Uploading $iso ($(du -h "$iso" | cut -f1))..." curl -sf --retry 3 --retry-delay 10 \ --max-time 1800 \ -H "Authorization: token $GITEA_TOKEN" \ -F "attachment=@$iso" \ "$GITEA_API/repos/$REPOSITORY/releases/$RELEASE_ID/assets" echo "Upload complete: $iso" done echo "Release $TAG_NAME created and ISOs uploaded." - name: Keep only latest 3 releases env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_API: http://192.168.1.168:3000/api/v1 REPOSITORY: ${{ github.repository }} run: | # Fetch all releases releases=$(curl -sf -H "Authorization: token $GITEA_TOKEN" \ "$GITEA_API/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 -sf -X DELETE -H "Authorization: token $GITEA_TOKEN" \ "$GITEA_API/repos/$REPOSITORY/releases/$id" fi done