firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.28k stars 128 forks source link

Changed rule regex and got exception #1162

Closed david-nano closed 6 months ago

david-nano commented 6 months ago

Minimal .gitlab-ci.yml illustrating the issue The rule I have in my job is: (before changes)

  if: $CI_COMMIT_MESSAGE =~ /^(BREAKING CHANGES|(feat|fix)(\([\w\-]+\))?!?):/ && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"
  when: on_success

Changed it to:

  if: $CI_COMMIT_MESSAGE =~ /^(?i)(BREAKING CHANGES|(feat|fix)(\([\w\-]+\))?!?):/ && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"
  when: on_success

Expected behavior Keep running local CI as before.

Current behavior Got this error:

SyntaxError: Invalid regular expression: /^(?i)(BREAKING CHANGES|(feat|fix)(\([\w\-]+\))?!?):/: Invalid group
    at Function.evaluateRuleIf (/snapshot/firecow-gitlab-ci-local/src/utils.ts:221:28)
    at Function.getRulesResult (/snapshot/firecow-gitlab-ci-local/src/utils.ts:182:23)
    at new Job (/snapshot/firecow-gitlab-ci-local/src/job.ts:186:38)
    at /snapshot/firecow-gitlab-ci-local/src/parser.ts:155:29
    at Function.forEachRealJob (/snapshot/firecow-gitlab-ci-local/src/utils.ts:52:13)
    at Parser.init (/snapshot/firecow-gitlab-ci-local/src/parser.ts:143:15)
    at Function.create (/snapshot/firecow-gitlab-ci-local/src/parser.ts:60:9)
    at handler (/snapshot/firecow-gitlab-ci-local/src/handler.ts:96:18)
    at Object.handler (/snapshot/firecow-gitlab-ci-local/src/index.ts:33:21)

Host information Ubuntu 22.04 gitlab-ci-local 4.47.0

Containerd binary Docker

Additional context I just want to ignore the case for "Fix" or "fix" when the user is committing to my job using this rule.

ANGkeith commented 6 months ago

https://github.com/firecow/gitlab-ci-local/issues/932#issuecomment-1653301250 Introducing of re2 might fix this issue.

currently, we do not support (?i)

while waiting for the fix,

instead of: if: $CI_COMMIT_MESSAGE =~ /^(?i)(BREAKING CHANGES|(feat|fix)(\([\w\-]+\))?!?):/

use: if: $CI_COMMIT_MESSAGE =~ /^(BREAKING CHANGES|(feat|fix)(\([\w\-]+\))?!?):/i

with this, you should be able to continue using gitlab-ci-local while still having the case insensitive match

firecow commented 6 months ago

We have an issue on supporting re2 regex https://github.com/firecow/gitlab-ci-local/issues/932