Files
AlvinArch/.gitea/workflows/build-iso.yaml
T
alvinlollo 568c64d40b
Syntax Check / syntax-check (push) Failing after 24s
Fix gitea workflows
2026-09-14 17:21:38 +10:00

94 lines
3.4 KiB
YAML

name: Scheduled ArchISO 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: Install archiso and dependencies
run: |
pacman -Syu --noconfirm archiso jq
- name: Build Arch ISO
run: |
# Replace 'releng' with your custom profile directory if needed
mkarchiso -v -w work -o out/ releng
- 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