name: docker-gorgone-testing

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

on:
  workflow_dispatch:
  push:
    branches:
      - develop
      - dev-[2-9][0-9].[0-9][0-9].x
    paths:
      - ".version"
      - ".github/docker/gorgone/**"
      - ".github/workflows/docker-gorgone-testing.yml"
  pull_request:
    paths:
      - ".version"
      - ".github/docker/gorgone/**"
      - ".github/workflows/docker-gorgone-testing.yml"

jobs:
  dependency-scan:
    uses: centreon/security-tools/.github/workflows/dependency-analysis.yml@main

  get-environment:
    needs: [dependency-scan]
    if: github.repository == 'centreon/centreon-collect'
    uses: ./.github/workflows/get-environment.yml

  dockerize:
    needs: [get-environment]
    if: |
      needs.get-environment.outputs.skip_workflow == 'false' &&
      needs.get-environment.outputs.stability != 'stable' &&
      github.repository == 'centreon/centreon-collect'
    runs-on: ubuntu-24.04

    strategy:
      fail-fast: false
      matrix:
        distrib: [alma8, alma9, bookworm] # No ubuntu in 24.10, 24.11 or later for now
    steps:
      - name: Checkout sources
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

      - name: Login to registry
        uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
        with:
          registry: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}
          username: ${{ secrets.HARBOR_CENTREON_PUSH_USERNAME }}
          password: ${{ secrets.HARBOR_CENTREON_PUSH_TOKEN }}

      - name: Login to proxy registry
        uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
        with:
          registry: ${{ vars.DOCKER_PROXY_REGISTRY_URL }}
          username: ${{ secrets.HARBOR_CENTREON_PUSH_USERNAME }}
          password: ${{ secrets.HARBOR_CENTREON_PUSH_TOKEN }}

      - uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

      - uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
        with:
          file: .github/docker/gorgone/${{ matrix.distrib }}/Dockerfile.testing-dependencies
          context: .
          build-args: |
            "VERSION=${{ needs.get-environment.outputs.major_version }}"
            "IS_CLOUD=${{ needs.get-environment.outputs.is_cloud }}"
            "NODE_VERSION=24"
            "PNPM_VERSION=10.24.0"
          pull: true
          push: true
          tags: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/gorgone-testing-dependencies-${{ matrix.distrib }}:${{ needs.get-environment.outputs.stability == 'unstable' && needs.get-environment.outputs.major_version || github.head_ref || github.ref_name }}
          secrets: |
            "ARTIFACTORY_INTERNAL_REPO_USERNAME=${{ secrets.ARTIFACTORY_INTERNAL_REPO_USERNAME }}"
            "ARTIFACTORY_INTERNAL_REPO_PASSWORD=${{ secrets.ARTIFACTORY_INTERNAL_REPO_PASSWORD }}"

  set-skip-label:
    needs: [get-environment, dockerize]
    if: |
      needs.get-environment.outputs.skip_workflow == 'false' &&
      ! cancelled() &&
      ! contains(needs.*.result, 'failure') &&
      ! contains(needs.*.result, 'cancelled')
    uses: ./.github/workflows/set-pull-request-skip-label.yml
