Skip to content

add v2 tests

add v2 tests #682

Workflow file for this run

name: Build package
on:
workflow_call:
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
push:
branches:
- master
- v*
jobs:
build:
runs-on: ubuntu-latest
outputs:
WHL: ${{ steps.filenames.outputs.WHL }}
TARGZ: ${{ steps.filenames.outputs.TARGZ }}
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Setup hatch
run: python -m pip install hatch
- name: Set new version
if: startsWith(github.ref, 'refs/tags/v')
run: |
python -m hatch version ${GITHUB_REF/refs\/tags\/v/}
- name: Build package
run: python -m hatch build
- name: Set filenames in output
id: filenames
run: |
echo WHL=$(echo dist/*.whl) >> $GITHUB_OUTPUT
echo TARGZ=$(echo dist/*.tar.gz) >> $GITHUB_OUTPUT
- name: Archive package
uses: actions/upload-artifact@v4
with:
name: distributions
path: dist
retention-days: 5
tests:
needs: build
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12"]
os: [ ubuntu-latest, windows-latest ]
distribution: [ "${{ needs.build.outputs.WHL }}",
"${{ needs.build.outputs.TARGZ }}" ]
runs-on: ${{ matrix.os }}
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: distributions
path: dist
- name: Install package and test dependencies
run: pip install ${{ matrix.distribution }}[test]
- name: Detect suffix on ubuntu
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
echo SUFFIX=$(python -c "import pathlib;p=pathlib.Path('${{ matrix.distribution }}');print('whl') if p.suffix=='.whl' else print('tar_gz')") >> $GITHUB_ENV
- name: Detect suffix on windows
if: ${{ matrix.os == 'windows-latest' }}
# https://github.com/actions/runner-images/issues/5251#issuecomment-1071030822
run: |
echo SUFFIX=$(python -c "import pathlib;p=pathlib.Path('${{ matrix.distribution }}');print('whl') if p.suffix=='.whl' else print('tar_gz')") | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Run pytest
run: >-
pytest
-n logical
--html=pytest_reports/unittest_report_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.html
--self-contained-html
--cov=$(python -c "import pathlib;import sdc11073;print(pathlib.Path(sdc11073.__file__).parent)")
--log-file pytest_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.log
- name: Archive test result
uses: actions/upload-artifact@v4
if: success() || failure() # upload artifacts also if test stage failed
with:
name: unittest_reports-${{ matrix.os }}-py${{ matrix.python-version }}-${{ env.SUFFIX }}
path: pytest_reports/unittest_report_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.html
retention-days: 5
- name: Archive test log
uses: actions/upload-artifact@v4
if: success() || failure() # upload artifacts also if test stage failed
with:
name: pytest_logs-${{ matrix.os }}-py${{ matrix.python-version }}-${{ env.SUFFIX }}
path: pytest_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.log
retention-days: 5
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: "8c8b98c0-4c00-4f83-a598-81f3857e63e9" # https://github.com/codecov/codecov-action/issues/837#issuecomment-1530053511
verbose: true