-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[Workflows] add a more secure way to run tests from a PR. #7969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cd22bf7
ccb53eb
9b534b1
51aeb35
2f3c287
7b19e75
3fcfeef
9c0f66a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Check running SLOW tests from a PR (only GPU) | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
docker_image: | ||
default: 'diffusers/diffusers-pytorch-cuda' | ||
description: 'Name of the Docker image' | ||
required: true | ||
branch: | ||
description: 'PR Branch to test on' | ||
required: true | ||
test: | ||
description: 'Tests to run (e.g.: `tests/models`).' | ||
required: true | ||
|
||
env: | ||
DIFFUSERS_IS_CI: yes | ||
IS_GITHUB_CI: "1" | ||
HF_HOME: /mnt/cache | ||
OMP_NUM_THREADS: 8 | ||
MKL_NUM_THREADS: 8 | ||
PYTEST_TIMEOUT: 600 | ||
RUN_SLOW: yes | ||
|
||
jobs: | ||
run_tests: | ||
name: "Run a test on our runner from a PR" | ||
runs-on: [single-gpu, nvidia-gpu, t4, ci] | ||
container: | ||
image: ${{ github.event.inputs.docker_image }} | ||
options: --gpus 0 --privileged --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ | ||
|
||
steps: | ||
- name: Validate test files input | ||
id: validate_test_files | ||
env: | ||
PY_TEST: ${{ github.event.inputs.test }} | ||
run: | | ||
if [[ ! "$PY_TEST" =~ ^tests/ ]]; then | ||
echo "Error: The input string must start with 'tests/'." | ||
exit 1 | ||
fi | ||
|
||
if [[ ! "$PY_TEST" =~ ^tests/(models|pipelines) ]]; then | ||
echo "Error: The input string must contain either 'models' or 'pipelines' after 'tests/'." | ||
exit 1 | ||
fi | ||
|
||
if [[ "$PY_TEST" == *";"* ]]; then | ||
echo "Error: The input string must not contain ';'." | ||
exit 1 | ||
fi | ||
echo "$PY_TEST" | ||
|
||
- name: Checkout PR branch | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.inputs.branch }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
|
||
|
||
- name: Install pytest | ||
run: | | ||
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" | ||
python -m uv pip install -e [quality,test] | ||
python -m uv pip install peft | ||
|
||
- name: Run tests | ||
env: | ||
PY_TEST: ${{ github.event.inputs.test }} | ||
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we want to allow arbitrary string inputs. e.g. This string I suppose only users in the HF org can dispatch this workflow right? Just feels a bit risky. cc: @glegendre01 to confirm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a validation step in the workflow which looks for things like that. |
||
run: | | ||
pytest "$PY_TEST" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also work if the PR is created from a fork? I thought it would not, which is why I liked the
gh
approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, yes. Cc: @glegendre01