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

Is there a variable for branch? #60

Closed
ekristen opened this issue Apr 5, 2021 · 4 comments · Fixed by #71
Closed

Is there a variable for branch? #60

ekristen opened this issue Apr 5, 2021 · 4 comments · Fixed by #71

Comments

@ekristen
Copy link

ekristen commented Apr 5, 2021

Is there a way to do the branch name dynamically as the prefix?

type=sha,prefix=${{ branch_name}}-,suffix=,enable=true

Something like that ^

@crazy-max
Copy link
Member

@ekristen

Is there a way to do the branch name dynamically as the prefix?

Not currently but we could support a global Handlebars template on prefix,suffix,value attributes. In the meantime you can do this:

steps:
  -
    name: Prepare
    id: prep
    run: |
      echo ::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
  -
    name: Docker meta
    id: meta
    uses: crazy-max/ghaction-docker-meta@v2
    with:
      images: name/app
      tags: |
        type=sha,prefix=${{ steps.prep.outputs.branch }}-,suffix=,enable=true

@monkbroc
Copy link

monkbroc commented May 3, 2021

I was looking for ${branch}-${sha} as the tag name and instead of settting the branch name as a prefix I ended up setting the SHA as a suffix so the rest of the type=ref,event=branch logic will apply.

      - name: Set short SHA
        id: vars
        run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
      -
        name: Docker meta
        id: meta
        uses: crazy-max/ghaction-docker-meta@v2
        with:
          images: |
            name/app
          tags: |
            type=ref,event=branch,suffix=-${{ steps.vars.outputs.sha_short }}

@crazy-max
Copy link
Member

@ekristen @monkbroc #71 should fix this issue. Can you test with crazy-max/ghaction-docker-meta@global-exp and let me know please? Documentation about global expressions is available here: https://github.com/crazy-max/ghaction-docker-meta/tree/global-exp#global-expressions

@monkbroc
Copy link

monkbroc commented May 7, 2021

Thanks! Yes, I confirm that #71 fixes this issue by using

          tags: |
            type=sha,prefix={{branch}}-

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