name: Docker Publish Release Multiarch

on:
  workflow_dispatch:
  release:
    types: [released]


permissions:
  contents: read


jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: oprypin/find-latest-tag@v1
        with:
          repository: Forceu/Gokapi 
          releases-only: true 
          prefix: 'v'
        id: latestversion

      - name: checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: install buildx
        id: buildx
        uses: crazy-max/ghaction-docker-buildx@v1
        with:
          version: latest
      - name: login to docker hub
        run: echo "${{ secrets.DOCKER_PW }}" | docker login -u "${{ secrets.DOCKER_USER }}" --password-stdin
      - name: build the image
        run: |
          docker buildx build --tag f0rc3/gokapi:latest --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 .
      - name: push the image
        run: |
          docker buildx build --push --tag f0rc3/gokapi:latest --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 .
          docker buildx build --push --tag f0rc3/gokapi:${{ steps.latestversion.outputs.tag }} --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 .
