name: release-docker-manual
on:
  pull_request:
    types:
      - labeled
    paths:
      - docker/**/Dockerfile
      - scripts/ci/**/*.sh
      - .github/workflows/release.docker.manual.yml

jobs:
  docker-image-debian:
    runs-on: ubuntu-22.04
    environment: docker-publish-manual  
    if: contains(github.event.label.name, 'docker:publish:v2.')
    steps:
      -
        name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      -
        name: Prepare Docker envs
        shell: bash
        run: |
          version=${{ github.event.label.name }}
          semver=${version#*docker:publish:v}
          echo "SEMVER=$semver" >> $GITHUB_ENV
          echo "SEMVER_MAJOR=${semver%.*.*}" >> $GITHUB_ENV
          echo "SEMVER_MINOR=${semver%.*}" >> $GITHUB_ENV
      -
        name: Docker meta debian
        id: meta_debian
        uses: docker/metadata-action@v5
        with:
          images: |
            joseluisq/static-web-server
            ghcr.io/static-web-server/static-web-server
          flavor: |
            latest=false
          tags: |
            type=raw,value=debian
            type=raw,value=${{ env.SEMVER }}-debian
            type=raw,value=${{ env.SEMVER_MAJOR }}-debian
            type=raw,value=${{ env.SEMVER_MINOR }}-debian
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Login to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Login to ghcr.io
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      -
        name: Build and push (debian)
        uses: docker/build-push-action@v6
        with:
          push: true
          context: .
          platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6,linux/ppc64le,linux/s390x
          file: ./docker/debian/Dockerfile
          tags: ${{ steps.meta_debian.outputs.tags }}
          build-args: |
            SERVER_VERSION=${{ env.SEMVER }}
