name: CI

on:
  push:
    branches:
      - 'main'
      - '*.*'
      - '!*backport*'
    tags:
      - 'v*'
      - '!*dev*'
      - '!*pre*'
      - '!*post*'
  pull_request:
  # Allow manual runs through the web UI
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions: {}

jobs:
  tests:
    uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v2
    with:
      envs: |
        - linux: py310
        - linux: py311
        - macos: py312
        - windows: py313
        - linux: py314
        - linux: py314-devdeps
        - linux: py312-conda
          toxdeps: tox-conda
        - linux: mypy
          pytest: false
      coverage: 'codecov'
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  build:
    needs: tests
    uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v2
    with:
      save_artifacts: true
      upload_to_pypi: false
      test_extras: tests,ftp
      test_command: pytest --pyargs parfive

  upload:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Upload built artifacts to PyPI
    runs-on: ubuntu-latest
    needs: [build]
    permissions:
      id-token: write
    environment:
      name: pypi
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v7
        with:
          merge-multiple: true
          pattern: dist-*
          path: dist

      - name: Run upload
        uses: pypa/gh-action-pypi-publish@release/v1
