Github actions ${{ github.event.release.tag_name }} always null

Viewed 988

I'm trying to deploy my repository to a private Docker registry on every new release and everything works except for the version tagging. No matter what I've tried ${{ github.event.release.tag_name }} is always '', which cancels the workflow since docker tags can't be empty.

on:
  release:
    types: [published]


jobs:
  push_to_registry:
    name: Push Docker image to Docker Registry
    runs-on: ubuntu-latest
    steps:
      - 
        name: Check out the repo
        uses: actions/checkout@v2
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - 
        name: Setup Docker Buildx
        uses: docker/setup-buildx-action@v1
      - 
        name: Log in to Docker Registry
        uses: docker/login-action@v1
        with:
          registry: ${{ secrets.DOCKER_REGISTRY }}
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: check tag
        if: ${{ github.event.release.tag_name }} == ''
        run: |
          echo Epic fail
          exit 1
      - 
        name: Build and Push to Docker Registry
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: ${{ secrets.DOCKER_REGISTRY }}/repos:latest, ${{ secrets.DOCKER_REGISTRY }}/$repos:${{ github.event.release.tag_name }}
      - 
        name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}

The repository this is running on is private so that might have something to do with it but I haven't been able to figure out what.

Any suggestions?

1 Answers

I think the problem is that github.event.release.tag_name is only available if the tagging itself triggered the build (but I'm not sure)

I made it work using a separate action: https://github.com/dawidd6/action-get-tag

Here's my usage:

steps:
  - uses: actions/checkout@v2
  - name: Get git tag
    id: tag
    uses: dawidd6/action-get-tag@v1
  - uses: docker/build-push-action@v2
    with:
      context: ./
      file: ./Dockerfile
      push: true
      tags: locustio/locust:${{ steps.tag.outputs.tag }}
Related