marketplace CI coveralls github docker

ghaction-version-gen

ghaction-version-gen is a docker github action that outputs a version number for you to use in a deploy action.

There are many ways to generate version information for a repository. They usually involve processing GITHUB_REF in some way, maybe using even using github-script.

This repository is also an example of how to create a docker github action that compiles a rust entrypoint in a container and then moves it to a second, minimal container.

Outputs

The following are the primary outputs of this action, usually the ones used for versioning:

You can these variables in action in the Examples section.

This github action is also able to check if a project-specific version matches with the latest tags. At the moment, only rust's Cargo.toml file is checked. If there's a mismatch and a new tag is being pushed, the action fails.

Secondary outputs

These are the secondary outputs that might be useful for debugging or as alternative versioning schemes:

Examples

version_tagged and version_commit

Using version_tagged and version_commit is quite simple:

yml jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - id: version uses: docker://lpenz/ghaction-version-gen:0.13.4 ... - name: deploy uses: <deploy action> if: steps.version.outputs.version_tagged != '' with: version: ${{ steps.version.outputs.version_tagged }}

That gets the deploy step to run only when a tag is pushed, and sets version to the tag with the optional v prefix stripped.

If we replace version_tagged with version_commit in the example above, we get an additional behavior: version_commit is also defined when main or master are pushed, and it assumes the value of the last tag (v stripped) suffixed with - and the distance of the pushed commit to that tag. This should be used in projects that want to deploy every time main is pushed.

version_docker_ci

The version_docker_ci variable was designed to work with the docker's [build-push-action]. It should be used in projects where we would use want to deploy from tags and from main/master, but we want main/master to be identified as latest in docker hub.

This is how it's used:

yml jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - id: version uses: docker://lpenz/ghaction-version-gen:0.13.4 - uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - uses: docker/build-push-action@v2 with: push: ${{ steps.version.outputs.version_docker_ci != 'null' }} tags: ${{ github.repository }}:${{ steps.version.outputs.version_docker_ci }}

Note that we don't make the [build-push-action] step conditional because we always want to build the container. Instead, we make push conditional, by checking that version_docker_ci is not null. We use null instead of the empty string as a workaround, because the action doesn't let us use an empty string as the version in tags.