Open djettah opened 1 year ago
We must support PCRE, but i don't think we do at the moment :+1:
Something is definitely wrong :smiley:
According to https://docs.gitlab.com/ee/ci/jobs/job_control.html#compare-a-variable-to-a-regex-pattern the regex syntax is called RE2.
Great, we need to utilize this package if possible then. https://www.npmjs.com/package/re2
@firecow I wish I would understood your first comment earlier. After digging into this subject for 3 hours I found out that the image you posted clearly shows that the specific regex mentioned in this issue should work using RegExp
without the need for RE2
or PCRE
. gitlab-ci-local handles the following case perfectly fine:
build-fake:
stage: build
script:
- echo fake build
rules:
- if: $CI_COMMIT_TAG =~ /^(\d+(\.\d+)*|latest)$/
To be clear, yes we should support RE2 to allow things like '/^([[:digit:]]+(\.[[:digit:]]+)*|latest)$/'
which are not supported by JS RegExp
. But, there is another bug that causes the mentioned REGEX expansion to fail:
https://github.com/firecow/gitlab-ci-local/blob/0e442a8a25982246427dacbdbd3bc4088afd7dd6/src/utils.ts#L202
since REGEX is a variable it is replaced with JSON.stringify(envs[name])
which replaces every \
with \\
. So, the evaluated result becomes: "1.11".match(/^(\\d+(\.\\d+)*|latest)$/) != null
instead of "1.11".match(/^(\d+(\.\d+)*|latest)$/) != null
.
Minimal .gitlab-ci.yml illustrating the issue
Expected behavior It should match a job but it doesn't:
Doesn't it support PCRE? GitLab does.
Host information Ubuntu gitlab-ci-local 4.41.2
Additional context Add any other context about the problem here.