mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
187 lines
8.1 KiB
YAML
187 lines
8.1 KiB
YAML
# ==================================================================================================================== #
|
|
# Authors: #
|
|
# Patrick Lehmann #
|
|
# Unai Martinez-Corral #
|
|
# #
|
|
# ==================================================================================================================== #
|
|
# Copyright 2020-2022 The pyTooling Authors #
|
|
# #
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); #
|
|
# you may not use this file except in compliance with the License. #
|
|
# You may obtain a copy of the License at #
|
|
# #
|
|
# http://www.apache.org/licenses/LICENSE-2.0 #
|
|
# #
|
|
# Unless required by applicable law or agreed to in writing, software #
|
|
# distributed under the License is distributed on an "AS IS" BASIS, #
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
|
# See the License for the specific language governing permissions and #
|
|
# limitations under the License. #
|
|
# #
|
|
# SPDX-License-Identifier: Apache-2.0 #
|
|
# ==================================================================================================================== #
|
|
name: Unit Testing
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
jobs:
|
|
description: 'JSON list with environment fields, telling the system and Python versions to run tests with.'
|
|
required: true
|
|
type: string
|
|
requirements:
|
|
description: 'Python dependencies to be installed through pip.'
|
|
required: false
|
|
default: '-r tests/requirements.txt'
|
|
type: string
|
|
pacboy:
|
|
description: 'MSYS2 dependencies to be installed through pacboy (pacman).'
|
|
required: false
|
|
default: ""
|
|
type: string
|
|
mingw_requirements:
|
|
description: 'Override Python dependencies to be installed through pip on MSYS2 (MINGW64) only.'
|
|
required: false
|
|
default: ''
|
|
type: string
|
|
tests_directory:
|
|
description: 'Path to the directory containing tests (test working directory).'
|
|
required: false
|
|
default: 'tests'
|
|
type: string
|
|
unittest_directory:
|
|
description: 'Path to the directory containing unit tests (relative to tests_directory).'
|
|
required: false
|
|
default: 'unit'
|
|
type: string
|
|
artifact:
|
|
description: "Generate unit test report with junitxml and upload results as an artifact."
|
|
required: false
|
|
default: ''
|
|
type: string
|
|
|
|
jobs:
|
|
|
|
UnitTesting:
|
|
name: ${{ matrix.sysicon }} ${{ matrix.pyicon }} Unit Tests using Python ${{ matrix.python }}
|
|
runs-on: ${{ matrix.runs-on }}
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include: ${{ fromJson(inputs.jobs) }}
|
|
|
|
defaults:
|
|
run:
|
|
shell: ${{ matrix.shell }}
|
|
|
|
steps:
|
|
- name: ⏬ Checkout repository
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Install dependencies for compute step
|
|
if: matrix.system == 'msys2'
|
|
run: pip install pyTooling
|
|
|
|
- name: Compute pacman/pacboy packages
|
|
id: pacboy
|
|
if: matrix.system == 'msys2'
|
|
shell: python
|
|
run: |
|
|
from os import getenv
|
|
from pathlib import Path
|
|
from re import compile
|
|
|
|
from pyTooling.Packageing import loadRequirementsFile
|
|
|
|
requirementsFile = Path("${{ inputs.requirements }}")
|
|
dependencies = loadRequirementsFile(requirementsFile)
|
|
|
|
filter = {
|
|
"pip": "python-pip:p",
|
|
"wheel": "python-wheel:p",
|
|
"coverage": "python-coverage:p",
|
|
"lxml": "python-lxml:p",
|
|
"ruamel-yaml": "python-ruamel-yaml:p python-ruamel.yaml.clib:p",
|
|
"numpy": "python-numpy:p",
|
|
}
|
|
|
|
regExp = compile(r"([\w_\-\.]+)(\s*(?:[<>=]+)\s*)(\d+(?:.\d+)*)")
|
|
|
|
packages = []
|
|
print(f"Processing requirements ({len(dependencies)}):")
|
|
for dependency in dependencies:
|
|
match = regExp.match(dependency)
|
|
if not match:
|
|
print(f" Wrong format: {dependency}")
|
|
continue
|
|
|
|
try:
|
|
package = match[0]
|
|
rewrite = filter[package]
|
|
|
|
print(f" Found rewrite rule for '{package}': {rewrite}")
|
|
packages.append(rewrite)
|
|
except KeyError:
|
|
continue
|
|
|
|
# Write jobs to special file
|
|
github_output = Path(getenv("GITHUB_OUTPUT"))
|
|
print(f"GITHUB_OUTPUT: {github_output}")
|
|
with github_output.open("a+") as f:
|
|
f.write(f"pacboy_packages={' '.join(packages)}\n")
|
|
|
|
- name: '🟦 Setup MSYS2'
|
|
if: matrix.system == 'msys2'
|
|
uses: msys2/setup-msys2@v2
|
|
with:
|
|
msystem: MINGW64
|
|
update: true
|
|
pacboy: >-
|
|
${{ steps.pacboy.outputs.pacboy_packages }}
|
|
${{ inputs.pacboy }}
|
|
|
|
- name: 🐍 Setup Python ${{ matrix.python }}
|
|
if: matrix.system != 'msys2'
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: ${{ matrix.python }}
|
|
|
|
- name: 🔧 Install wheel and pip dependencies (native)
|
|
if: matrix.system != 'msys2'
|
|
run: |
|
|
python -m pip install --disable-pip-version-check -U wheel
|
|
python -m pip install --disable-pip-version-check ${{ inputs.requirements }}
|
|
|
|
- name: 🔧 Install pip dependencies (MSYS2)
|
|
if: matrix.system == 'msys2'
|
|
run: |
|
|
if [ 'x${{ inputs.mingw_requirements }}' != 'x' ]; then
|
|
python -m pip install --disable-pip-version-check ${{ inputs.mingw_requirements }}
|
|
else
|
|
python -m pip install --disable-pip-version-check ${{ inputs.requirements }}
|
|
fi
|
|
|
|
- name: ☑ Run unit tests (Windows)
|
|
if: matrix.system == 'windows'
|
|
run: |
|
|
cd ${{ inputs.tests_directory }}
|
|
$PYTEST_ARGS = if ("${{ inputs.artifact }}".length -gt 0) { "--junitxml=TestReportSummary.xml" } else { "" }
|
|
python -m pytest -rA ${{ inputs.unittest_directory }} $PYTEST_ARGS --color=yes
|
|
|
|
- name: ☑ Run unit tests (Ubuntu/macOS)
|
|
if: matrix.system != 'windows'
|
|
run: |
|
|
cd ${{ inputs.tests_directory }}
|
|
[ 'x${{ inputs.artifact }}' != 'x' ] && PYTEST_ARGS='--junitxml=TestReportSummary.xml' || unset PYTEST_ARGS
|
|
python -m pytest -rA ${{ inputs.unittest_directory }} $PYTEST_ARGS --color=yes
|
|
|
|
- name: 📤 Upload 'TestReportSummary.xml' artifact
|
|
if: inputs.artifact != ''
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: ${{ inputs.artifact }}-${{ matrix.system }}-${{ matrix.python }}
|
|
path: ${{ inputs.tests_directory }}/TestReportSummary.xml
|
|
if-no-files-found: error
|
|
retention-days: 1
|