Skip to content

Commit b5f7860

Browse files
committed
revert and add image pruning
1 parent 24e9de8 commit b5f7860

3 files changed

Lines changed: 109 additions & 11 deletions

File tree

.github/workflows/ci_release.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ jobs:
3030
uses: ./.github/workflows/test.yml
3131
secrets: inherit
3232
with:
33-
# Map tags to PR number, main branch, or release tag; skip pushes otherwise.
34-
image-tag: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number)
35-
|| (github.ref == 'refs/heads/main' && 'main')
36-
|| (startsWith(github.ref, 'refs/tags/v') && github.ref_name)
37-
|| 'skip' }}
33+
# tag with the pr in the format of pr-1234 or the tag / branch if it is not a PR.
34+
image-tag: ${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
3835

3936
proto:
4037
uses: ./.github/workflows/proto.yml

.github/workflows/ghcr-prune.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Cleanup workflow for pruning old commit-hash Docker tags from GHCR.
2+
name: GHCR Tag Prune
3+
on:
4+
pull_request:
5+
schedule:
6+
- cron: "0 6 * * *" # daily at 06:00 UTC
7+
workflow_dispatch:
8+
inputs:
9+
retention-days:
10+
description: "Override retention window (days)"
11+
required: false
12+
type: number
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
env:
19+
DEFAULT_RETENTION_DAYS: 14
20+
21+
jobs:
22+
prune:
23+
name: Remove aged commit-hash tags
24+
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
package:
29+
- ev-node
30+
- ev-node-evm-single
31+
- local-da
32+
steps:
33+
- name: Delete stale tags
34+
uses: actions/github-script@v7
35+
env:
36+
PACKAGE_NAME: ${{ matrix.package }}
37+
OVERRIDE_RETENTION: ${{ github.event.inputs.retention-days }}
38+
with:
39+
script: |
40+
const packageName = process.env.PACKAGE_NAME;
41+
if (!packageName) {
42+
core.setFailed('PACKAGE_NAME env not provided');
43+
return;
44+
}
45+
46+
const retentionDaysInput = process.env.OVERRIDE_RETENTION;
47+
const retentionDays = retentionDaysInput ? Number(retentionDaysInput) : Number(process.env.DEFAULT_RETENTION_DAYS);
48+
if (Number.isNaN(retentionDays) || retentionDays <= 0) {
49+
core.setFailed(`Invalid retention window: ${retentionDaysInput}`);
50+
return;
51+
}
52+
const cutoff = Date.now() - retentionDays * 24 * 60 * 60 * 1000;
53+
const owner = context.repo.owner;
54+
const ownerType = context.payload.repository?.owner?.type === 'User' ? 'User' : 'Organization';
55+
56+
core.info(`Processing ${packageName} for ${ownerType.toLowerCase()} ${owner}; removing commit-hash tags older than ${retentionDays} days`);
57+
58+
const listParams = {
59+
package_type: 'container',
60+
package_name: packageName,
61+
per_page: 100,
62+
};
63+
if (ownerType === 'Organization') {
64+
listParams.org = owner;
65+
} else {
66+
listParams.username = owner;
67+
}
68+
69+
const listFn = ownerType === 'Organization'
70+
? github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg
71+
: github.rest.packages.getAllPackageVersionsForPackageOwnedByUser;
72+
73+
const deleteFn = ownerType === 'Organization'
74+
? github.rest.packages.deletePackageVersionForOrg
75+
: github.rest.packages.deletePackageVersionForUser;
76+
77+
const versions = await github.paginate(listFn, listParams);
78+
core.info(`Found ${versions.length} versions`);
79+
80+
const hashRegex = /^[0-9a-f]{40}$/i;
81+
let deleted = 0;
82+
for (const version of versions) {
83+
const created = new Date(version.created_at).getTime();
84+
if (Number.isNaN(created) || created >= cutoff) {
85+
continue;
86+
}
87+
88+
const tags = version.metadata?.container?.tags ?? [];
89+
const hasCommitTag = tags.some(tag => hashRegex.test(tag));
90+
if (!hasCommitTag) {
91+
continue;
92+
}
93+
94+
core.info(`Deleting version ${version.id} (${tags.join(', ')}) created ${version.created_at}`);
95+
await deleteFn({
96+
package_type: 'container',
97+
package_name: packageName,
98+
package_version_id: version.id,
99+
...(ownerType === 'Organization' ? { org: owner } : { username: owner }),
100+
});
101+
deleted += 1;
102+
}
103+
104+
core.info(`Deleted ${deleted} old commit-hash tags for ${packageName}`);

.github/workflows/test.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
build-ev-node-image:
1313
name: Build ev-node Docker Image
1414
# skip building images for merge groups as they are already built on PRs and main
15-
if: github.event_name != 'merge_group' && inputs.image-tag != 'skip'
15+
if: github.event_name != 'merge_group'
1616
runs-on: ubuntu-latest
1717
permissions:
1818
packages: write
@@ -41,7 +41,7 @@ jobs:
4141
build-ev-node-evm-single-image:
4242
name: Build ev-node EVM Single Docker Image
4343
# skip building images for merge groups as they are already built on PRs and main
44-
if: github.event_name != 'merge_group' && inputs.image-tag != 'skip'
44+
if: github.event_name != 'merge_group'
4545
runs-on: ubuntu-latest
4646
permissions:
4747
packages: write
@@ -71,7 +71,7 @@ jobs:
7171
build-local-da-image:
7272
name: Build local-da Docker Image
7373
# skip building images for merge groups as they are already built on PRs and main
74-
if: github.event_name != 'merge_group' && inputs.image-tag != 'skip'
74+
if: github.event_name != 'merge_group'
7575
runs-on: ubuntu-latest
7676
permissions:
7777
packages: write
@@ -100,7 +100,6 @@ jobs:
100100

101101
docker-tests:
102102
name: Docker E2E Tests
103-
if: inputs.image-tag != 'skip'
104103
needs: build-ev-node-image
105104
runs-on: ubuntu-latest
106105
steps:
@@ -117,7 +116,6 @@ jobs:
117116

118117
docker-upgrade-tests:
119118
name: Docker Upgrade E2E Tests
120-
if: inputs.image-tag != 'skip'
121119
needs: build-ev-node-evm-single-image
122120
runs-on: ubuntu-latest
123121
steps:
@@ -132,7 +130,6 @@ jobs:
132130
EVM_SINGLE_IMAGE_REPO: ghcr.io/${{ github.repository_owner }}/ev-node-evm-single
133131
EVM_SINGLE_NODE_IMAGE_TAG: ${{ inputs.image-tag }}
134132

135-
136133
build_all-apps:
137134
name: Build All ev-node Binaries
138135
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)