mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
86 lines
2.4 KiB
YAML
86 lines
2.4 KiB
YAML
name: Unit Testing
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
python_versions:
|
|
description: 'Space separated list of Python versions to run tests with.'
|
|
required: false
|
|
default: '3.6 3.7 3.8 3.9 3.10'
|
|
type: string
|
|
requirements:
|
|
description: 'Python dependencies to be installed through pip.'
|
|
required: false
|
|
default: '-r tests/requirements.txt'
|
|
type: string
|
|
TestReport:
|
|
description: "Generate unit test report with junitxml and upload results as an artifact."
|
|
required: false
|
|
default: false
|
|
type: string
|
|
|
|
jobs:
|
|
|
|
|
|
Versions:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
jobs: ${{ steps.versions.outputs.jobs }}
|
|
steps:
|
|
|
|
- id: versions
|
|
shell: python
|
|
run: |
|
|
icons = {
|
|
'3.6': '🔴', # until 23.12.2021
|
|
'3.7': '🟠', # until 27.06.2023
|
|
'3.8': '🟡', # until Oct. 2024
|
|
'3.9': '🟢', # until Oct. 2025
|
|
'3.10': '🟢', # until Oct. 2026
|
|
}
|
|
jobs = [
|
|
{'python': version, 'icon': icons[version]}
|
|
for version in '${{ inputs.python_versions }}'.split(' ')
|
|
]
|
|
print(f'::set-output name=jobs::{jobs!s}')
|
|
|
|
|
|
UnitTesting:
|
|
name: ${{ matrix.icon }} Unit Tests using Python ${{ matrix.python }}
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- Versions
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include: ${{ fromJson(needs.Versions.outputs.jobs) }}
|
|
|
|
steps:
|
|
- name: ⏬ Checkout repository
|
|
uses: actions/checkout@v2
|
|
|
|
- name: 🐍 Setup Python ${{ matrix.python }}
|
|
uses: actions/setup-python@v2
|
|
with:
|
|
python-version: ${{ matrix.python }}
|
|
|
|
- name: 🔧 Install dependencies
|
|
run: |
|
|
python -m pip install -U pip
|
|
python -m pip install ${{ inputs.requirements }}
|
|
|
|
- name: ☑ Run unit tests
|
|
run: |
|
|
[ '${{ inputs.TestReport }}' = 'true' ] && PYTEST_ARGS='--junitxml=TestReport.xml' || unset PYTEST_ARGS
|
|
python -m pytest -rA tests/unit $PYTEST_ARGS --color=yes
|
|
|
|
- name: 📤 Upload 'TestReport.xml' artifact
|
|
if: inputs.TestReport == 'true'
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: TestReport-${{ matrix.python }}
|
|
path: TestReport.xml
|
|
if-no-files-found: error
|
|
retention-days: 1
|