name: Build tests

on: [push, pull_request]

env:
  # Minimum versions to build refpolicy.
  PYTHON_VERSION: "3.10"
  SELINUX_USERSPACE_VERSION: "3.2"
  # branch for sechecker
  SECHECKER_VERSION: "4.4"
  # branch for selint
  SELINT_VERSION: "v1.5.0"

jobs:
  lint_branch_policy:
    uses: ./.github/workflows/lint-policy.yml
    with:
      python-version: "3.10"
      selint-version: "v1.5.0"

  build_userspace:
    uses: ./.github/workflows/build-userspace.yml
    # depend on lint so expensive operations don't run if lint fails
    needs: lint_branch_policy
    with:
      version: "3.2"

  build_setools:
    uses: ./.github/workflows/build-setools.yml
    needs: build_userspace
    with:
      version: "4.4"
      python-version: "3.10"

  build_branch_policy:
    uses: ./.github/workflows/build-policy.yml
    needs: build_userspace
    with:
      # Minimum versions to build refpolicy.
      python-version: "3.10"

  validate_branch_policy:
    uses: ./.github/workflows/validate-policy.yml
    needs: [build_branch_policy, build_setools, build_userspace]
    with:
      python-version: "3.10"

  build_PRtarget_policy:
    uses: ./.github/workflows/build-policy.yml
    needs: build_userspace
    if: ${{ github.event_name == 'pull_request' }}
    with:
      version: ${{ github.base_ref }}
      artifact-name: "PRbase"
      python-version: "3.10"

  diff_policy:
    uses: ./.github/workflows/diff-policy.yml
    needs: [build_branch_policy, build_PRtarget_policy, build_setools, build_userspace]
    if: ${{ github.event_name == 'pull_request' }}
    with:
      left: "PRbase"
      right: "refpolicy"
      python-version: "3.10"
