name: Publish Docker image
on:
  release:
    types: [published]
jobs:
  docker_publish:
    name: Push Docker image to Github Hub
    runs-on: ubuntu-latest
    steps:
      - name: Get the version
        id: vars
        run: |
          echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7})
          echo ::set-output name=tag::$(echo ${GITHUB_REF#refs/tags/})
      - name: Docker Login to Registry
        run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u vulcanize --password-stdin
      - name: Docker Pull
        run: docker pull ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.sha}}
      - name: Tag docker image
        run: docker tag ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.sha}} ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.tag}}
      - name: Docker Push to Github Hub
        run: docker push ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.tag}}
