name: Publish geth to release
on:
  release:
    types: [published]
jobs:
  push_to_registries:
    name: Publish assets to Release
    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 Github Registry
        run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin
      - name: Docker Pull
        run: docker pull docker.pkg.github.com/vulcanize/go-ethereum/go-ethereum:${{steps.vars.outputs.sha}}
      - name: Copy ethereum binary file
        run: docker run --rm --entrypoint cat docker.pkg.github.com/vulcanize/go-ethereum/go-ethereum:${{steps.vars.outputs.sha}} /usr/local/bin/geth > geth-linux-amd64
      - name: Docker Login to Docker Registry
        run: echo ${{ secrets.VULCANIZEJENKINS_PAT }} | docker login -u vulcanizejenkins --password-stdin
      - name: Tag docker image
        run: docker tag docker.pkg.github.com/vulcanize/go-ethereum/go-ethereum:${{steps.vars.outputs.sha}} vulcanize/vdb-geth:${{steps.vars.outputs.tag}}
      - name: Docker Push to Docker Hub
        run: docker push vulcanize/vdb-geth:${{steps.vars.outputs.tag}}
      - name: Get release
        id: get_release
        uses: bruceadams/get-release@v1.2.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Upload Release Asset
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: geth-linux-amd64
          asset_name: geth-linux-amd64
          asset_content_type: application/octet-stream
