diff --git a/.forgejo/workflows/cleanup.yml b/.forgejo/workflows/cleanup.yml new file mode 100644 index 0000000..48305c8 --- /dev/null +++ b/.forgejo/workflows/cleanup.yml @@ -0,0 +1,56 @@ +on: + workflow_dispatch: + schedule: + - cron: "30 3 * * *" + +jobs: + cleanup-workflow-runs: + runs-on: docker + steps: + - name: Install Packages + run: apt-get update && apt-get install -y curl jq + + - name: Delete workflow runs older than 14 days + env: + TOKEN: ${{ forgejo.token }} + API: ${{ forgejo.api_url }} + REPO: ${{ forgejo.repository }} + CURRENT_RUN_ID: ${{ forgejo.run_id }} + run: | + set -eu + + CUTOFF="$(date -u -d "14 days ago" +"%Y-%m-%dT%H:%M:%SZ")" + PAGE=1 + DELETE_IDS=delete-workflow-runs.txt + + : > "$DELETE_IDS" + + while :; do + curl -fsS \ + -H "Authorization: token $TOKEN" \ + "$API/repos/$REPO/actions/runs?page=$PAGE&limit=50" \ + -o runs.json + + COUNT="$(jq '.workflow_runs | length' runs.json)" + test "$COUNT" -gt 0 || break + + jq -r \ + --arg cutoff "$CUTOFF" \ + --arg current "$CURRENT_RUN_ID" \ + '.workflow_runs[] + | select((.id | tostring) != $current) + | select(["success", "failure", "cancelled", "skipped", "succeeded", "failed"] | index(.status)) + | select(.created < $cutoff) + | .id' runs.json \ + >> "$DELETE_IDS" + + PAGE="$((PAGE + 1))" + done + + while IFS= read -r run_id; do + test -n "$run_id" || continue + echo "Deleting workflow run $run_id" + curl -fsS -X DELETE \ + -H "Authorization: token $TOKEN" \ + "$API/repos/$REPO/actions/runs/$run_id" + done < "$DELETE_IDS" diff --git a/.forgejo/workflows/deploy-prod.yml b/.forgejo/workflows/deploy-prod.yml index ef210bd..6adc499 100644 --- a/.forgejo/workflows/deploy-prod.yml +++ b/.forgejo/workflows/deploy-prod.yml @@ -232,6 +232,46 @@ jobs: -F "attachment=@$file" done + - name: Delete dev releases for prod version + env: + TOKEN: ${{ forgejo.token }} + API: ${{ forgejo.api_url }} + REPO: ${{ forgejo.repository }} + TAG: ${{ steps.version.outputs.tag }} + run: | + set -eu + + PAGE=1 + PREFIX="$TAG-dev-" + DELETE_RELEASES=delete-dev-releases.tsv + + : > "$DELETE_RELEASES" + + while :; do + curl -fsS \ + -H "Authorization: token $TOKEN" \ + "$API/repos/$REPO/releases?page=$PAGE&limit=50&pre-release=true" \ + -o releases.json + + COUNT="$(jq 'length' releases.json)" + test "$COUNT" -gt 0 || break + + jq -r \ + --arg prefix "$PREFIX" \ + '.[] | select(.prerelease == true) | select(.tag_name | startswith($prefix)) | [.id, .tag_name] | @tsv' releases.json \ + >> "$DELETE_RELEASES" + + PAGE="$((PAGE + 1))" + done + + while IFS="$(printf '\t')" read -r release_id release_tag; do + test -n "$release_id" || continue + echo "Deleting dev release $release_tag" + curl -fsS -X DELETE \ + -H "Authorization: token $TOKEN" \ + "$API/repos/$REPO/releases/$release_id" + done < "$DELETE_RELEASES" + - name: Update root flake release hash env: TAG: ${{ steps.version.outputs.tag }} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..58c21e6 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# Information + +All dev releases between two prod version get deleted upon creation of the latest prod release.