Skip to content

Commit 1be1282

Browse files
sayakpaulDN6
andcommitted
[Workflows] add a more secure way to run tests from a PR. (#7969)
* add a more secure way to run tests from a PR. * make pytest more secure. * address dhruv's comments. * improve validation check. * Update .github/workflows/run_tests_from_a_pr.yml Co-authored-by: Dhruv Nair <[email protected]> --------- Co-authored-by: Dhruv Nair <[email protected]>
1 parent d1ddc5e commit 1be1282

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Check running SLOW tests from a PR (only GPU)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
docker_image:
7+
default: 'diffusers/diffusers-pytorch-cuda'
8+
description: 'Name of the Docker image'
9+
required: true
10+
branch:
11+
description: 'PR Branch to test on'
12+
required: true
13+
test:
14+
description: 'Tests to run (e.g.: `tests/models`).'
15+
required: true
16+
17+
env:
18+
DIFFUSERS_IS_CI: yes
19+
IS_GITHUB_CI: "1"
20+
HF_HOME: /mnt/cache
21+
OMP_NUM_THREADS: 8
22+
MKL_NUM_THREADS: 8
23+
PYTEST_TIMEOUT: 600
24+
RUN_SLOW: yes
25+
26+
jobs:
27+
run_tests:
28+
name: "Run a test on our runner from a PR"
29+
runs-on: [single-gpu, nvidia-gpu, t4, ci]
30+
container:
31+
image: ${{ github.event.inputs.docker_image }}
32+
options: --gpus 0 --privileged --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
33+
34+
steps:
35+
- name: Validate test files input
36+
id: validate_test_files
37+
env:
38+
PY_TEST: ${{ github.event.inputs.test }}
39+
run: |
40+
if [[ ! "$PY_TEST" =~ ^tests/ ]]; then
41+
echo "Error: The input string must start with 'tests/'."
42+
exit 1
43+
fi
44+
45+
if [[ ! "$PY_TEST" =~ ^tests/(models|pipelines) ]]; then
46+
echo "Error: The input string must contain either 'models' or 'pipelines' after 'tests/'."
47+
exit 1
48+
fi
49+
50+
if [[ "$PY_TEST" == *";"* ]]; then
51+
echo "Error: The input string must not contain ';'."
52+
exit 1
53+
fi
54+
echo "$PY_TEST"
55+
56+
- name: Checkout PR branch
57+
uses: actions/checkout@v4
58+
with:
59+
ref: ${{ github.event.inputs.branch }}
60+
repository: ${{ github.event.pull_request.head.repo.full_name }}
61+
62+
63+
- name: Install pytest
64+
run: |
65+
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
66+
python -m uv pip install -e [quality,test]
67+
python -m uv pip install peft
68+
69+
- name: Run tests
70+
env:
71+
PY_TEST: ${{ github.event.inputs.test }}
72+
run: |
73+
pytest "$PY_TEST"

0 commit comments

Comments
 (0)