name: release image & asset

on:
 push:
   tags:
      - "v*"

jobs:
  package:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v2
      with:
        platforms: linux/amd64,linux/arm64,linux/arm/v7

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v2

    - name: Docker tag
      id: vars
      run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
    - name: Login to Docker Hub
      uses: docker/login-action@v2
      with:
        password: ${{ secrets.DOCKER_PASSWORD }}
        username: ${{ secrets.DOCKER_USERNAME }}

    - name: Build and push eiblog
      uses: docker/build-push-action@v3
      with:
        context: .
        file: ./build/package/eiblog.Dockerfile
        platforms: linux/amd64,linux/arm64,linux/arm/v7
        push: true
        tags: |
          deepzz0/eiblog:${{ steps.vars.outputs.tag }}
          deepzz0/eiblog:latest

    - name: Build and push backup
      uses: docker/build-push-action@v3
      with:
        context: .
        file: ./build/package/backup.Dockerfile
        platforms: linux/amd64,linux/arm64,linux/arm/v7
        push: true
        tags: |
          deepzz0/backup:${{ steps.vars.outputs.tag }}
          deepzz0/backup:latest

    - 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
