GitHunt
JL

jlxip/docker-semver

Build and push Docker image with Semantic Versioning 2.0.0 tags

docker-semver

About

This is a very simple GitHub action to build and push Docker images. It's based on docker/build-push-action, with the only difference that the tags must follow Semantic Versioning 2.0.0. When a tag is pushed on the GitHub repository, let's say 1.4.1, docker/build-push-action is called, uploading to the hub the following tags, all pointing to the same image:

  • 1.4.1
  • 1.4
  • 1
  • latest

This way, users can always pull to user/yourimage:1 and be able to update it while knowing that no backwards-incompatible changes will be made.

Note: when pushing 1.5.1-rc1, it will NOT push 1.5.1, but it will push 1.5 and 1. Note that due to Docker limitations, metadata (1.5.1+build1) cannot be used as a version.

Use in the lines of:

name: Publish
on:
  create:
    tags:
      - '*'
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: jlxip/docker-semver@1
        with:
          context: .
          image: user/yourimage
          version: ${{ github.ref_name }}

Languages

Shell100.0%

Contributors

GNU General Public License v3.0
Created November 28, 2022
Updated June 26, 2025