Skip to content

Commit

Permalink
Remove old release
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-va committed Nov 19, 2024
1 parent fa572e2 commit 661985a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/scripts/find-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 9 additions & 7 deletions .github/scripts/remove-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
// });
}
};

Expand All @@ -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,
Expand All @@ -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);
}
}
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- "**"
- "!main"

permissions: write-all

env:
NODE_VERSION: "22.x"
DB_USERNAME: postgres
Expand All @@ -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:
Expand Down

0 comments on commit 661985a

Please sign in to comment.