-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alexandr Demicev <[email protected]>
- Loading branch information
1 parent
e535531
commit a625ece
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Cleanup e2e images | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
workflow_dispatch: | ||
|
||
env: | ||
ORG: rancher | ||
REPO: turtles | ||
PACKAGE: turtles-e2e | ||
|
||
jobs: | ||
delete_old_versions: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run delete old versions script | ||
run: ./scripts/cleanup-test-images.sh ${{ env.ORG }} ${{ env.REPO }} ${{ env.PACKAGE }} ${{ secrets.GITHUB_TOKEN }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -ne 4 ]; then | ||
echo "Usage: $0 <org> <repo> <package-name> <github-token>" | ||
exit 1 | ||
fi | ||
|
||
ORG="$1" | ||
REPO="$2" | ||
PACKAGE_NAME="$3" | ||
GITHUB_TOKEN="$4" | ||
|
||
API_URL="https://api.github.com/orgs/$ORG/packages/container/$PACKAGE_NAME/versions?per_page=100" | ||
|
||
CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
|
||
response=$(curl -L \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"$API_URL") | ||
|
||
echo "$response" | jq -r \ | ||
--arg current_date "$CURRENT_DATE" \ | ||
'map(select(.created_at < $current_date)) | .[] | .id' | while read version_id; do | ||
echo "Deleting version: $version_id" | ||
curl -s -X DELETE \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"https://api.github.com/orgs/$ORG/packages/container/$PACKAGE_NAME/versions/$version_id" | ||
done | ||
|
||
echo "Deletion process complete." |