Gitea 1.27.3 expires a run's logs and artifacts but never the run record itself, so the Actions list grows without limit and fills with entries whose logs are already gone. Clearing it meant 455 API calls from a scratch file on one machine, which is the wrong home for something that has to happen again every few weeks. Dry run unless apply is typed as true. The operation cannot be undone and there is no confirmation once it starts, so the harmless answer has to be the default rather than the one you get by leaving a box alone. Manual only, deliberately. The list is an annoyance rather than a problem, and a cron that quietly deletes history deserves to be a decision taken on its own rather than one that arrives bundled with the tool. A run that is not completed is never a candidate, which is also what stops the cleanup deleting the run it is executing in. Ages a run by started_at, falling back to completed_at. That fallback is the whole reason this is worth committing rather than repeating from memory: a run cancelled before it ever started reports an epoch started_at while carrying a real completed_at, so reading only the first makes every cancelled run look undateable. The manual pass did exactly that and left nineteen runs from three weeks earlier in a list that was supposed to hold seven days. Neither timestamp usable still means keep — an epoch read as 1969 would delete the runs that have not happened yet. Uses a dedicated ACTIONS_CLEANUP_TOKEN secret rather than the automatic per-job token, since deleting a run may be beyond what that token permits. If it turns out to be enough, the secret and the env line both go. Host and repository come from the run's own context, so the file carries no hostname and survives the move #313 may yet make. No npm install: the script uses node's own https module, so there is nothing to fetch and nothing to break when a dependency moves. Verified by running the script against the live instance: a dry run reported 19 stale cancelled runs the earlier pass had missed, and applying it removed them with no failures. Closes #324 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
54 lines
2.0 KiB
YAML
54 lines
2.0 KiB
YAML
name: Clean up old workflow runs
|
|
|
|
# Manual only, and dry run by default (#324).
|
|
#
|
|
# Gitea 1.27.3 expires a run's logs and artifacts but never the run record
|
|
# itself, so the Actions list grows without limit and fills with entries whose
|
|
# logs are already gone. This removes those entries.
|
|
#
|
|
# Deliberately not on a schedule. Deleting a run cannot be undone, the list is
|
|
# an annoyance rather than a problem, and a cron that quietly removes history
|
|
# should be a decision taken on its own rather than the default that arrives
|
|
# with the tool.
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
keep_days:
|
|
description: 'Keep runs newer than this many days'
|
|
required: false
|
|
default: '7'
|
|
apply:
|
|
description: 'Type true to actually delete. Anything else reports only.'
|
|
required: false
|
|
default: 'false'
|
|
|
|
jobs:
|
|
cleanup:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
# No npm install: the script uses only node's own https module, so there
|
|
# is nothing to fetch and nothing that can break when a dependency moves.
|
|
- name: Delete old runs
|
|
env:
|
|
# A dedicated secret rather than the automatic per-job token, because
|
|
# deleting a run may be beyond what that token is allowed to do. If it
|
|
# turns out to be sufficient, this and the secret can both go.
|
|
GITEA_ACCESS_TOKEN: ${{ secrets.ACTIONS_CLEANUP_TOKEN }}
|
|
# Taken from the run's own context so this file carries no hostname
|
|
# and works unchanged if the instance ever moves — which #313 may yet
|
|
# make happen.
|
|
GITEA_HOST: ${{ github.server_url }}
|
|
GITEA_REPO: ${{ github.repository }}
|
|
KEEP_DAYS: ${{ github.event.inputs.keep_days }}
|
|
APPLY: ${{ github.event.inputs.apply }}
|
|
run: node scripts/cleanup-workflow-runs.js
|