Allow existence of protected and immutable rules with the same pattern
Context
Related to https://docs.gitlab.com/user/packages/container_registry/immutable_container_tags/.
Problem
Currently it's not possible to create a container registry tag immutable rule with a pattern that's already being used for a tag protected rule (and vice versa).
If attempting to do so we get the following error:
There is no technical reason to not allow both to exist. As explained in the linked user docs, these two types of rules are complementary and evaluated in sequence.
Workaround
The current workaround is to provide a slightly different pattern that targets the same tags. For example, if one has a protected pattern of ^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$ to match SemVer tags, they could use the following variations for the corresponding immutable rule:
- Optional end anchor (no-op):
^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$? - Simplify pattern slightly:
^v?\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$
(1) should work with any regex pattern that ends with $. Alternatively, adding ^? at the beginning if it starts with ^ should also be a universal option.
