name: deploy

on:
  push:
    tags:
      - '*'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Set env
      run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v3

    - name: Login to DockerHub
      uses: docker/login-action@v3
      with:
        username: ${{ secrets.DOCKER_USER }}
        password: ${{ secrets.DOCKER_PASSWORD }}

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

    - name: Build and release on dockerhub
      uses: docker/build-push-action@v6
      with:
        file: support/build.Dockerfile
        push: true
        platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
        tags: pldubouilh/gossa:latest,pldubouilh/gossa:${{github.ref_name}}

    - name: Build all artifacts
      run: make build-all

    - name: "Release gh release versioned"
      uses: ncipollo/release-action@v1
      with:
        allowUpdates: true
        artifacts: "builds/*"
        bodyFile: "builds/buildout"
        token: ${{ secrets.GITHUB_TOKEN }}

    - name: "Release gh release latest"
      uses: ncipollo/release-action@v1
      with:
        tag: latest
        name: Latest
        allowUpdates: true
        artifacts: "builds/*"
        bodyFile: "builds/buildout"
        token: ${{ secrets.GITHUB_TOKEN }}
