2023-01-16 04:09:55 -05:00
|
|
|
name: Purge old images from main branch
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
schedule:
|
2023-01-16 10:05:59 -05:00
|
|
|
- cron: "0 0/3 * * *"
|
2023-01-16 08:48:42 -05:00
|
|
|
- cron: "0 1/3 * * *"
|
|
|
|
- cron: "0 2/3 * * *"
|
2023-01-16 04:09:55 -05:00
|
|
|
|
|
|
|
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
|
2023-12-20 10:10:35 -05:00
|
|
|
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
2023-01-16 04:09:55 -05:00
|
|
|
with:
|
|
|
|
ref: ${{ github.head_ref }}
|
|
|
|
|
|
|
|
- name: Login to AWS
|
2024-02-21 09:29:06 -05:00
|
|
|
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
|
2023-01-16 04:09:55 -05:00
|
|
|
with:
|
|
|
|
role-to-assume: arn:aws:iam::795746500882:role/GithubConstellationVersionsAPIRead
|
|
|
|
aws-region: eu-central-1
|
|
|
|
|
2023-01-16 08:48:42 -05:00
|
|
|
- name: Determine stream
|
|
|
|
id: stream
|
|
|
|
run: |
|
|
|
|
case "${{ github.event.schedule }}" in
|
|
|
|
"0 0/3 * * *")
|
2023-04-14 12:25:53 -04:00
|
|
|
echo "stream=debug" | tee -a "$GITHUB_OUTPUT"
|
2023-01-16 08:48:42 -05:00
|
|
|
;;
|
|
|
|
"0 1/3 * * *")
|
2023-04-14 12:25:53 -04:00
|
|
|
echo "stream=console" | tee -a "$GITHUB_OUTPUT"
|
2023-01-16 08:48:42 -05:00
|
|
|
;;
|
|
|
|
"0 2/3 * * *")
|
2023-04-14 12:25:53 -04:00
|
|
|
echo "stream=nightly" | tee -a "$GITHUB_OUTPUT"
|
2023-01-16 08:48:42 -05:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown schedule: ${{ github.event.schedule }}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2023-01-16 04:09:55 -05:00
|
|
|
- name: List versions
|
|
|
|
id: list
|
|
|
|
uses: ./.github/actions/versionsapi
|
|
|
|
with:
|
|
|
|
command: list
|
|
|
|
ref: main
|
2023-01-16 08:48:42 -05:00
|
|
|
stream: ${{ steps.stream.outputs.stream }}
|
2023-01-16 04:09:55 -05:00
|
|
|
|
|
|
|
- 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)
|
2023-03-16 12:07:06 -04:00
|
|
|
if [[ -z "${deletable}" ]]; then
|
2023-01-16 04:09:55 -05:00
|
|
|
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}"
|
2023-04-14 12:25:53 -04:00
|
|
|
echo "version=${ver}" | tee -a "$GITHUB_OUTPUT"
|
2023-01-16 04:09:55 -05:00
|
|
|
|
|
|
|
delete:
|
|
|
|
name: Delete version
|
|
|
|
if: needs.find-version.outputs.version != ''
|
2023-01-31 08:30:36 -05:00
|
|
|
permissions:
|
|
|
|
id-token: write
|
|
|
|
contents: read
|
2023-01-16 04:09:55 -05:00
|
|
|
uses: ./.github/workflows/versionsapi.yml
|
|
|
|
needs: find-version
|
|
|
|
secrets: inherit
|
|
|
|
with:
|
|
|
|
command: remove
|
|
|
|
version_path: ${{ needs.find-version.outputs.version }}
|