Skip to content

🧹 Prune Actions Storage #2

🧹 Prune Actions Storage

🧹 Prune Actions Storage #2

name: 🧹 Prune Workflow Runs
# Deletes stale GitHub Actions run history on a weekly cadence:
# - runs older than the retention window for workflows still present on the
# default branch, and
# - ALL runs for workflows whose source is gone from the default branch.
# See scripts/fleet/prune-workflow-runs.mts. Byte-identical across the fleet
# (cascaded); edit template/base/.github/workflows/prune-workflow-runs.yml and
# re-cascade via `pnpm run sync`.
on:
schedule:
# Sundays at 04:00 UTC — off-peak, clear of the daily/weekly update runs.
- cron: '0 4 * * 0'
workflow_dispatch:
inputs:
days:
description: 'Retention window in days for present workflows'
required: false
type: string
default: '15'
dry-run:
description: 'Report what would be deleted without deleting'
required: false
type: boolean
default: false
permissions:
actions: write
contents: read
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
prune:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
# First step can't call the local ./.github/actions/fleet/checkout
# composite (nothing checked out yet); bootstrap the workspace with the
# same inline git-fetch shape at fetch-depth 1, non-persisting auth.
- name: Bootstrap checkout
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
TRIGGER_REF: ${{ github.ref }}
run: |
set -euo pipefail
git init -q
git config --local advice.detachedHead false
git remote remove origin 2>/dev/null || true
git remote add origin "${SERVER_URL}/${REPOSITORY}"
FETCH_ARGS=(--no-tags --prune --depth 1 origin "${TRIGGER_REF}")
if [ -n "${GITHUB_TOKEN}" ]; then
AUTH_B64="$(printf 'x-access-token:%s' "${GITHUB_TOKEN}" | base64 | tr -d '\n')"
git -c "http.${SERVER_URL}/.extraheader=AUTHORIZATION: basic ${AUTH_B64}" fetch "${FETCH_ARGS[@]}"
else
git fetch "${FETCH_ARGS[@]}"
fi
git checkout -q --detach FETCH_HEAD
- uses: ./.github/actions/fleet/setup-and-install
- name: Prune workflow runs
env:
GH_TOKEN: ${{ github.token }}
DAYS: ${{ inputs.days || '15' }}
DRY_RUN: ${{ inputs.dry-run }}
run: |
ARGS=(--days "$DAYS")
if [ "$DRY_RUN" = "true" ]; then
ARGS+=(--dry-run)
fi
node scripts/fleet/prune-workflow-runs.mts "${ARGS[@]}"