# Copyright 2024 Defense Unicorns
# SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial

name: Test

on:
  # This workflow is triggered on pull requests to the main branch.
  pull_request:
    # milestoned is added here as a way to retrigger workflows that are stuck or otherwise didn't run correctly
    types: [milestoned, opened, reopened, synchronize]
    paths-ignore:
      - "**.md"
      - "**.jpg"
      - "**.png"
      - "**.gif"
      - "**.svg"
      - adr/**
      - docs/**
      - .gitignore
      - renovate.json
      - releaser.yaml
      - CODEOWNERS
      - LICENSE
      - CONTRIBUTING.md
      - SECURITY.md

# Permissions for the GITHUB_TOKEN used by the workflow.
permissions:
  contents: read # Allows reading the content of the repository.
  packages: read # Allows reading the content of the repository's packages.
  id-token: write

# Abort prior jobs in the same workflow / PR
concurrency:
  group: test-${{ github.ref }}
  cancel-in-progress: true

jobs:
  check-flavor:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: test-flavor
        uses: defenseunicorns/uds-common/.github/actions/test-flavor@f922776396f05f743055f2751fe19ec0160968ae # v1.7.3
        id: test-flavor
    outputs:
      upgrade-flavors: ${{ steps.test-flavor.outputs.upgrade-flavors }}

  validate:
    needs: check-flavor
    strategy:
      fail-fast: true
      matrix:
        type: [install, upgrade]
        flavor: [upstream, registry1, unicorn]
    uses: defenseunicorns/uds-common/.github/workflows/callable-test.yaml@f922776396f05f743055f2751fe19ec0160968ae # v1.7.3
    with:
      upgrade-flavors: ${{ needs.check-flavor.outputs.upgrade-flavors }}
      flavor: ${{ matrix.flavor }}
      type: ${{ matrix.type }}
      runsOn: uds-swf-ubuntu-big-boy-4-core
    secrets: inherit # Inherits all secrets from the parent workflow.