#### THIS IS A TEMPLATE ####
# This workflow is created to be a template for every time an e2e test is required,

on:
  workflow_call:
    inputs:
      name:
        required: true
        type: string
      platforms-test:
        type: string
        default: linux/amd64
      platforms-publish:
        type: string
        default: linux/amd64

env:
  PLATFORMS: ${{ inputs.platforms-test }}

permissions:
  contents: write
  packages: write

jobs:
  changestag:
    permissions:
      contents: read  # for dorny/paths-filter to fetch a list of changed files
    runs-on: ubuntu-latest
    outputs:
      tag: ${{ steps.filter.outputs.tag }}

    steps:
      - name: Checkout
        uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
        id: filter
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          filters: |
            tag:
              - 'images/**/TAG'

  image-build:
    name: Build
    runs-on: ubuntu-latest
    permissions:
      contents: read

    steps:
      - name: Checkout
        uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

      - name: Build
        run: |
          cd images/ && make NAME=${{ inputs.name }} build

  image-push:
    name: Push
    needs: changestag
    if: |
      (github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'kubernetes/ingress-nginx' && needs.changestag.outputs.tag == 'true')
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write
    env:
      PLATFORMS: ${{ inputs.platforms-publish }}
    steps:
    - name: Checkout
      uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

    - name: Login to GitHub Container Registry
      uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}

    - name: Push
      run: |
          cd images/ && make REGISTRY=ingressnginx NAME=${{ inputs.name }} push

