name: Publish image # Build and push the Docker image to the GitHub Container Registry # (ghcr.io) on version tags only. on: push: tags: - 'v*' env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: publish: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract image metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # v1.2.3 -> 1.2.3, 1.2, 1 ; plus a moving `latest` for the newest tag. tags: | type=semver,pattern={{version}} # A fix to release 1.2.3 is tagged v1.2.3.1: four numbers are not semver, so # the pattern above makes no tag for it; this one does (image tag 1.2.3.1). type=match,pattern=v(\d+\.\d+\.\d+\.\d+),group=1 type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=raw,value=latest - name: Build and push uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max