-
Notifications
You must be signed in to change notification settings - Fork 1
feat(prune-pull-requests-images-tags): add preserve-tags-filter #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(prune-pull-requests-images-tags): add preserve-tags-filter #653
Conversation
|
Hi, thank you for creating your PR, we will check it out very soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a preserve-tags-filter feature to the pull request image tag pruning workflow, allowing users to specify a regular expression pattern for tags that should not be deleted during automated cleanup operations.
Changes:
- Added a new
preserve-tags-filterinput parameter to the workflow, action, and implementation - Enhanced tag filtering logic to exclude tags matching the preserve pattern from deletion
- Updated documentation in action.yml to describe the new parameter and its usage
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
.github/workflows/prune-pull-requests-images-tags.yml |
Added preserve-tags-filter input parameter definition and pass-through to the action |
actions/docker/prune-pull-requests-image-tags/action.yml |
Added preserve-tags-filter input with description and passed it to the index.js script |
actions/docker/prune-pull-requests-image-tags/index.js |
Implemented preserve filter logic to filter out matching tags before deletion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const preservedTags = tags.filter((tag) => tag.match(preserveTagsFilter)); | ||
| if (preservedTags.length > 0) { | ||
| core.debug( | ||
| `Preserving tags matching filter ${preserveTagsFilter}: ${preservedTags.join(", ")}`, | ||
| ); | ||
| } | ||
| return tags.filter((tag) => !tag.match(preserveTagsFilter)); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preserve filter regex is not validated before use. Consider adding validation similar to the pull-request-tag-filter validation (lines 65-79 in action.yml) to ensure the regex pattern is valid. An invalid regex pattern would cause the match() calls to throw an error at runtime. Additionally, consider wrapping the match() operations in try-catch blocks to handle potential regex errors gracefully.
| const preservedTags = tags.filter((tag) => tag.match(preserveTagsFilter)); | |
| if (preservedTags.length > 0) { | |
| core.debug( | |
| `Preserving tags matching filter ${preserveTagsFilter}: ${preservedTags.join(", ")}`, | |
| ); | |
| } | |
| return tags.filter((tag) => !tag.match(preserveTagsFilter)); | |
| let preserveRegex; | |
| try { | |
| preserveRegex = new RegExp(preserveTagsFilter); | |
| } catch (error) { | |
| core.warning( | |
| `Invalid preserve tag filter regex "${preserveTagsFilter}". Skipping preserve filter. Error: ${error.message}`, | |
| ); | |
| // If the regex is invalid, do not attempt to match; return all tags unchanged. | |
| return tags; | |
| } | |
| const preservedTags = tags.filter((tag) => { | |
| try { | |
| return preserveRegex.test(tag); | |
| } catch (error) { | |
| core.warning( | |
| `Error while applying preserve tag filter regex "${preserveTagsFilter}" to tag "${tag}". Treating tag as not preserved. Error: ${error.message}`, | |
| ); | |
| return false; | |
| } | |
| }); | |
| if (preservedTags.length > 0) { | |
| core.debug( | |
| `Preserving tags matching filter ${preserveTagsFilter}: ${preservedTags.join(", ")}`, | |
| ); | |
| } | |
| return tags.filter((tag) => { | |
| try { | |
| return !preserveRegex.test(tag); | |
| } catch (error) { | |
| core.warning( | |
| `Error while applying preserve tag filter regex "${preserveTagsFilter}" to tag "${tag}". Keeping tag. Error: ${error.message}`, | |
| ); | |
| return true; | |
| } | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better, use core.setFailed if an error occured
…ion and error handling Addresses PR review comments by adding robust regex validation and error handling: - Extract preserve filter logic into dedicated filterPreservedTags function - Validate preserve filter regex before use with try-catch - Use core.setFailed for invalid regex patterns - Handle regex matching errors gracefully with appropriate warnings - Improve code modularity and maintainability
This pull request introduces an enhancement to the Docker image tag pruning workflow and action by adding support for preserving specific tags based on a user-defined regular expression filter. This allows teams to ensure that important tags (like version tags) are not deleted during automated cleanup of pull request image tags.
Enhancements to tag pruning logic:
preserve-tags-filterinput to both the workflow (.github/workflows/prune-pull-requests-images-tags.yml) and the reusable action (actions/docker/prune-pull-requests-image-tags/action.yml), allowing users to specify a regular expression for tags that should never be deleted [1] [2].preserve-tags-filterinput through to the action, ensuring the filter is available during execution [1] [2] [3].index.js) to accept and handle the newpreserveTagsFilterparameter, filtering out tags that match the preserve filter before deletion [1] [2] [3] [4].