name: Docker Image CI (multiarch)
on:
  push:
    branches: [ master ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Get current date
        id: date
        run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"
        
      - name: Check out the repo
        uses: actions/checkout@v2
        
      - name: Prepare-multiarch
        id: prep-multiarch
        run: |
          DOCKER_IMAGE=ghcr.io/${{ github.repository }}
          VERSION=latest
          if [[ '${{ github.head_ref }}' != '' ]]; then
            VERSION=${{github.head_ref}}
          fi
          TAGS="${DOCKER_IMAGE}:${VERSION}-multiarch,${DOCKER_IMAGE}:${{ steps.date.outputs.date }}-multiarch"
          echo ${TAGS}
          echo "tags-multiarch=${TAGS}" >> "$GITHUB_OUTPUT"
      
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
        
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
        
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }} 
          
      - name: Push multiarch to GitHub Packages
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ./.docker/Dockerfile
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          push: true
          tags: ${{ steps.prep-multiarch.outputs.tags-multiarch }}
