Files
artcraft-services/.github/workflows/linux-distro-tools.yml
Dylan M. Taylor e938767d26 ci: lock workflow actions through an actions.lock lockfile
Mutable action tags are a supply-chain risk: a moved tag runs different code
without a diff. Every workflow action is now pinned through
.github/workflows/actions.lock, and CI verifies the lockfile so an out-of-sync
or tampered one fails instead of running.
2026-11-12 07:19:43 -05:00

166 lines
7.3 KiB
YAML

name: Linux package repository tools
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
wait-for-deploy:
name: Wait for Cloudflare deploy
runs-on: ubuntu-latest
permissions:
contents: read
statuses: read
checks: read
timeout-minutes: 20
outputs:
deploy-url: ${{ steps.wait.outputs.deploy_url }}
steps:
- name: Harden runner
uses: step-security/harden-runner@v2.22.4
with:
egress-policy: audit
- name: Await Cloudflare deploy
id: wait
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BRANCH_NAME: ${{ github.head_ref }}
COMMIT_SHA: ${{ github.sha }}
REPO: ${{ github.repository }}
run: |
# The distro tests below run against a real deployment, never a server started here.
if [[ "$EVENT_NAME" == "pull_request" ]]; then
TARGET_SHA="$PR_HEAD_SHA"
SHORT_SHA="${TARGET_SHA:0:7}"
BRANCH_SLUG="$(echo "${BRANCH_NAME}" | tr '/_.' '-' | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9-]+//g; s/^-+|-+$//g')"
# A DNS label is at most 63 characters: past that the preview host is not this slug, so wait for the bot comment's URL instead.
DEPLOY_URL=""
if [[ ${#BRANCH_SLUG} -le 63 ]]; then DEPLOY_URL="https://${BRANCH_SLUG}.getartcraft.dev"; fi
echo "Awaiting Cloudflare deploy preview for PR #${PR_NUMBER} (branch ${BRANCH_NAME}, commit ${TARGET_SHA})..."
else
TARGET_SHA="$COMMIT_SHA"
SHORT_SHA="${TARGET_SHA:0:7}"
DEPLOY_URL="https://getartcraft.com"
echo "Testing the production deployment of ${TARGET_SHA} at ${DEPLOY_URL}..."
fi
FAILURE_GRACE_SECONDS=120
failure_started_at=""
for i in {1..90}; do
# For PRs, extract the preview URL directly from the Cloudflare bot comment if present for this commit
if [[ "$EVENT_NAME" == "pull_request" ]]; then
CF_URL=$(gh api --paginate "repos/${REPO}/issues/${PR_NUMBER}/comments?per_page=100" 2>/dev/null | jq -rs --arg sha "$SHORT_SHA" '
[ .[][] |
select(.user.login == "cloudflare-workers-and-pages[bot]") |
select(.body | contains("(commit " + $sha + ")")) |
.body |
capture("Preview URL:\\s*(?<urls>[^\\n\\r]+)")? |
.urls |
[scan("https://[a-zA-Z0-9.-]+\\.(?:getartcraft\\.dev|workers\\.dev)")] |
.[]
] | (map(select(contains("getartcraft.dev"))) | first) // first // empty
' 2>/dev/null || true)
if [[ -n "$CF_URL" ]]; then
DEPLOY_URL="$CF_URL"
fi
fi
# Check Workers Builds check run status on this commit
# Every page, the exact "Workers Builds: artcraft-services" run first, then any other Cloudflare build run
CHECK_DATA=$(gh api --paginate "repos/${REPO}/commits/${TARGET_SHA}/check-runs?per_page=100" 2>/dev/null | jq -s '
[.[].check_runs[]] | (map(select(.name == "Workers Builds: artcraft-services")) + map(select(.name | test("^Workers Builds")))) | first // empty
' 2>/dev/null || true)
CHECK_STATUS=$(echo "$CHECK_DATA" | jq -r '.status // empty' 2>/dev/null || true)
CHECK_CONCLUSION=$(echo "$CHECK_DATA" | jq -r '.conclusion // empty' 2>/dev/null || true)
if [[ "$CHECK_CONCLUSION" == "failure" || "$CHECK_CONCLUSION" == "timed_out" || "$CHECK_CONCLUSION" == "cancelled" ]]; then
# Cloudflare may retry a failed build for this commit shortly afterward.
if [[ -z "$failure_started_at" ]]; then
failure_started_at=$SECONDS
echo "Cloudflare reported ${CHECK_CONCLUSION}; allowing ${FAILURE_GRACE_SECONDS}s for a retry..."
fi
if (( SECONDS - failure_started_at >= FAILURE_GRACE_SECONDS )); then
echo "Error: the Cloudflare deploy check still reports ${CHECK_CONCLUSION} after the ${FAILURE_GRACE_SECONDS}s grace period!" >&2
exit 1
fi
elif [[ "$CHECK_STATUS" == "in_progress" || "$CHECK_STATUS" == "queued" || "$CHECK_CONCLUSION" == "success" ]]; then
failure_started_at=""
fi
ready=0
[[ "$CHECK_STATUS" == "completed" && "$CHECK_CONCLUSION" == "success" ]] && ready=1
if [[ "$ready" == "1" ]] && curl -sf -o /dev/null "${DEPLOY_URL}/apt/artcraft.sources" 2>/dev/null; then
echo "Deployment is live and responsive at ${DEPLOY_URL} (attempt $i)!"
echo "Warming up package repository endpoints..."
curl -sf -m 60 -o /dev/null "${DEPLOY_URL}/apt/dists/stable/Release" 2>/dev/null || true
curl -sf -m 60 -o /dev/null "${DEPLOY_URL}/rpm/repodata/repomd.xml" 2>/dev/null || true
curl -sf -m 60 -o /dev/null "${DEPLOY_URL}/arch/x86_64/artcraft.db" 2>/dev/null || true
echo "deploy_url=${DEPLOY_URL}" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Attempt $i/90: waiting for ${DEPLOY_URL} (check: ${CHECK_STATUS:-waiting}/${CHECK_CONCLUSION:-pending})..."
sleep 10
done
echo "Error: timed out waiting for ${DEPLOY_URL} (${TARGET_SHA})" >&2
exit 1
test-distro-tools:
name: ${{ matrix.name }}
needs: wait-for-deploy
if: needs.wait-for-deploy.outputs.deploy-url != ''
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- name: "Ubuntu 26.04 (APT)"
distro: ubuntu
- name: "Debian (APT)"
distro: debian
- name: "Fedora 45 (DNF)"
distro: fedora
- name: "RHEL (DNF)"
distro: rhel
# libzypp rejects hostnames containing "--", so this leg reaches a deploy preview through
# the script's forwarder while every other leg talks to the deployment directly.
- name: "openSUSE Tumbleweed (Zypper)"
distro: opensuse
- name: "Flatpak OCI Remote"
distro: flatpak
- name: "Arch Linux (Pacman)"
distro: arch
defaults:
run:
working-directory: frontend/apps/artcraft-website-next
steps:
- name: Harden runner
uses: step-security/harden-runner@v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7.0.1
- name: Setup Node
uses: actions/setup-node@v7.1.0
with:
node-version: 22
# manifest-info.mjs runs on jiti, so the tests need the dependencies even though the site
# itself comes from the deployment.
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Test OCI signature verification
if: matrix.distro == 'flatpak'
run: node --test scripts/verify-flatpak-signatures.test.mjs
- name: Verify repository via ${{ matrix.name }}
run: ./scripts/test-distro-repos.sh ${{ matrix.distro }} "${{ needs.wait-for-deploy.outputs.deploy-url }}"