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 e1e54cf
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion .github/workflows/delete-old-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ env:

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
- All Packages

jobs:
delete-old:
Expand All @@ -19,6 +34,34 @@ 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;
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 @@ -42,7 +85,9 @@ jobs:
});
for (version of response.data) {
console.log(version)
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 (version.metadata.container.tags.length == 0) {
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions/" + version.id, { });
Expand Down

0 comments on commit e1e54cf

Please sign in to comment.