Skip to content

Sync v5 migration docs #935

Sync v5 migration docs

Sync v5 migration docs #935

Workflow file for this run

name: tests
on:
push:
branches: [main, v4]
tags:
- 'v*'
pull_request:
branches: [main, v4]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
# Only resolve distributions published at least one week ago, reducing the
# chance of installing packages affected by undetected supply chain attacks
UV_EXCLUDE_NEWER: 7 days
# Make uv pip install into the python provided by setup-python
UV_SYSTEM_PYTHON: 1
jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ matrix.python }}
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: true
cache-suffix: py${{ matrix.python }}
cache-dependency-glob: pyproject.toml
- name: Test without optional dependencies and without pyyaml
run: |
uv pip install .[coverage]
uv pip uninstall pyyaml types-PyYAML
pytest --cov --cov-report=term --cov-report=xml --junit-xml=junit.xml
mv coverage.xml coverage_py${{ matrix.python }}_bare.xml
mv junit.xml junit_py${{ matrix.python }}_bare.xml
- name: Test with all optional dependencies
run: |
uv pip install .[test,all]
pytest --cov --cov-report=term --cov-report=xml --junit-xml=junit.xml
mv coverage.xml coverage_py${{ matrix.python }}_all.xml
mv junit.xml junit_py${{ matrix.python }}_all.xml
- name: Test without future annotations
run: |
sed -i '/^from __future__ import annotations$/d' jsonargparse_tests/test_*.py
pytest --cov --cov-report=term --cov-report=xml --junit-xml=junit.xml
mv coverage.xml coverage_py${{ matrix.python }}_types.xml
mv junit.xml junit_py${{ matrix.python }}_types.xml
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage_py${{ matrix.python }}
path: ./coverage_py*
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: junit_py${{ matrix.python }}
path: ./junit_py*
argparse-compatibility:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ matrix.python }}
cache: pip
- run: pip install --require-hashes -r .github/workflows/tox.lock
- run: tox -e py-argparse
env:
# Used by the gh CLI to download CPython's test_argparse.py
GH_TOKEN: ${{ github.token }}
windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ matrix.python }}
cache: pip
- run: pip install --require-hashes -r .github/workflows/tox.lock
- run: tox -e py-all-extras
macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
python: ["3.12", "3.14"]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ matrix.python }}
cache: pip
- run: pip install --require-hashes -r .github/workflows/tox.lock
- run: tox -e py-all-extras
omegaconf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
cache: pip
- run: pip install --require-hashes -r .github/workflows/tox.lock
- run: tox -e omegaconf
pydantic-v1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: true
cache-suffix: pydantic-v1
cache-dependency-glob: pyproject.toml
- name: With pydantic<2
run: |
uv pip install .[coverage]
uv pip install "pydantic<2"
pytest --cov --cov-report=term --cov-report=xml --junit-xml=junit.xml jsonargparse_tests/test_pydantic.py
mv coverage.xml coverage_pydantic1.xml
mv junit.xml junit_pydantic1.xml
- name: with pydantic>=2
run: |
sed -i "s|import pydantic|import pydantic.v1 as pydantic|" jsonargparse_tests/test_pydantic.py
sed -i "s|^annotated = .*|annotated = False|" jsonargparse_tests/test_pydantic.py
uv pip install "pydantic>=2"
pytest --cov --cov-report=term --cov-report=xml --junit-xml=junit.xml jsonargparse_tests/test_pydantic.py
mv coverage.xml coverage_pydantic2.xml
mv junit.xml junit_pydantic2.xml
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage_pydantic
path: ./coverage_py*
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: junit_pydantic
path: ./junit_py*
build-package:
# This job builds the artifacts that pypi-publish publishes. To protect
# against cache poisoning attacks, it must not use any cache (actions/cache,
# setup-python's cache or setup-uv's enable-cache) and dependencies must be
# installed with --require-hashes from a lock file.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- name: Build package
run: |
pip install --require-hashes -r .github/workflows/build.lock
python -m build
cd jsonargparse_tests
python -m build --wheel
mv dist/*.whl ../dist/
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package
path: ./dist/*
installed-package:
runs-on: ubuntu-latest
needs: [build-package]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: true
cache-suffix: installed-package
cache-dependency-glob: pyproject.toml
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: package
path: dist
- name: Test without optional dependencies and without pyyaml
run: |
cd dist
uv pip install $(ls jsonargparse-*.whl)[test-no-urls] $(ls jsonargparse_tests-*.whl)
uv pip uninstall pyyaml
python -m jsonargparse_tests
- name: Test with all optional dependencies
run: |
cd dist
uv pip install $(ls jsonargparse-*.whl)[test,all]
python -m jsonargparse_tests
doctest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: true
cache-suffix: doctest
cache-dependency-glob: pyproject.toml
- run: uv pip install -e .[all,test,shtab,doc]
- name: Run doc tests
run: sphinx-build -M doctest sphinx sphinx/_build sphinx/index.rst
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
cache: pip
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
key: pre-commit-cache-${{ hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/pre-commit
- run: pip install --require-hashes -r .github/workflows/pre-commit.lock
- run: pre-commit run -a --hook-stage pre-push mypy
codecov:
runs-on: ubuntu-latest
needs: [linux, pydantic-v1]
permissions:
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
merge-multiple: true
- uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
fail_ci_if_error: true
files: ./coverage_*.xml
use_oidc: true
- uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
fail_ci_if_error: true
report_type: test_results
files: ./junit_*.xml
use_oidc: true
sonarcloud:
runs-on: ubuntu-latest
environment: sonarcloud
if: |
(github.event_name == 'push') ||
(github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork)
needs: [linux, pydantic-v1]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0 # Shallow clone disabled for a better relevancy of analysis
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
merge-multiple: true
- name: Get version
run: |
TAG=$(git describe --tags --exact-match 2>/dev/null | sed 's/^v//')
if [ -n "$TAG" ]; then
VERSION="$TAG"
else
VERSION="$(git describe --tags --abbrev=0 | sed 's/^v//')+$(git rev-parse --short HEAD)"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: SonarSource/sonarqube-scan-action@59db25f34e16620e48ab4bb9e4a5dce155cb5432 # v8.0.0
with:
args: >
-Dsonar.organization=mauvilsa
-Dsonar.projectKey=mauvilsa_jsonargparse
-Dsonar.projectVersion=${{ env.VERSION }}
-Dsonar.sources=jsonargparse
-Dsonar.exclusions=sphinx/**
-Dsonar.tests=jsonargparse_tests
-Dsonar.python.coverage.reportPaths=coverage_*.xml
-Dsonar.python.version=3.10,3.11,3.12,3.13,3.14
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
pypi-publish:
# This job publishes to PyPI the package created by build-package. Same as
# there, it must not use any cache to protect against cache poisoning.
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs: [linux, windows, macos, argparse-compatibility, omegaconf, pydantic-v1, installed-package, doctest, mypy]
environment:
name: pypi
url: https://pypi.org/p/jsonargparse
permissions:
id-token: write
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: package
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0