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

New boolean input tag_with_latest #43

Closed
felipecrs opened this issue May 12, 2020 · 8 comments
Closed

New boolean input tag_with_latest #43

felipecrs opened this issue May 12, 2020 · 8 comments

Comments

@felipecrs
Copy link

felipecrs commented May 12, 2020

New boolean input tag_with_latest

It would add the ability for users to better set when to push as latest, such as evaluating an expression for example.

Example: tag as latest when push git tags

- uses: docker/build-push-action@v1
  with:
    username: ${{ secrets.DOCKER_USERNAME }}
    password: ${{ secrets.DOCKER_PASSWORD }}
    repository: felipecassiors/argbash-test
    add_git_labels: true
    # Only push as latest when push a git tag
    tag_with_latest: ${{ startsWith(github.ref, 'refs/tags/') }}
    tag_with_ref: true
    tag_with_sha: true

Usage with tag_with_ref

If tag_with_latest property is defined alongside tag_with_ref, then the strategy of push as latest when the branch is master from tag_with_ref should be ignored.

@felipecrs
Copy link
Author

felipecrs commented May 12, 2020

I think this also fixes #40, since we'd be able to define custom conditions for pushing latest, such as the branch name.

Something like:

tag_with_latest: ${{ github.ref == 'refs/heads/develop' && github.event_name == 'push' }}

@ibnesayeed
Copy link

I usually publish bleeding-edge changes of the master branch with master tag and reserve the latest for when the repo is tagged. This way, people who pull my images without explicit tags can always get something that I explicitly released.

  • on push to a branch
    • build image with the branch name as the image tag
  • on release/repo tag
    • build image with the tag ref as the image tag
    • build image with latest tag

@felipecrs
Copy link
Author

felipecrs commented May 13, 2020

@ibnesayeed yeah, this is also my intended behavior that will be possible with this feature suggestion.

# Use the following if you just push as latest when push git tags
tag_with_latest: ${{ startsWith(github.ref, 'refs/tags/') }} 

@felipecrs
Copy link
Author

felipecrs commented May 13, 2020

Ok, I wrongly thought there was a boolean input called latest already. I rewrote the Issue/Feature Request.

@felipecrs felipecrs changed the title The latest property must take precendence over tag_with_ref New boolean input tag_with_latest May 13, 2020
@hholst80
Copy link

hholst80 commented May 28, 2020

Great workflow suggestion. However isn't this solvable outside this extension? Simply don't run the action unless there is a tag set.

@felipecrs
Copy link
Author

Right, but what to do if we want to run the action in both cases, but only push as latest when is a tag? Without this feature, we would at least have to create 2 (and mainly duplicated) different jobs.

@sagikazarmark
Copy link

I like the idea, personally I was surprised to see that master will also be tagged as latest. As a workaround I have two separate docker steps.

One for the regular CI jobs:

on:
  push:
    branches:
      - master
  pull_request:

#...
      - name: Determine tag
        uses: haya14busa/action-cond@v1
        id: imagetag
        with:
          cond: ${{ github.event_name == 'pull_request' }}
          if_true: ${{ github.sha }}
          if_false: "master"

      - name: Build
        uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: sagikazarmark/myrepo
          tags: ${{ steps.imagetag.outputs.value }}
          add_git_labels: true
          push: ${{ github.event_name == 'push' }}

And one for releases:

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"

jobs:
  docker:
    name: Docker
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Build and push image
        uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: sagikazarmark/myrepo
          tags: latest
          tag_with_ref: true
          add_git_labels: true

@crazy-max
Copy link
Member

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

Successfully merging a pull request may close this issue.

5 participants