constellation/.github/workflows/purge-main.yml
renovate[bot] 0a190c2bf6
deps: update GitHub action dependencies (#1499)
Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
2023-03-22 17:57:47 +01:00

92 lines
2.5 KiB
YAML

name: Purge old images from main branch
on:
workflow_dispatch:
schedule:
- cron: "0 0/3 * * *"
- cron: "0 1/3 * * *"
- cron: "0 2/3 * * *"
jobs:
find-version:
name: Delete version from main ref
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.find.outputs.version }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0
with:
ref: ${{ github.head_ref }}
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef # v2.0.0
with:
role-to-assume: arn:aws:iam::795746500882:role/GithubConstellationVersionsAPIRead
aws-region: eu-central-1
- name: Determine stream
id: stream
run: |
case "${{ github.event.schedule }}" in
"0 0/3 * * *")
echo "stream=debug" >> "$GITHUB_OUTPUT"
;;
"0 1/3 * * *")
echo "stream=console" >> "$GITHUB_OUTPUT"
;;
"0 2/3 * * *")
echo "stream=nightly" >> "$GITHUB_OUTPUT"
;;
*)
echo "Unknown schedule: ${{ github.event.schedule }}"
exit 1
;;
esac
- name: List versions
id: list
uses: ./.github/actions/versionsapi
with:
command: list
ref: main
stream: ${{ steps.stream.outputs.stream }}
- name: Find version to delete
id: find
shell: bash
run: |
versions=$(cat versionsapi_output.txt)
echo "Found versions:"
echo "${versions}"
echo "Newest 10 versions shouldn't be deleted"
deletable=$(echo "${versions}" | head -n -10)
if [[ -z "${deletable}" ]]; then
echo "No deletable versions found"
exit 0
fi
echo "Found deletable versions:"
echo "${deletable}"
ver=$(echo "${deletable}" | head -n 1)
echo "Deleting oldest version: ${ver}"
echo "version=${ver}" >> "$GITHUB_OUTPUT"
delete:
name: Delete version
if: needs.find-version.outputs.version != ''
permissions:
id-token: write
contents: read
uses: ./.github/workflows/versionsapi.yml
needs: find-version
secrets: inherit
with:
command: remove
dryrun: true
version_path: ${{ needs.find-version.outputs.version }}