Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag chaining with match and semver #56

Open
zero88 opened this issue Apr 1, 2021 · 8 comments · Fixed by #59
Open

Tag chaining with match and semver #56

zero88 opened this issue Apr 1, 2021 · 8 comments · Fixed by #59

Comments

@zero88
Copy link

zero88 commented Apr 1, 2021

Behaviour

My context is kind of mono repository that each project has itself life-cycle.
Currently, I separate GitHub release tag as: project/semver

Steps to reproduce this issue

  1. Input
# Ref context
refs/tags/project1/v1.0.0
# GH docker meta
tags: type=ref,event=branch
  type=ref,event=tag
  type=ref,event=pr
  type=sha
  type=match,pattern=project1\/v(.*),group=1
  1. Output
project1-v1.0.0

It should be 1.0.0 ???

Expected behaviour

I'm wondering how to make tag chaining from match to semver. I have not yet understand prefix/suffix/value for what purpose.
In my case: I expect tag output is

  • 1.0.0
  • 1.0
  • latest

Another thing, typo in https://github.com/crazy-max/ghaction-docker-meta#typematch

tags: |
  type=group,enable=true,priority=800,prefix=,suffix=,pattern=,group=0,value=

Should be type=match?

@crazy-max
Copy link
Member

@zero88

It should be 1.0.0 ???

That's because your pattern is incorrect I guess. What is the value of GITHUB_REF in your pipeline? I would need the link to your repo to know why. I think I will add more logs in this action to enhance the bug reports.

Also you got project1-v1.0.0 because it matches type=ref,event=tag. But again I would need a link to your repo to be sure.

In my case: I expect tag output is
* 1.0.0
* 1.0
* latest

Same as before I would need the link to your repo/workflow to understand what you want and the current behavior.

Should be type=match?

Yes good catch! Feel free to open a PR to fix the README thanks :)

@zero88
Copy link
Author

zero88 commented Apr 2, 2021

My current project is private repo, but I can reproduce in my test project.
I updated github_ref in description also:

# Ref context
refs/tags/project1/v1.0.0

That's because your pattern is incorrect I guess

I don't think my pattern is wrong. I guess your implementation normalizes tag with / then regex matching. I tried both escape \/ and non escape /, still doesn't work

Also you got project1-v1.0.0 because it matches type=ref,event=tag

If I understand your description correctly:

  • type=ref priority = 600 < type=match priority = 800, gh-action handles greater priority first, then it makes a chaining process match -> ref
  • In my case, if I want to transform github tag from refs/tags/project1/v1.0.0 -> 1.0.0, I need provide ghaction input as:
tags: type=ref,event=branch
  type=ref,event=tag
  type=ref,event=pr
  type=sha
  type=semver
  type=match,pattern=project1\/v(.*),group=1,priority=1000

Then I should receive: 1.0.0, 1.0, latest

crazy-max added a commit that referenced this issue Apr 3, 2021
@crazy-max
Copy link
Member

@zero88 I have improved the logging. Can you give me the output of the meta step please?

zero88 added a commit to zero88/gh-test that referenced this issue Apr 5, 2021
zero88 added a commit to zero88/gh-test that referenced this issue Apr 5, 2021
zero88 added a commit to zero88/gh-test that referenced this issue Apr 5, 2021
@zero88
Copy link
Author

zero88 commented Apr 5, 2021

@crazy-max
Please check this one: https://github.com/zero88/gh-test/runs/2267140740?check_suite_focus=true
Compare step project_context (from mine) and docker_context (yours)
It is release workflow.

Other runs seem fine from main to pr: https://github.com/zero88/gh-test/actions/workflows/p1.yml

@crazy-max
Copy link
Member

crazy-max commented Apr 5, 2021

@zero88 I think the following should work:

tags:
  type=match,pattern=p1-v(\d.\d.\d),group=1
  type=match,pattern=p1-v(\d.\d),group=1
  type=ref,event=pr
  type=sha

or

tags:
  type=match,pattern=\d.\d.\d
  type=match,pattern=\d.\d
  type=ref,event=pr
  type=sha

@zero88
Copy link
Author

zero88 commented Apr 6, 2021

@crazy-max Thank you for your response.

After your suggestion, it works.
But, 2 points that make me confusing:

  • Regex pattern

    • / will be escaped to - in prepare step then you do regex matching? So if feature/a/b-c then feature-a-b-c? So it doesn't clear to identify which one is / or -
    • For correcting regex pattern that follow semver(without pre-release/metadata), it should be \d+\.\d+\.\d+ in strict mode. Then 12.1.0 is valid but 1a3.4 is invalid
  • Priority property: it seems not correct usage, or not yet join a processing party as my expectation in above comment.

    type=ref priority = 600 < type=match priority = 800, gh-action handles greater priority first, then it makes a chaining process match -> ref

    I want to release sub project with tag as <sub_project_name>/<sem_ver>
    So, my solution is match is first pattern with highest priority then its output will be input of other follow patterns. Do you consider to include this trick in future? I can contribute if you want, but not today, might be next month :)

Click to expand!
Context info
  eventName: push
  sha: 7bd3423c87f22638de66f435cbe85c496d7c19d8
  ref: refs/tags/p1/v1.1.2
  workflow: build-p1
  action: crazy-maxghaction-docker-meta
  actor: zero88
  runNumber: 18
  runId: 721013978
Processing tags input
  type=match,pattern=p1-v(.*),group=1,priority=1000,value=,enable=true,prefix=,suffix=
  type=semver,pattern={{major}}.{{minor}},value=,enable=true,priority=900,prefix=,suffix=
  type=ref,event=branch,enable=true,priority=600,prefix=,suffix=
  type=ref,event=pr,prefix=pr-,enable=true,priority=600,suffix=
  type=sha,prefix=sha-,enable=true,priority=100,suffix=
Processing flavor input
  latest=auto
  prefix=
  suffix=
Warning: p1-v1.1.2 is not a valid semver. More info: https://semver.org/
Docker image version
  1.1.2
Docker tags
  zero88/p1:1.1.2
  zero88/p1:sha-7bd3423
  zero88/p1:latest

@crazy-max crazy-max reopened this Apr 6, 2021
@crazy-max
Copy link
Member

crazy-max commented Apr 8, 2021

@zero88

  • / will be escaped to - in prepare step then you do regex matching? So if feature/a/b-c then feature-a-b-c? So it doesn't clear to identify which one is / or -

Yes that's it, I think we should check matches before escaping.

  • Priority property: it seems not correct usage, or not yet join a processing party as my expectation in above comment.

priority only allows to manage tags sorting.

  • So, my solution is match is first pattern with highest priority then its output will be input of other follow patterns. Do you consider to include this trick in future? I can contribute if you want, but not today, might be next month :)

We can think about that. Maybe smth like that:

type=match,asref=foo,pattern=p1-v(\d.\d.\d),group=1
type=semver,pattern={{version}},use=foo

@aaronadamsCA
Copy link

Just to help out GitHub issue search: hyphen, dash, slash, path separator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants