From 661985a4d417f80d74e634596315fb39f951ece8 Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Tue, 19 Nov 2024 15:23:52 +0100 Subject: [PATCH] Remove old release --- .github/scripts/find-version.js | 1 + .github/scripts/remove-packages.js | 16 +++++++------ .github/workflows/code-quality.yml | 36 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.github/scripts/find-version.js b/.github/scripts/find-version.js index f549771c..fc2186bd 100644 --- a/.github/scripts/find-version.js +++ b/.github/scripts/find-version.js @@ -10,6 +10,7 @@ const findNextVersion = (tags, branch) => { if (version.preRelease == null || version.patch !== 0) { version.minor += 1; version.patch = 0; + version.preRelease = null; } } else { // It's a patch. diff --git a/.github/scripts/remove-packages.js b/.github/scripts/remove-packages.js index c4896bc7..73204691 100644 --- a/.github/scripts/remove-packages.js +++ b/.github/scripts/remove-packages.js @@ -8,12 +8,13 @@ const removePackageVersions = async (imageUrl, imageVersions) => { const [_imageHost, imageOwner, imageName] = imageUrl.split("/"); const imageIds = await loadOutdatedVersionIds(octokit, imageOwner, imageName, imageVersions); for (const imageId of imageIds) { - await octokit.rest.packages.deletePackageVersionForOrg({ - package_type: "container", - package_name: imageName, - org: imageOwner, - package_version_id: imageId, - }); + console.log("Delete", { imageUrl, imageId, imageVersions }); + // await octokit.rest.packages.deletePackageVersionForOrg({ + // package_type: "container", + // package_name: imageName, + // org: imageOwner, + // package_version_id: imageId, + // }); } }; @@ -23,6 +24,7 @@ const loadOutdatedVersionIds = async (octokit, imageOwner, imageName, versions) const ids = new Set(); while (true) { + console.log("Delete", { imageName, imageOwner }); const response = await octokit.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({ package_type: "container", package_name: imageName, @@ -37,7 +39,7 @@ const loadOutdatedVersionIds = async (octokit, imageOwner, imageName, versions) // as well as any ids that do not have a tag anymore, i.e. are fully unused. const { tags } = entry.metadata.container; const matchedTags = tags.filter((tag) => versions.delete(tag)); - if (tags.length === 0 || matchedTags.length !== 0) { + if (matchedTags.length !== 0) { ids.add(entry.id); } } diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index a7c6800a..f6982106 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -7,6 +7,8 @@ on: - "**" - "!main" +permissions: write-all + env: NODE_VERSION: "22.x" DB_USERNAME: postgres @@ -15,6 +17,40 @@ env: DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?schema=public jobs: + cleanup: + name: "cleanup" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup node + run: | + npm install @octokit/rest + - name: Remove outdated versions + uses: actions/github-script@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BASE_IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }} + CURRENT_VERSION: ${{ needs.determine_version.outputs.version }} + TAGS: ${{ steps.get_tags.outputs.tags }} + with: + script: | + const { findOutdatedVersions, makeVersionTag } = require('./.github/scripts/find-version.js'); + const { removePackageVersions } = require('./.github/scripts/remove-packages.js'); + + await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-api`, [{ + major: 1, + minor: 7, + patch: 0, + preRelease: 5, + }].map(makeVersionTag)); + await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-app`, [{ + major: 1, + minor: 7, + patch: 0, + preRelease: 5, + }].map(makeVersionTag)); + dependency-review: runs-on: ubuntu-latest steps: