cpu and gpu #4
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: | |
schedule: | |
- cron: '0 2 * * *' # daily at 02:00 UTC | |
push: | |
branches: [ docker ] | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
prune: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install dependencies | |
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 > /dev/null | |
sudo apt-get update | |
sudo apt-get install -y gh | |
- name: Delete all but the newest version | |
env: | |
OWNER: ${{ github.repository_owner }} | |
IMAGE: deep-learning-crash-course | |
run: | | |
echo "Fetching all versions of $OWNER/$IMAGE..." | |
versions=$(gh api --paginate -H "Accept: application/vnd.github.v3+json" \ | |
/orgs/$OWNER/packages/container/$IMAGE/versions) | |
# find the newest by creation timestamp | |
newest_id=$(echo "$versions" \ | |
| jq -r 'sort_by(.created_at) | reverse | .[0].id') | |
echo "🛡 Keeping version $newest_id (most recent)" | |
# loop through all and delete those that aren't the newest | |
echo "$versions" | jq -c '.[]' | while read ver; do | |
id=$(echo "$ver" | jq -r '.id') | |
if [ "$id" != "$newest_id" ]; then | |
echo "Deleting version $id" | |
gh api -X DELETE \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
/orgs/$OWNER/packages/container/$IMAGE/versions/$id | |
fi | |
done | |