Skip to content

Conversation

@NikitaCOEUR
Copy link
Contributor

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:

  • Added a new preserve-tags-filter input 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].
  • Updated the workflow to pass the preserve-tags-filter input through to the action, ensuring the filter is available during execution [1] [2] [3].
  • Modified the action's implementation (index.js) to accept and handle the new preserveTagsFilter parameter, filtering out tags that match the preserve filter before deletion [1] [2] [3] [4].

@github-actions
Copy link
Contributor

Hi, thank you for creating your PR, we will check it out very soon

Copy link

Copilot AI left a 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-filter input 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.

Comment on lines 131 to 137
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));
Copy link

Copilot AI Jan 30, 2026

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.

Suggested change
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;
}
});

Copilot uses AI. Check for mistakes.
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants