I am Mita, Your Housekeeper #659
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
name: I am Mita, Your Housekeeper # 家政婦のミタ | |
on: | |
schedule: | |
- cron: '0 23 * * TUE' # Runs at 08:00 Tokyo time every Wednesday ⌚ | |
- cron: '0 23 27 * *' # Runs at 08:00 Tokyo time on day-of-month 28 🗓️ | |
workflow_dispatch: | |
inputs: | |
prune_tags: | |
description: 'Prune old releases' | |
type: boolean | |
default: false | |
prune_pkgs: | |
description: 'Prune untagged packages' | |
type: boolean | |
default: false | |
jobs: | |
prune_old_releases: | |
if: github.event.schedule == '0 23 * * TUE' || github.event.inputs.prune_tags == 'true' | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Prune old releases | |
run: ./util/prunetags.sh | |
env: | |
GH_TOKEN: ${{ github.token }} | |
prune_untagged_pkgs: | |
if: github.event.schedule == '0 23 27 * *' || github.event.inputs.prune_pkgs == 'true' | |
runs-on: ubuntu-24.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
image_name: [fedora,base-win64,win64-nonfree] | |
steps: | |
- name: Prune untagged pkgs | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.dodosolsollalasol }} | |
script: | | |
// list package versions | |
const list_package_versions = await github.request(`GET /user/packages/container/${{ matrix.image_name }}/versions`, { | |
per_page: 100 | |
}); | |
// get only the versions with no tags | |
const versions_to_prune = list_package_versions.data.filter(version => version.metadata.container.tags.length === 0); | |
// get the ids of the versions to prune | |
const ids_to_prune = versions_to_prune.map(version => version.id); | |
// delete all the versions in parallel | |
const prune_results = await Promise.all(ids_to_prune.map(id => { | |
return github.request(`DELETE /user/packages/container/${{ matrix.image_name }}/versions/${id}`) | |
.then(result => { | |
return `✂️ prune ${id} ${result.status === 204 ? "🎉 success" : "❌ failure"}`; | |
}); | |
})); | |
prune_results.forEach(message => console.log(message)); |