Repository navigation
113 lines (95 loc) · 3.81 KB
/
Copy pathreusable-maya-tests.yml
File metadata and controls
113 lines (95 loc) · 3.81 KB
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
name: reusable / maya tests
on:
workflow_call:
workflow_dispatch: # Manual trigger
jobs:
# Cheap gate: skips the disk purge + multi-GB Maya image pull when there are
# no tests, the common case for freshly created template projects.
collect_tests:
runs-on: ubuntu-latest
outputs:
tests_collected: ${{ steps.check_tests.outputs.tests_collected }}
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: '3.13'
- name: Install dependencies
run: uv sync --only-group test
- name: Check for tests
id: check_tests
run: |
set +e
# --ignore=tests/template: CI also fires on a generated repo's
# first commit, before setup has deleted the template's own tests.
output=$(uv run --no-sync pytest --collect-only --ignore=tests/template)
exit_code=$?
set -e
echo "$output"
# Exit 5 is the only non-zero status meaning "nothing to run". A
# collection error (exit 2) also prints "collected 0 items", so
# treating it as an empty suite would skip every test and stay green.
if [ $exit_code -eq 5 ]; then
echo "tests_collected=0" >> $GITHUB_OUTPUT
echo "No tests were collected."
exit 0
fi
if [ $exit_code -ne 0 ]; then
echo "::error::pytest --collect-only failed (exit $exit_code)." \
"Tests must import outside Maya: move 'from maya import ...'" \
"into a test or fixture, as tests/maya/conftest.py does."
exit 1
fi
collected=$(echo "$output" | grep -oP 'collected \K\d+')
if [ -z "$collected" ]; then
echo "::error::Could not parse a test count from pytest output."
exit 1
fi
echo "tests_collected=$collected" >> $GITHUB_OUTPUT
echo "Collected $collected tests."
no_tests_found:
needs: collect_tests
if: needs.collect_tests.outputs.tests_collected == '0'
runs-on: ubuntu-latest
steps:
- name: No tests found
run: echo "No tests were collected. Skipping test execution."
maya:
needs: collect_tests
if: needs.collect_tests.outputs.tests_collected != '0'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# add/remove versions to match what you target; tags: https://github.com/mottosso/docker-maya/
maya_version: ["2024"]
steps:
- name: Checkout code
uses: actions/checkout@v5
# No job-level `container:`: that pulls before any step can free disk space first,
# and large Maya images can exceed the runner's free disk mid-pull.
- name: Free disk space
run: |
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc \
/usr/local/share/powershell /usr/share/swift /opt/hostedtoolcache/CodeQL
df -h /
- name: Pull Maya image
run: docker pull mottosso/maya:${{ matrix.maya_version }} # ty mottosso!
- name: Install test dependencies and run tests in Maya container
run: |
docker run --rm \
-e XDG_RUNTIME_DIR=/var/tmp/runtime-root \
-e MAYA_DISABLE_ADP=1 \
-v "${{ github.workspace }}:/workspace" \
-w /workspace \
mottosso/maya:${{ matrix.maya_version }} \
bash -c '
set -e
if command -v curl >/dev/null; then curl -LsSf https://astral.sh/uv/install.sh | sh
else wget -qO- https://astral.sh/uv/install.sh | sh
fi
export PATH="$HOME/.local/bin:$PATH"
uv pip install --python "$(command -v mayapy)" --group test .
mayapy -m pytest tests --ignore=tests/template
'