feat(workflows): upload coverage / JUnit results in workflows #1580
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: | |
- main # allow to trigger the workflow with tag push event | |
pull_request: | |
paths: | |
- setup.py | |
- setup.cfg | |
- pyproject.toml | |
- MANIFEST.in | |
- CMakeLists.txt | |
- include/** | |
- src/** | |
- optree/version.py | |
- .github/workflows/build.yml | |
release: | |
types: | |
- published | |
# Allow to trigger the workflow manually | |
workflow_dispatch: | |
inputs: | |
task: | |
description: "Task type" | |
type: choice | |
options: | |
- build-only | |
- build-and-publish | |
required: true | |
permissions: | |
contents: read | |
concurrency: | |
group: "${{ github.workflow }}-${{ github.ref }}" | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
env: | |
PYTHON_TAG: "py3" # to be updated | |
jobs: | |
build-sdist: | |
name: Build sdist | |
if: github.repository == 'metaopt/optree' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/')) | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.7 - 3.13" | |
update-environment: true | |
- name: Upgrade pip | |
run: | | |
python -m pip install --upgrade pip setuptools wheel pybind11 | |
- name: Set __release__ | |
if: | | |
startsWith(github.ref, 'refs/tags/') || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.task == 'build-and-publish') | |
run: | | |
python .github/workflows/set_release.py | |
- name: Print version | |
run: python setup.py --version | |
- name: Install dependencies | |
run: python -m pip install --upgrade pip setuptools wheel build | |
- name: Build sdist | |
run: python -m build --sdist | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sdist | |
path: dist/*.tar.gz | |
if-no-files-found: error | |
build-wheels: | |
name: Build wheels for Python ${{ matrix.python-version }} on ${{ matrix.runner }} (${{ matrix.archs }}) | |
if: github.repository == 'metaopt/optree' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/')) | |
runs-on: ${{ matrix.runner }} | |
needs: [build-sdist] | |
strategy: | |
matrix: | |
runner: [ubuntu-latest, windows-latest, macos-latest] | |
python-version: | |
- "3.7" | |
- "3.8" | |
- "3.9" | |
- "3.10" | |
- "3.11" | |
- "3.12" | |
- "3.13" | |
- "3.13t" | |
- "pypy-3.9" | |
- "pypy-3.10" | |
archs: | |
# Generic | |
- "auto" | |
# Linux | |
- "aarch64" | |
- "ppc64le" | |
- "s390x" | |
# Windows | |
- "ARM64" | |
include: | |
- runner: macos-13 | |
python-version: "3.7" | |
archs: "auto" | |
exclude: | |
- runner: ubuntu-latest | |
python-version: "pypy-3.9" | |
archs: "ppc64le" | |
- runner: ubuntu-latest | |
python-version: "pypy-3.10" | |
archs: "ppc64le" | |
- runner: ubuntu-latest | |
python-version: "pypy-3.9" | |
archs: "s390x" | |
- runner: ubuntu-latest | |
python-version: "pypy-3.10" | |
archs: "s390x" | |
- runner: windows-latest | |
python-version: "3.7" | |
archs: "ARM64" | |
- runner: windows-latest | |
python-version: "3.8" | |
archs: "ARM64" | |
- runner: windows-latest | |
python-version: "pypy-3.9" | |
archs: "ARM64" | |
- runner: windows-latest | |
python-version: "pypy-3.10" | |
archs: "ARM64" | |
- runner: macos-latest | |
python-version: "3.7" # Python 3.7 does not support macOS ARM64 | |
# Exclude archs of other platforms | |
- runner: ubuntu-latest | |
archs: "ARM64" | |
- runner: windows-latest | |
archs: "aarch64" | |
- runner: windows-latest | |
archs: "ppc64le" | |
- runner: windows-latest | |
archs: "s390x" | |
- runner: macos-latest | |
archs: "aarch64" | |
- runner: macos-latest | |
archs: "ppc64le" | |
- runner: macos-latest | |
archs: "s390x" | |
- runner: macos-latest | |
archs: "ARM64" | |
fail-fast: false | |
timeout-minutes: 180 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Determine Python version | |
shell: bash | |
run: | | |
PYTHON_VERSION="${{ matrix.python-version }}" | |
PYTHON_VERSION="${PYTHON_VERSION%t}" | |
echo "Using Python version: ${PYTHON_VERSION}" | |
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> "${GITHUB_ENV}" | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
update-environment: true | |
allow-prereleases: true | |
- name: Set up Environment | |
run: | | |
python -m pip install --upgrade pip setuptools wheel pybind11 | |
- name: Set __release__ | |
if: | | |
startsWith(github.ref, 'refs/tags/') || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.task == 'build-and-publish') | |
run: python .github/workflows/set_release.py | |
- name: Print version | |
run: python setup.py --version | |
- name: Set CIBW_BUILD | |
shell: bash | |
run: | | |
PYTHON_TAG="$( | |
echo 'import sys; print( | |
"{0.name[0]}p{1.major}{1.minor}".format( | |
sys.implementation, | |
sys.version_info, | |
).lower(), | |
)' | python - | |
)" | |
if [[ "${{ matrix.python-version }}" == *"t" ]]; then | |
PYTHON_TAG="${PYTHON_TAG}t" | |
fi | |
echo "PYTHON_TAG=${PYTHON_TAG}" | tee -a "${GITHUB_ENV}" | |
echo "CIBW_BUILD=${PYTHON_TAG}-*" | tee -a "${GITHUB_ENV}" | |
- name: Set up QEMU | |
if: runner.os == 'Linux' | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: all | |
- name: Build wheels | |
uses: pypa/[email protected] | |
env: | |
CIBW_BUILD: ${{ env.CIBW_BUILD }} | |
CIBW_ARCHS: ${{ matrix.archs }} | |
CIBW_ARCHS_MACOS: ${{ matrix.archs }} universal2 | |
with: | |
package-dir: . | |
output-dir: wheelhouse | |
config-file: "{package}/pyproject.toml" | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: wheels-${{ env.PYTHON_TAG }}-${{ runner.os }}-${{ matrix.archs }} | |
path: wheelhouse/*.whl | |
if-no-files-found: error | |
list-artifacts: | |
name: List artifacts | |
if: github.repository == 'metaopt/optree' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/')) | |
runs-on: ubuntu-latest | |
needs: [build-sdist, build-wheels] | |
timeout-minutes: 15 | |
steps: | |
- name: Download built sdist | |
uses: actions/download-artifact@v4 | |
with: | |
# unpacks default artifact into dist/ | |
# if `name: artifact` is omitted, the action will create extra parent dir | |
name: sdist | |
path: dist | |
- name: Download built wheels | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: wheels-* | |
path: dist | |
merge-multiple: true | |
- name: List distributions | |
run: ls -lh dist/* | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: artifacts | |
path: dist/* | |
if-no-files-found: error | |
publish: | |
runs-on: ubuntu-latest | |
needs: [list-artifacts] | |
if: | | |
github.repository == 'metaopt/optree' && github.event_name != 'pull_request' && | |
(github.event_name != 'workflow_dispatch' || github.event.inputs.task == 'build-and-publish') && | |
(github.event_name != 'push' || startsWith(github.ref, 'refs/tags/')) | |
timeout-minutes: 15 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.7 - 3.13" | |
update-environment: true | |
- name: Upgrade pip | |
run: | | |
python -m pip install --upgrade pip setuptools wheel pybind11 | |
- name: Set __release__ | |
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
run: | | |
python .github/workflows/set_release.py | |
- name: Print version | |
run: python setup.py --version | |
- name: Check consistency between the package version and release tag | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
PACKAGE_VER="v$(python setup.py --version)" | |
RELEASE_TAG="${GITHUB_REF#refs/*/}" | |
if [[ "${PACKAGE_VER}" != "${RELEASE_TAG}" ]]; then | |
echo "package ver. (${PACKAGE_VER}) != release tag. (${RELEASE_TAG})" | |
exit 1 | |
fi | |
- name: Download built artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
# unpacks default artifact into dist/ | |
# if `name: artifact` is omitted, the action will create extra parent dir | |
name: artifacts | |
path: dist | |
- name: List distributions | |
run: ls -lh dist/* | |
- name: Publish to TestPyPI | |
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.TESTPYPI_UPLOAD_TOKEN }} | |
repository-url: https://test.pypi.org/legacy/ | |
verbose: true | |
print-hash: true | |
skip-existing: true | |
- name: Publish to PyPI | |
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_UPLOAD_TOKEN }} | |
verbose: true | |
print-hash: true | |
skip-existing: true |