prune-dist #59
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# truncate the -dist history every Sunday night, to avoid unbounded growth | |
name: prune-dist | |
on: | |
schedule: | |
- cron: '0 1 * * 0' | |
# can be run manually on https://github.com/cockpit-project/cockpit/actions | |
workflow_dispatch: | |
jobs: | |
run: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: none | |
environment: cockpit-dist | |
env: | |
HEAD_SHA: ${{ github.sha }} | |
DIST_REPO: ssh://[email protected]/${{ github.repository }}-dist.git | |
steps: | |
- name: Delete old tags | |
run: | | |
set -ex | |
eval $(ssh-agent) | |
ssh-add - <<< '${{ secrets.DEPLOY_KEY }}' | |
git clone "${DIST_REPO}" dist-repo | |
cd dist-repo | |
now="$(date +%s)" | |
for tag in $(git tag -l); do | |
tag_time="$(git show -s --format=%at $tag)" | |
if [ "$tag" = "sha-${HEAD_SHA}" ]; then | |
echo "$tag refers to current project default branch HEAD, keeping" | |
elif [ $((now - tag_time)) -ge 604800 ]; then | |
echo "$tag is older than 7 days, deleting..." | |
git push origin ":$tag" | |
else | |
echo "$tag is younger than 7 days, keeping" | |
fi | |
done | |
ssh-add -D | |
ssh-agent -k |