name: release-aur on: # Trigger after release-linux completes (it uploads amd64 tarball) workflow_run: workflows: ["release-linux"] types: [completed] workflow_dispatch: inputs: version: description: "Version to publish (e.g. 1.0.0)" required: true type: string pkgrel: description: "Package release number (bump for same-version rebuilds)" required: false default: "1" type: string concurrency: group: aur-publish cancel-in-progress: false permissions: contents: read jobs: update-aur: runs-on: ubuntu-latest # Only run on manual dispatch, or successful stable tag releases (no -rc) if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v') && !contains(github.event.workflow_run.head_branch, '-rc')) }} steps: - name: Checkout uses: actions/checkout@v4 - name: Determine version id: version env: EVENT_NAME: ${{ github.event_name }} WORKFLOW_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} DISPATCH_VERSION: ${{ inputs.version }} run: | if [[ "$EVENT_NAME" == "workflow_run" ]]; then # Extract version from the triggering workflow's head branch (tag) REF="$WORKFLOW_HEAD_BRANCH" if [[ ! "$REF" =~ ^v[0-9]+(\.[0-9]+){1,3}([.-][0-9A-Za-z.-]+)?$ ]]; then echo "Invalid workflow_run head branch for release: $REF" exit 1 fi VERSION="${REF#v}" else VERSION="$DISPATCH_VERSION" fi echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "Detected version: $VERSION" - name: Wait for all release assets env: VERSION: ${{ steps.version.outputs.version }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo "Waiting for release assets to be available..." echo "Note: amd64 should be ready (release-linux completed), waiting for aarch64..." MAX_WAIT=1800 INTERVAL=30 ELAPSED=0 while [ $ELAPSED -lt $MAX_WAIT ]; do echo "Checking for release assets (${ELAPSED}s elapsed)..." # Check if both tarballs exist (follow redirects, GitHub returns 302) AMD64_CODE=$(curl -sL -o /dev/null -w "%{http_code}" "https://github.com/vicrodh/qbz/releases/download/v${VERSION}/qbz_${VERSION}_amd64.tar.gz") AARCH64_CODE=$(curl -sL -o /dev/null -w "%{http_code}" "https://github.com/vicrodh/qbz/releases/download/v${VERSION}/qbz_${VERSION}_aarch64.tar.gz") AMD64_EXISTS=$([[ "$AMD64_CODE" == "200" ]] && echo "true" || echo "false") AARCH64_EXISTS=$([[ "$AARCH64_CODE" == "200" ]] && echo "true" || echo "false") if [ "$AMD64_EXISTS" = "true" ] && [ "$AARCH64_EXISTS" = "true" ]; then echo "Both release assets are available!" break fi echo "Waiting for assets... (amd64: $AMD64_EXISTS, aarch64: $AARCH64_EXISTS)" sleep $INTERVAL ELAPSED=$((ELAPSED + INTERVAL)) done if [ $ELAPSED -ge $MAX_WAIT ]; then echo "Timeout waiting for release assets after 30 minutes" exit 1 fi - name: Download release tarballs and get checksums id: checksums env: VERSION: ${{ steps.version.outputs.version }} run: | # Download x86_64 tarball AMD64_URL="https://github.com/vicrodh/qbz/releases/download/v${VERSION}/qbz_${VERSION}_amd64.tar.gz" echo "Downloading: $AMD64_URL" curl -fsSL -o /tmp/qbz_amd64.tar.gz "$AMD64_URL" SHA256_AMD64=$(sha256sum /tmp/qbz_amd64.tar.gz | cut -d' ' -f1) echo "sha256_amd64=$SHA256_AMD64" >> "$GITHUB_OUTPUT" echo "x86_64 Checksum: $SHA256_AMD64" # Download aarch64 tarball AARCH64_URL="https://github.com/vicrodh/qbz/releases/download/v${VERSION}/qbz_${VERSION}_aarch64.tar.gz" echo "Downloading: $AARCH64_URL" curl -fsSL -o /tmp/qbz_aarch64.tar.gz "$AARCH64_URL" SHA256_AARCH64=$(sha256sum /tmp/qbz_aarch64.tar.gz | cut -d' ' -f1) echo "sha256_aarch64=$SHA256_AARCH64" >> "$GITHUB_OUTPUT" echo "aarch64 Checksum: $SHA256_AARCH64" - name: Setup SSH for AUR env: AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }} run: | mkdir -p ~/.ssh echo "$AUR_SSH_PRIVATE_KEY" > ~/.ssh/aur chmod 600 ~/.ssh/aur echo "Host aur.archlinux.org" >> ~/.ssh/config echo " IdentityFile ~/.ssh/aur" >> ~/.ssh/config echo " User aur" >> ~/.ssh/config ssh-keyscan -t ed25519 aur.archlinux.org >> ~/.ssh/known_hosts - name: Clone AUR repo run: | git clone ssh://aur@aur.archlinux.org/qbz-bin.git /tmp/aur-qbz-bin cd /tmp/aur-qbz-bin # Ensure we are on master (recover from detached HEAD if remote branch was corrupted) git checkout master 2>/dev/null || git checkout -b master - name: Determine pkgrel id: pkgrel run: | if [[ "${{ github.event_name }}" == "release" ]]; then echo "pkgrel=1" >> "$GITHUB_OUTPUT" else echo "pkgrel=${{ inputs.pkgrel || '1' }}" >> "$GITHUB_OUTPUT" fi - name: Update PKGBUILD env: VERSION: ${{ steps.version.outputs.version }} PKGREL: ${{ steps.pkgrel.outputs.pkgrel }} SHA256_AMD64: ${{ steps.checksums.outputs.sha256_amd64 }} SHA256_AARCH64: ${{ steps.checksums.outputs.sha256_aarch64 }} run: | cd /tmp/aur-qbz-bin # Copy PKGBUILD from main repo (source of truth) cp ${{ github.workspace }}/packaging/aur/PKGBUILD . # Update version and pkgrel sed -i "s/^pkgver=.*/pkgver=${VERSION}/" PKGBUILD sed -i "s/^pkgrel=.*/pkgrel=${PKGREL}/" PKGBUILD # Update checksums for both architectures sed -i "s/^sha256sums_x86_64=.*/sha256sums_x86_64=('${SHA256_AMD64}')/" PKGBUILD sed -i "s/^sha256sums_aarch64=.*/sha256sums_aarch64=('${SHA256_AARCH64}')/" PKGBUILD echo "=== Updated PKGBUILD ===" cat PKGBUILD - name: Generate .SRCINFO run: | cd /tmp/aur-qbz-bin docker run --rm -v "$PWD":/pkg -w /pkg -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) archlinux:latest bash -c " pacman -Sy --noconfirm pacman-contrib sudo useradd -m builder chown -R builder:builder /pkg sudo -u builder makepkg --printsrcinfo > .SRCINFO chown -R \$HOST_UID:\$HOST_GID /pkg " cat .SRCINFO - name: Commit and push to AUR env: VERSION: ${{ steps.version.outputs.version }} run: | cd /tmp/aur-qbz-bin git config user.name "GitHub Actions" git config user.email "actions@github.com" git add PKGBUILD .SRCINFO git commit -m "Update to v${VERSION}" git push