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

Still not tagging versions, despite auto_tags:true #11

Closed
adrienjoly opened this issue Mar 28, 2020 · 7 comments
Closed

Still not tagging versions, despite auto_tags:true #11

adrienjoly opened this issue Mar 28, 2020 · 7 comments

Comments

@adrienjoly
Copy link

adrienjoly commented Mar 28, 2020

Hi!

First of all, thanks for this action, we've been using it for months to publish Openwhyd on Docker Hub!

We enabled auto_tags:true in the GitHub workflow that runs semantic-release and publish-docker-action, but we still don't see new tags (others than latest) on our Docker hub page, despite the fact that our CI logs shows that semantic-release did create a new tag before running publish-docker-action with auto_tags:true.

Did we forget anything in our configuration? (openwhyd/openwhyd@dca5597, introduced in openwhyd/openwhyd#306)

Thanks in advance for your help!

Adrien
Openwhyd

@jerray
Copy link
Owner

jerray commented Mar 29, 2020

Please make sure your workflow is listening push events for tags.
You should add tags pattern in your workflow file nodejs.yml:

name: CI

on:
  push:
    branches:
      - master
    tags:
      - *
  pull_request:
    branches:
      - master

@adrienjoly
Copy link
Author

Thanks for your reply!

In my current configuration, tags are created in the same workflow as the one running publish-docker-action.

If I add tags to the list of events that this workflows responds to, does that mean that it will take two consecutive executions of that workflow for publish-docker-action to actually deploy that tag to docker hub? (the first to generate the tag, and the second to deploy using that tag)

Or am I missing anything?

@jerray
Copy link
Owner

jerray commented Mar 30, 2020

Yes, you're right. If you add tags to the event list, after Semantic Release step finishes, it will start another workflow.

The auto_tags depends on current git reference GITHUB_REF. In your case, the workflow only listens push event on master branch, GITHUB_REF environment variable is always refs/heads/master. It results this action only generating latest tag.

If you add tags to the list of events, after pushing a tag to the repository, GitHub starts another workflow with environment variable GITHUB_REF=refs/tags/vX.Y.Z. Now, this action will generate docker tags as you expected. But I think you will want to skip Semantic Release step in this situation. Just add if: !startsWith(github.ref, 'refs/tags/') to that step.

I suggest switch actions/checkout version to v2. It provides more specific git information than v1.

@adrienjoly
Copy link
Author

Thanks for the explanation!

Ideally, I'd love to publish the docker image of each version with two tags: latest and the version number (a.k.a. the GitHub release tag) => is it possible to do both in one shot, to save some time and resources?

@jerray
Copy link
Owner

jerray commented Apr 1, 2020

There is a simple solution for it. You can add another step before this action to generate tag list for it.

I don't know much about the semantic-release command, but I guess it creates a new git tag. After that, you can execute a shell command git tag -l --sort=-v:refname | head -1 to get the new tag (vX.Y.Z). If you don't want the prefix v exists in docker image tag, pipe the result to cut -c 2- to remove prefix. Here we can get the version number X.Y.Z. Prepend or append latest to it with delimiter ,. We get latest,X.Y.Z.

Now the only question is how to assign this result to publish-docker-action's tags argument. You can use action output to pass values between steps. For more information, please visit Workflow commands for GitHub Actions.

Here's an example for you.

- id: create_docker_tags
  run: |
    echo "::set-output name=tags::latest,$(git tag -l --sort=-v:refname | head -1 | cut -c 2-)"

- uses: jerray/publish-docker-action@v1.0.3
  with:
    username: ${{ secrets.DOCKER_USERNAME }}
    password: ${{ secrets.DOCKER_PASSWORD }}
    tags: ${{ steps.create_docker_tags.outputs.tags }}

@adrienjoly
Copy link
Author

Thanks for the awesome suggestion, jerray! I'm trying that in openwhyd/openwhyd#320 🤞

adrienjoly added a commit to openwhyd/openwhyd that referenced this issue Apr 5, 2020
adrienjoly pushed a commit to openwhyd/openwhyd that referenced this issue Apr 5, 2020
## [1.34.1](v1.34.0...v1.34.1) (2020-04-05)

### Bug Fixes

* **release:** attempt to publish tags on docker hub ([#320](#320)) ([bc64ec0](bc64ec0)), closes [#306](#306) [/github.com/jerray/publish-docker-action/issues/11#issuecomment-607077257](https://github.com//github.com/jerray/publish-docker-action/issues/11/issues/issuecomment-607077257)
@adrienjoly
Copy link
Author

It worked! 🎉

image

Thank you so much, you rock! 💪

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

No branches or pull requests

2 participants