forked from pyinstaller/pyinstaller-hooks-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (130 loc) · 4.87 KB
/
oneshot-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# 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@v4
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@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up .NET Core for pythonnet tests
uses: actions/setup-dotnet@v3
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 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 }}