name: release image & asset

on:
 push:
   tags:
      - "v*"

jobs:
  package:
    runs-on: ubuntu-latest
    steps:
    - name: Golang env
      uses: actions/setup-go@v2
      with:
        go-version: ^1.15
    - name: Checkout
      uses: actions/checkout@v2
    - name: Cache mod
      uses: actions/cache@v1
      with:
        path: ~/go/pkg/mod
        key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
        restore-keys: |
          ${{ runner.os }}-go-
    - name: Docker tag
      id: vars
      run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
    - name: Set up QEMU
      uses: docker/setup-qemu-action@v1
    - name: Docker Buildx
      uses: docker/setup-buildx-action@v1
    - name: Docker login
      uses: docker/login-action@v1
      with:
        password: ${{ secrets.DOCKER_PASSWORD }}
        username: ${{ secrets.DOCKER_USERNAME }}
    - name: Build image
      env:
        GOPROXY: https://goproxy.io,direct
      run: scripts/run_build.sh deepzz0 ${{ steps.vars.outputs.tag }}

    - name: Package tar
      env:
        GOPROXY: https://goproxy.io,direct
      run: scripts/dist_tar.sh ${{ steps.vars.outputs.tag }}
    - name: Release push
      uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        files: |
          *.tar.gz
