cpu and gpu #2
This file contains hidden or 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
name: "Prune old GHCR images" | |
on: | |
# 1) Run daily at 02:00 UTC | |
schedule: | |
- cron: '0 2 * * *' | |
# 2) Also run on every push to main (or your default branch) | |
push: | |
branches: | |
- docker | |
permissions: | |
contents: read # for listing versions | |
packages: write # for deleting package versions | |
jobs: | |
prune: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install jq and GitHub CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ | |
| sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] \ | |
https://cli.github.com/packages stable main" \ | |
| sudo tee /etc/apt/sources.list.d/github-cli.list | |
sudo apt-get update | |
sudo apt-get install -y gh | |
- name: Delete non-latest versions | |
env: | |
OWNER: ${{ github.repository_owner }} | |
IMAGE: deep-learning-crash-course | |
run: | | |
gh api -H "Accept: application/vnd.github.v3+json" \ | |
/users/$OWNER/packages/container/$IMAGE/versions \ | |
| jq -c '.[]' \ | |
| while read version; do | |
id=$(echo "$version" | jq -r '.id') | |
tags=$(echo "$version" | jq -r '.metadata.container.tags[]') | |
if [[ ! " $tags " =~ " latest " ]]; then | |
echo "Deleting version $id (tags: $tags)" | |
gh api -X DELETE \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
/users/$OWNER/packages/container/$IMAGE/versions/$id | |
fi | |
done |