name: Downstream

on:
  workflow_dispatch:
  schedule:
    - cron: '0 7 * * 1'  # Every Monday at 6am UTC
  pull_request:
    # We also want this workflow triggered if the `Downstream CI` label is
    # added or present when PR is updated
    types:
      - synchronize
      - labeled
  push:
    tags:
      - '*'

# Only cancel in-progress jobs or runs for the current workflow
#   This cancels the already triggered workflows for a specific PR without canceling
#   other instances of this workflow (other PRs, scheduled triggers, etc) when something
#   within that PR re-triggers this CI
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  asdf:
    uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v2
    if: (github.repository == 'asdf-format/asdf' && (github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'Downstream CI')))
    with:
      submodules: false
      # Any env name which does not start with `pyXY` will use this Python version.
      default_python: '3.12'
      envs: |
        - linux: asdf-wcs-schemas
        - linux: asdf-coordinates-schemas
        - linux: asdf-zarr
        - linux: asdf-compression

  astropy:
    uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v2
    if: (github.repository == 'asdf-format/asdf' && (github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'Downstream CI')))
    with:
      submodules: false
      # Any env name which does not start with `pyXY` will use this Python version.
      default_python: '3.12'
      envs: |
        - linux: asdf-astropy
        - linux: specutils

  stsci:
    uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v2
    if: (github.repository == 'asdf-format/asdf' && (github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'Downstream CI')))
    with:
      submodules: false
      # Any env name which does not start with `pyXY` will use this Python version.
      default_python: '3.12'
      envs: |
        - linux: astrocut
        - linux: gwcs
        - linux: jwst
        - linux: stdatamodels
        - linux: stpipe
        - linux: roman_datamodels

  third-party:
    uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v2
    if: (github.repository == 'asdf-format/asdf' && (github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'Downstream CI')))
    with:
      submodules: false
      # Any env name which does not start with `pyXY` will use this Python version.
      default_python: '3.12'
      envs: |
        - linux: weldx
        - linux: sunpy
        - linux: dkist
        - linux: abacusutils
