name: Build Swarm Connectivity Tester

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

env:
  PLATFORMS: linux/amd64,linux/arm64

jobs:
  swarm-connectivity-tester-build:
    name: Build Swarm Connectivity Tester
    runs-on: ubuntu-latest
    strategy:
      matrix:
        component:
          - target
          - reporter
    steps:
      - uses: benzine-framework/action-setup-php@main
      - uses: benzine-framework/action-get-datetime@main
      - uses: benzine-framework/action-setup-docker@main
        with:
          ghcr_user: matthewbaggett
          ghcr_token: ${{ secrets.GITHUB_TOKEN }}
          docker_hub_user: matthewbaggett
          docker_hub_token: ${{ secrets.DOCKER_HUB_TOKEN }}
      - uses: docker/build-push-action@v5
        with:
          context: .
          target: connect-${{ matrix.component }}
          platforms: ${{ github.actor != 'nektos/act' && env.PLATFORMS || 'linux/amd64' }}
          pull: true
          push: ${{ github.ref == 'refs/heads/main' }}
          tags: |
            benzine/swarm-connectivity-tester:${{ matrix.component }}
            ghcr.io/benzine-framework/swarm-connectivity-tester:${{ matrix.component }}
          cache-from: ${{ env.DOCKER_CACHE_FROM }}
          cache-to: ${{ env.DOCKER_CACHE_TO }}
          build-contexts: |
            php:cli=docker-image://ghcr.io/benzine-framework/php:cli-${{ env.PHP_VERSION }}
            php:nginx=docker-image://ghcr.io/benzine-framework/php:nginx-${{ env.PHP_VERSION }}