Merge pull request 'chore(ci): remove old releases from forgejo-integration' (#4920) from earl-warren/forgejo:wip-integration-cleanup into forgejo
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-remote-cacher (map[image:docker.io/valkey/valkey:7.2.5-alpine3.19 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:ghcr.io/microsoft/garnet-alpine:1.0.14 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:redis:7.2 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:registry.redict.io/redict:7.3.0-scratch port:6379]) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4920
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-08-10 13:18:08 +00:00
commit a83f5cd0f0

View file

@ -0,0 +1,40 @@
on:
workflow_dispatch:
schedule:
- cron: '@daily'
jobs:
integration-cleanup:
if: vars.ROLE == 'forgejo-integration'
runs-on: docker
container:
image: 'code.forgejo.org/oci/node:20-bookworm'
steps:
- name: apt install curl jq
run: |
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get -q install -qq -y curl jq
- name: remove old releases and tags
run: |
url=https://any:${{ secrets.TOKEN }}@codeberg.org
curl -sS "$url/api/v1/repos/forgejo-integration/forgejo/releases" | jq -r '.[] | "\(.published_at) \(.tag_name)"' | sort | while read published_at version ; do
if echo $version | grep -e '-test$' >/dev/null; then
old="18 months"
else
old="1 day"
fi
too_old=$(env -i date --date="- $old" +%F)
too_old_seconds=$(env -i date --date="- $old" +%s)
published_at_seconds=$(env -i date --date="$published_at" +%s)
if test $published_at_seconds -le $too_old_seconds ; then
echo "$version was published more than $old ago ($published_at <= $too_old) and will be removed"
curl -X DELETE -sS "$url/api/v1/repos/forgejo-integration/forgejo/releases/tags/$version"
curl -X DELETE -sS "$url/api/v1/repos/forgejo-integration/forgejo/tags/$version"
else
echo "$version was published less than $old ago"
fi
done