codemagic-docs icon indicating copy to clipboard operation
codemagic-docs copied to clipboard

Missing details about syntax for tags and branch patterns

Open tsimbalar opened this issue 2 years ago • 1 comments

As per discussion in Slack : https://codemagicio.slack.com/archives/CEKE2KZ37/p1649930771811679

In the documentation, there are some examples of using patterns to specify the name of tags or branches that trigger a workflow, for instance : https://docs.codemagic.io/yaml/yaml-getting-started/#triggering

Unfortunately the examples are quite "basic" , and are either:

  • a particular branch/tag
  • or a wildcard *

The assumption is that this is some sort of glob syntax, but as it's not really standardized, it's hard to know which features of glob are supported or not.

When we need to filter a bit more finely, this becomes a bit hard.

Naively, I assumed I'd be able to use a pattern like v+([0-9]).+([0-9]).+([0-9]) , to include tags with a name like v{1 or more number}.{1 or more number}.{1 or more number} ... but this doesn't work.

As a workaround, I ended up with combining inclusion and exclusion filters

      tag_patterns:
        # build for tags that look like `vX.X.X`
        - pattern: "v*.*.*"
          include: true
        # but ignore if there is a `-` somewhere (for instance `v2.1.3-rc`)
        - pattern: "*-*"
          include: false

but this doesn't quite express the real goal here.

Could we have more details about what level of glob support is available ?

Thanks !

tsimbalar avatar Apr 14 '22 13:04 tsimbalar

Thanks @tsimbalar. This is actually an issue for me right now. I'm not sure how to make my tag triggers work.

I use semantic versioning for tags (e.g. v1.2.0-rc.1 for release candidate versions and v1.2.0 for release versions). I then trigger a build for beta when a release candidate is tagged or I trigger a prod build when a release version is tagged

I'm not sure how to filter for release candidate version and release version tags

It would be helpful if there were more examples

HemlockBane avatar Oct 15 '22 14:10 HemlockBane

I'm having a similar problem.

I have a 2 workflows. One for prod builds and one for QA builds. I’m trying to setup a proper triggering ruleset to start builds. Basically what I want to do is,

  1. When a tag in the format of v1.0.0-prod is created, the prod workflow would run.
  2. When a tag in the format of v1.0.0-qa is created, the QA workflow would run.

I added the below to my codemagic.yaml file.

triggering:
      events:
        - tag
      branch_patterns:
        - pattern: "master"
        - include: true
          source: true
      tag_patterns:
        - pattern: "v*.*.*-prod"
        - include: true

But in my tests, I’ve found that, if I create the tags in basically any format (some samples below), still the build would trigger!

v1.0.0.1-prod - with an extra digit. v1.0.1-test - undefined name at the end. new-tag - completely different than the pattern defined in codemagic.yaml

Not sure how to restrict the triggers to only conform to my exact vX.X.X-prod format.

Isuru-Nanayakkara avatar Nov 19 '22 06:11 Isuru-Nanayakkara

i would also like to have more infos about how those patterns work if they are not regex compliant. I had a major f%ck up because of a wrong branch name ended up in an ugly release version name in Apple Connect which i cant even delete on Apple site.

logemann avatar Nov 19 '22 14:11 logemann

We use fnmatch module for pattern matching. Regex obviously is much richer, supporting repetitions, and (in ERE) alternation and specific numbers of repetitions.

K-Codemagic avatar Jan 03 '23 08:01 K-Codemagic

@Isuru-Nanayakkara Seems the configuration is incorrect in your yaml:

triggering:
      events:
        - tag
      branch_patterns:
        - pattern: "master"
        - include: true
          source: true
      tag_patterns:
        - pattern: "v*.*.*-prod"
        - include: true

Instead it should be as follows:

triggering:
      events:
        - tag
      branch_patterns:   
        - pattern: 'master'
          include: true
          source: true
      tag_patterns:         
        - pattern: 'v*.*.*-prod'
          include: true

K-Codemagic avatar Jan 03 '23 08:01 K-Codemagic

Hi all, thanks for the feedback! We've now switched to a library that allows defining more advanced patterns for matching branch and tag names.

helinanever avatar Jan 17 '23 14:01 helinanever