name: push-hugo-support

on:
  workflow_dispatch:

  push:
    branches:
    - main
    paths:
    - Dockerfile
    - netlify.toml

jobs:
  hugo-support:
    runs-on: ubuntu-latest
    needs: hugo-image
    steps:
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      -
        name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_FLUXCD_USER }}
          password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
      -
        name: Checkout repo
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
      -
        name: Set repo_owner variable
        run: make --silent print-repo-owner >> $GITHUB_ENV
      -
        name: Set hugo_version variable
        run: make --silent print-hugo-version >> $GITHUB_ENV
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: linux/amd64,linux/arm64
          push: true
          builder: ${{ steps.buildx.outputs.name }}
          build-args: |
            HUGO_VERSION=${{ env.hugo_version }}
          tags: ${{ env.repo_owner }}/website:hugo-support

  hugo-image:
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      -
        name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_FLUXCD_USER }}
          password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
      -
        name: Checkout repo
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
      -
        name: Set repo_owner variable
        run: make --silent print-repo-owner >> $GITHUB_ENV
      -
        name: Set hugo_version variable
        run: make --silent print-hugo-version >> $GITHUB_ENV
      -
        name: Clone hugo repo
        run: make hugo
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v5
        with:
          context: hugo
          platforms: linux/amd64,linux/arm64
          push: true
          builder: ${{ steps.buildx.outputs.name }}
          build-args: |
            HUGO_VERSION=${{ env.hugo_version }}
            HUGO_BUILD_TAGS=extended
          tags: ${{ env.repo_owner }}/website:hugo-${{ env.hugo_version }}-extended
