name: Docker Images CI
on:
  push:
    branches: main

jobs:
  buildx:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Cache Docker layers
        uses: actions/cache@v4
        id: cache
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-
      -
        name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: linux/arm/v7,linux/amd64
          push: true
          tags: albertoxamin/bang:latest
          cache-from: type=registry,ref=user/app:latest
          cache-to: type=inline

      - name: Notify discord
        uses: th0th/notify-discord@v0.4.1
        if: ${{ always() }}
        env:
          DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
          GITHUB_ACTOR: ${{ github.actor }}
          GITHUB_JOB_NAME: "Docker image main :latest"
          GITHUB_JOB_STATUS: ${{ job.status }}
