Oneshot test #1
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
# Workflow to test individual hooks across multiple versions of the | |
# library the are written for. | |
# This action is not run continuously. You must manually trigger it. | |
# | |
# This workflow features workflow_dispatch parameters: | |
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/ | |
# And daisy-chaining the output of one job to dynamically set the matrix of a | |
# second job: | |
# https://stackoverflow.com/a/62953566/7390688 | |
--- | |
name: Oneshot test | |
on: | |
workflow_dispatch: | |
# Input parameters: | |
inputs: | |
package: | |
description: | | |
Package names and versions to test. Jobs are split by comma. | |
required: true | |
default: 'numpy==1.19, numpy<1.18' | |
os: | |
description: | | |
OS(s) to run on. Can be any combinations of ubuntu, windows, macos. | |
(Please use macos sparingly.)' | |
required: true | |
default: 'ubuntu' | |
python-version: | |
description: 'Version(s) of Python' | |
required: true | |
default: '3.11,' | |
fail-fast: | |
description: 'Terminate all tests if one fails (true/false).' | |
required: true | |
default: 'false' | |
commands: | |
description: | | |
Additional installation commands to run from terminal. | |
Ran from bash irregardless of OS. | |
Use ';' to separate multiple commands. | |
required: false | |
pytest_args: | |
description: | | |
Additional arguments to be passed to pytest. | |
env: | |
# Colored pytest output on CI despite not having a tty | |
FORCE_COLOR: 1 | |
permissions: {} | |
jobs: | |
generate-matrix: | |
# Parse inputs into a json containing the matrix that will parametrize the | |
# next "test" step. | |
name: Generate Matrix | |
runs-on: ubuntu-latest | |
env: | |
# Copy github.event.inputs into an environment variable INPUTS which can | |
# be easily read in Python. | |
INPUTS: ${{ toJson(github.event.inputs) }} | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
# Actually parse the configuration. | |
- id: set-matrix | |
shell: python | |
run: | | |
import os, json, pprint | |
inputs = json.loads(os.environ["INPUTS"]) | |
pprint.pprint(inputs) | |
# Split by comma, ignore trailing comma, remove whitespace. | |
parse_list = lambda x: [i.strip() for i in x.strip(", ").split(",")] | |
# Wrap a word in quotes, escaping any literal quotes already there. | |
quote = lambda x: '"{}"'.format(x.replace('"', r'\"')) | |
matrix = { | |
"os": [i + "-latest" for i in parse_list(inputs["os"])], | |
"python-version": parse_list(inputs["python-version"]), | |
"requirements": parse_list(inputs["package"]), | |
} | |
# Wrap each word in " " quotes to force bash to interpret special | |
# characters such as > as literals. | |
matrix["requirements"] = [ | |
" ".join(map(quote, i.split(" "))) | |
for i in matrix["requirements"] | |
] | |
pprint.pprint(matrix) | |
# Outputs are set by printing special :: | |
print("::set-output name=matrix::", json.dumps(matrix), sep="") | |
test: | |
permissions: | |
contents: read # to fetch code (actions/checkout) | |
needs: generate-matrix | |
runs-on: ${{ matrix.os }} | |
strategy: | |
# Use the test matrix generated in the last step. | |
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} | |
# Caution: `fail-fast` expects a bool but `inputs.fail-fast` is a string. | |
# There doesn't seem to be a nice function to cast 'true' to true. | |
fail-fast: ${{ github.event.inputs.fail-fast == 'true' }} | |
env: | |
# Rebuild bootloader when installing PyInstaller from develop branch | |
PYINSTALLER_COMPILE_BOOTLOADER: 1 | |
# Finally, the usual: setup Python, install dependencies, test. | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Set up .NET Core for pythonnet tests | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '6.x' | |
- name: Run bash commands | |
if: ${{ github.event.inputs.commands }} | |
run: ${{ github.event.inputs.commands }} | |
- name: Install dependencies | |
shell: bash | |
run: | | |
# Upgrade to the latest pip. | |
python -m pip install -U pip "setuptools<71.0.0" wheel | |
# Install hooks-contrib | |
pip install -e . | |
pip install -r requirements-test.txt | |
pip install ${{ matrix.requirements }} | |
# Install PyInstaller | |
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip | |
- name: Run tests | |
run: pytest -v ${{ inputs.pytest_args }} |