Skip to content

Commit 7ef6cdd

Browse files
Copilotneilime
andcommitted
Add schedule event support to get-image-metadata action and fix cleanup errors
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
1 parent c9559e3 commit 7ef6cdd

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

.github/workflows/__test-action-docker-prune-pull-requests-image-tags.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,19 @@ jobs:
225225
github-token: ${{ secrets.GITHUB_TOKEN }}
226226
script: |
227227
const packages = process.env.PACKAGES.split("\n").map(packageName => packageName.trim()).filter(Boolean);
228-
await Promise.all(packages.map(packageName => {
229-
return github.rest.packages.deletePackageForOrg({
230-
package_type: 'container',
231-
package_name: packageName,
232-
org: process.env.GITHUB_REPOSITORY_OWNER,
233-
});
228+
await Promise.all(packages.map(async (packageName) => {
229+
try {
230+
return await github.rest.packages.deletePackageForOrg({
231+
package_type: 'container',
232+
package_name: packageName,
233+
org: process.env.GITHUB_REPOSITORY_OWNER,
234+
});
235+
} catch (error) {
236+
// Ignore 404 errors (package not found)
237+
if (error.status === 404) {
238+
console.log(`Package "${packageName}" not found, skipping deletion`);
239+
return;
240+
}
241+
throw error;
242+
}
234243
}));

actions/docker/get-image-metadata/action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ runs:
8080
8181
// If push on default branch set tag to latest
8282
const isPushOnDefaultBranch = context.eventName === 'push' && `${{ github.ref }}` === `refs/heads/${{ github.event.repository.default_branch }}`;
83-
core.setOutput('flavor', isPushOnDefaultBranch ? 'latest=true' : 'latest=false');
83+
// For schedule events, don't set latest tag to avoid unintended updates
84+
const isSchedule = context.eventName === 'schedule';
85+
core.setOutput('flavor', (isPushOnDefaultBranch && !isSchedule) ? 'latest=true' : 'latest=false');
8486
8587
const isPullRequestOrIssueComment =
8688
context.eventName === 'pull_request'
@@ -102,6 +104,12 @@ runs:
102104
return;
103105
}
104106
107+
// For schedule events, use the default branch name as tag
108+
if(context.eventName === 'schedule') {
109+
core.setOutput('tags', `type=raw,value=${{ github.event.repository.default_branch }}`);
110+
return;
111+
}
112+
105113
core.setFailed(`No tags found for the current event: ${context.eventName}`);
106114
107115
- id: docker-metadata

0 commit comments

Comments
 (0)