Skip to content

Commit

Permalink
Add inputs to workflow [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Aug 7, 2023
1 parent 6988fc2 commit b3e871e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/clear-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ jobs:
with:
script: |
console.log("About to clear")
const caches = await github.rest.actions.getActionsCacheList({
const response = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
page: 1,
per_page: 1
})
for (const cache of caches.data.actions_caches) {
const pages = (function() {
if (typeof response.headers.link !== 'undefined') {
return response.headers.link.split(">").slice(-2)[0].split('=').slice(-1)[0]
}
return 1;
})();
console.log(pages)
console.log(response)
for (const cache of response.data.actions_caches) {
console.log(cache)
github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
Expand Down
67 changes: 62 additions & 5 deletions .github/workflows/delete-old-images.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
name: Delete Older Than
name: Delete Old Packages

env:
PER_PAGE: 100

on:
workflow_dispatch:
inputs:
age:
type: choice
required: true
description: Delete older than
options:
- 1 Hour
- 12 Hours
- 1 Day
- 1 Week
- 2 Weeks
- 1 Month
- 6 Months
- 1 Year
- 2 Years
- 3 Years
- 4 Years
- 5 Years
- All Packages

jobs:
delete-old:
delete-old-packages:
runs-on: ubuntu-latest
steps:
-
Expand All @@ -19,6 +38,42 @@ jobs:
with:
github-token: ${{ secrets.DELETE_PACKAGES_TOKEN }}
script: |
const delete_age = (function() {
switch ("${{ github.event.inputs.age }}") {
case "All Packages":
return 0;
case "1 Hour":
return 60;
case "12 Hours":
return 720;
case "1 Day":
return 1440;
case "1 Week":
return 10080;
case "2 Weeks":
return 20160;
case "1 Month":
return 43800;
case "6 Months":
return 262800;
case "1 Year":
return 525600;
case "2 Years":
return 525600 * 2;
case "3 Years":
return 525600 * 3;
case "4 Years":
return 525600 * 4;
case "5 Years":
return 525600 * 5;
default:
return 157680000;
}
})();
const now = new Date();
const epoch_minutes = Math.round(now.getTime() / 1000 / 60);
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
Expand All @@ -41,13 +96,15 @@ jobs:
page: page
});
console.log("Deleting packages updated more than " + delete_age + " minutes ago...")
for (version of response.data) {
console.log(version)
if (version.metadata.container.tags.length == 0) {
let updated_at = new Date(version.updated_at)
let minutes_old = epoch_minutes - Math.round(updated_at.getTime() / 1000 / 60);
console.log("Package is " + minutes_old + " minutes old")
if (minutes_old > delete_age) {
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/delete-untagged-images.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Delete Untagged
name: Delete Untagged Packages

env:
PER_PAGE: 100
Expand Down

0 comments on commit b3e871e

Please sign in to comment.