-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const { Octokit } = require("@octokit/rest"); | ||
const dayjs = require("dayjs"); | ||
|
||
async function run() { | ||
const today = dayjs(); | ||
|
||
const client = new Octokit({ | ||
auth: process.env.GITHUB_TOKEN, | ||
}); | ||
|
||
const versions = | ||
await client.packages.getAllPackageVersionsForPackageOwnedByAuthenticatedUser( | ||
{ | ||
package_type: "container", | ||
package_name: "pkmn-tcg-app", | ||
} | ||
); | ||
|
||
let versionsRemoved = 0; | ||
|
||
for (const version of versions.data) { | ||
// delete untagged versions that are older than 7 days | ||
if ( | ||
today.diff(dayjs(version.created_at), "days") > 7 && | ||
version.metadata.container.tags.length === 0 | ||
) { | ||
await client.packages.deletePackageVersionForAuthenticatedUser({ | ||
package_type: "container", | ||
package_name: "pkmn-tcg-app", | ||
package_version_id: version.id, | ||
}); | ||
versionsRemoved++; | ||
} | ||
} | ||
|
||
console.log(`Image versions pruned: ${versionsRemoved}`); | ||
} | ||
|
||
run(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "prune-containers", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"dependencies": { | ||
"@octokit/rest": "^21.0.1", | ||
"dayjs": "^1.11.12" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
on: | ||
push: | ||
branches: | ||
- "main" | ||
name: Docker | ||
jobs: | ||
build: | ||
name: Build Container | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ghcr.io/lannonbr/pokemon-tcg-app:latest | ||
- name: Prune old images | ||
run: | | ||
cd .github/actions/prune-containers | ||
npm install | ||
node index.js | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |