# This workflow runs all workflows to build the dependencies required for the
# project on various Linux flavors, as well as on MacOS and Windows, on a
# scheduled basis, on merge into the 'develop', 'release', or 'master' branches,
# or manually. The missing commits check is only run when the code is merged
# into the 'develop' or 'release' branches, and the documentation is built when
# the code is merged into the 'develop' branch.
name: Trigger

on:
  push:
    branches:
      - "develop"
      - "release*"
      - "master"
    paths:
      # These paths are unique to `on-trigger.yml`.
      - ".github/workflows/reusable-check-missing-commits.yml"
      - ".github/workflows/on-trigger.yml"
      - ".github/workflows/publish-docs.yml"

      # Keep the paths below in sync with those in `on-pr.yml`.
      - ".github/actions/build-deps/**"
      - ".github/actions/build-test/**"
      - ".github/actions/setup-conan/**"
      - ".github/scripts/strategy-matrix/**"
      - ".github/workflows/reusable-build.yml"
      - ".github/workflows/reusable-build-test-config.yml"
      - ".github/workflows/reusable-build-test.yml"
      - ".github/workflows/reusable-strategy-matrix.yml"
      - ".github/workflows/reusable-test.yml"
      - ".codecov.yml"
      - "cmake/**"
      - "conan/**"
      - "external/**"
      - "include/**"
      - "src/**"
      - "tests/**"
      - "CMakeLists.txt"
      - "conanfile.py"
      - "conan.lock"

  # Run at 06:32 UTC on every day of the week from Monday through Friday. This
  # will force all dependencies to be rebuilt, which is useful to verify that
  # all dependencies can be built successfully. Only the dependencies that
  # are actually missing from the remote will be uploaded.
  schedule:
    - cron: "32 6 * * 1-5"

  # Run when manually triggered via the GitHub UI or API.
  workflow_dispatch:

concurrency:
  # When a PR is merged into the develop branch it will be assigned a unique
  # group identifier, so execution will continue even if another PR is merged
  # while it is still running. In all other cases the group identifier is shared
  # per branch, so that any in-progress runs are cancelled when a new commit is
  # pushed.
  group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' && github.sha || github.ref }}
  cancel-in-progress: true

defaults:
  run:
    shell: bash

jobs:
  check-missing-commits:
    if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && contains(fromJSON('["develop", "release"]'), github.ref_name) }}
    uses: ./.github/workflows/reusable-check-missing-commits.yml

  build-test:
    uses: ./.github/workflows/reusable-build-test.yml
    strategy:
      fail-fast: ${{ github.event_name == 'merge_group' }}
      matrix:
        os: [linux, macos, windows]
    with:
      os: ${{ matrix.os }}
      strategy_matrix: ${{ github.event_name == 'schedule' && 'all' || 'minimal' }}
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
