name: Postgres w/Healthcheck

permissions:
  contents: read
  packages: write

on:
  workflow_call:
  workflow_dispatch:
  push:
    branches:
      - main
  schedule:
    - cron: "0 14 * * 2" # 2pm Patch Tuesday

concurrency:
  group: ${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  postgres-build:
    name: "Build"
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        version:
          - latest
          - 16
          - 16.2
          - 16.1
          - "16.0"
          - 15
          - 15.6
          - 15.5
          - 15.4
          - 15.3
          - 15.2
          - 15.1
          - "15.0"
          - 14
          - 14.11
          - 14.10
          - 14.9
          - 14.8
          - 14.7
          - 14.6
          - 14.5
          - 14.4
          - 14.3
          - 14.2
          - 14.1
          - "14.0"
          - 13
          - 13.14
          - 12
          - 12.18
        alpine:
          - "-alpine"
          - ""
        exclude:
          - version: latest
            alpine: "-alpine"
    steps:
      - uses: actions/checkout@v4

      - uses: docker/setup-qemu-action@v3

      - uses: docker/setup-buildx-action@v3

      - name: "Setup: Login to Docker Hub"
        uses: docker/login-action@v3
        with:
          username: matthewbaggett
          password: ${{ secrets.DOCKER_HUB_TOKEN }}

      - name: "Setup: Login to GHCR"
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: matthewbaggett
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: "Setup: Docker meta"
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: |
            benzine/postgres
            ghcr.io/benzine-framework/postgres
          labels: |
            org.opencontainers.image.title=Postgres ${{ matrix.version }}${{ matrix.alpine }} w/healthcheck
            org.opencontainers.image.description=Postgres ${{ matrix.version }} with Healthcheck
            org.opencontainers.image.vendor=Matthew Baggett <matthew@baggett.me>
          tags: |
            type=raw,value=${{ matrix.version }}${{ matrix.alpine }},enable=true

      - name: "Docker: Build & Push"
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: ${{ env.ACT && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
          pull: true
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          annotations: ${{ steps.meta.outputs.annotations }}
          build-contexts: |
            postgres:injected-version=docker-image://postgres:${{ matrix.version }}${{ matrix.alpine }}