Skip to content

Commit 8d9e34b

Browse files
authored
Disable running slow CI for doc-only changes (#9072)
1 parent d1eb12c commit 8d9e34b

11 files changed

+290
-20
lines changed

.github/workflows/_build_plugin.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ on:
1616
type: number
1717
description: Timeout in minutes for the build job
1818
default: 120
19+
has_code_changes:
20+
required: false
21+
type: string
22+
description: Whether to run full workflow or not
23+
default: 'true'
1924
secrets:
2025
gcloud-service-key:
2126
required: true
@@ -32,23 +37,31 @@ jobs:
3237
BAZEL_REMOTE_CACHE: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
3338
steps:
3439
- name: Checkout actions
40+
if: inputs.has_code_changes == 'true'
3541
uses: actions/checkout@v4
3642
with:
3743
sparse-checkout: |
3844
.github/workflows/setup
3945
path: .actions
4046
- name: Setup
47+
if: inputs.has_code_changes == 'true'
4148
uses: ./.actions/.github/workflows/setup
4249
with:
4350
torch-commit: ${{ inputs.torch-commit }}
4451
cuda: true
4552
- name: Build
53+
if: inputs.has_code_changes == 'true'
4654
shell: bash
4755
run: |
4856
cd pytorch/xla/infra/ansible
4957
ansible-playbook playbook.yaml -vvv -e "stage=build_plugin arch=amd64 accelerator=cuda cuda_compute_capabilities=5.2,7.5,8.6 src_root=${GITHUB_WORKSPACE} cache_suffix=-ci" --skip-tags=fetch_srcs,install_deps
5058
- name: Upload wheel
59+
if: inputs.has_code_changes == 'true'
5160
uses: actions/upload-artifact@v4
5261
with:
5362
name: cuda-plugin
5463
path: /dist/*.whl
64+
- name: Report no code changes
65+
if: inputs.has_code_changes == 'false'
66+
run: |
67+
echo "No code changes were detected that require running the full test suite."

.github/workflows/_build_torch_with_cuda.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ on:
2020
type: number
2121
description: Timeout in minutes for the build job
2222
default: 120
23+
has_code_changes:
24+
required: false
25+
type: string
26+
description: Whether to run full workflow or not
27+
default: 'true'
2328
jobs:
2429
build:
2530
runs-on: ${{ inputs.runner }}
@@ -33,23 +38,31 @@ jobs:
3338
MAX_JOBS: 24
3439
steps:
3540
- name: Checkout actions
41+
if: inputs.has_code_changes == 'true'
3642
uses: actions/checkout@v4
3743
with:
3844
sparse-checkout: |
3945
.github/workflows/setup
4046
path: .actions
4147
- name: Setup
48+
if: inputs.has_code_changes == 'true'
4249
uses: ./.actions/.github/workflows/setup
4350
with:
4451
torch-commit: ${{ inputs.torch-commit }}
4552
cuda: true
4653
- name: Build PyTorch with CUDA enabled
54+
if: inputs.has_code_changes == 'true'
4755
shell: bash
4856
run: |
4957
cd pytorch
5058
python setup.py bdist_wheel
5159
- name: Upload wheel
60+
if: inputs.has_code_changes == 'true'
5261
uses: actions/upload-artifact@v4
5362
with:
5463
name: torch-with-cuda
5564
path: pytorch/dist/*.whl
65+
- name: Report no code changes
66+
if: inputs.has_code_changes == 'false'
67+
run: |
68+
echo "No code changes were detected that require running the full test suite."

.github/workflows/_build_torch_xla.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ on:
2020
type: number
2121
description: Timeout in minutes for the build job
2222
default: 120
23+
has_code_changes:
24+
required: false
25+
type: string
26+
description: Whether to run full workflow or not
27+
default: 'true'
2328
secrets:
2429
gcloud-service-key:
2530
required: true
@@ -39,27 +44,37 @@ jobs:
3944
# Need to check out local composite actions before using them
4045
# https://github.com/orgs/community/discussions/11771
4146
- name: Checkout actions
47+
if: inputs.has_code_changes == 'true'
4248
uses: actions/checkout@v4
4349
with:
4450
sparse-checkout: |
4551
.github/workflows/setup
4652
path: .actions
4753
- name: Setup
54+
if: inputs.has_code_changes == 'true'
4855
uses: ./.actions/.github/workflows/setup
4956
with:
5057
torch-commit: ${{ inputs.torch-commit }}
5158
- name: Build
59+
if: inputs.has_code_changes == 'true'
5260
shell: bash
5361
run: |
5462
cd pytorch/xla/infra/ansible
5563
ansible-playbook playbook.yaml -vvv -e "stage=build arch=amd64 accelerator=tpu src_root=${GITHUB_WORKSPACE} bundle_libtpu=0 build_cpp_tests=1 git_versioned_xla_build=1 cache_suffix=-ci" --skip-tags=fetch_srcs,install_deps
5664
- name: Upload wheel
65+
if: inputs.has_code_changes == 'true'
5766
uses: actions/upload-artifact@v4
5867
with:
5968
name: torch-xla-wheels
6069
path: /dist/*.whl
6170
- name: Upload CPP test binaries
71+
if: inputs.has_code_changes == 'true'
6272
uses: actions/upload-artifact@v4
6373
with:
6474
name: cpp-test-bin
6575
path: /tmp/test/bin
76+
- name: Report no code changes
77+
if: inputs.has_code_changes == 'false'
78+
run: |
79+
echo "No code changes were detected that require running the full test suite."
80+
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Check Code Changes
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
event_name:
7+
required: true
8+
type: string
9+
# For pull_request, base_sha is github.event.pull_request.base.sha (target branch tip)
10+
# For push, base_sha is github.event.before
11+
base_sha:
12+
required: true
13+
type: string
14+
# For pull_request, head_sha is github.event.pull_request.head.sha (PR branch tip)
15+
# For push, head_sha is github.sha
16+
head_sha:
17+
required: true
18+
type: string
19+
outputs:
20+
has_code_changes:
21+
description: "True if non-markdown code files were changed or event is workflow_dispatch/schedule, false otherwise."
22+
value: ${{ jobs.check_files.outputs.has_code_changes }}
23+
24+
jobs:
25+
check_files:
26+
runs-on: ubuntu-24.04
27+
outputs:
28+
has_code_changes: ${{ steps.perform_check.outputs.has_code_changes }}
29+
steps:
30+
- name: Checkout code for diff (if needed)
31+
# Checkout only if a diff is actually needed
32+
if: inputs.event_name != 'workflow_dispatch' && inputs.event_name != 'schedule'
33+
uses: actions/checkout@v4
34+
with:
35+
# Fetch all history for all branches and tags.
36+
# This is necessary for `git diff A...B` (three-dot diff) to find the merge base
37+
# and correctly diff PR changes against the point where it diverged.
38+
# It's also needed for `git diff A B` if A and B are far apart.
39+
fetch-depth: 0
40+
41+
- name: Perform file content check
42+
id: perform_check
43+
run: |
44+
echo "Event Name: ${{ inputs.event_name }}"
45+
echo "Base SHA input (for PR: target branch; for Push: before SHA): ${{ inputs.base_sha }}"
46+
echo "Head SHA input (for PR: PR head; for Push: current SHA): ${{ inputs.head_sha }}"
47+
48+
# Handle workflow_dispatch and schedule events first
49+
if [[ "${{ inputs.event_name }}" == "workflow_dispatch" || "${{ inputs.event_name }}" == "schedule" ]]; then
50+
echo "Event is ${{ inputs.event_name }}. Assuming code changes or full run needed."
51+
echo "has_code_changes=true" >> "$GITHUB_OUTPUT"
52+
exit 0 # Exit early, no diff needed
53+
fi
54+
55+
# Handle initial push (base SHA is all zeros)
56+
# For an initial push, all files in the head_sha are considered "changed" (new).
57+
if [[ "${{ inputs.base_sha }}" == "0000000000000000000000000000000000000000" ]]; then
58+
echo "Initial push (base SHA is zeros). Assuming code changes."
59+
# We can list all files in the current commit (inputs.head_sha) if needed,
60+
# but for simplicity, just assuming code changes is often sufficient.
61+
# To be precise, one could do: git ls-tree -r --name-only ${{ inputs.head_sha }} > changed_files.txt
62+
# And then apply the markdown filter. For now, we'll assume changes.
63+
echo "has_code_changes=true" >> "$GITHUB_OUTPUT"
64+
exit 0
65+
fi
66+
67+
# Handle cases where base and head are the same (e.g., re-run on a specific commit, or a push with no new commits)
68+
# This can happen if a workflow is re-run, or if a branch is pushed without new commits (e.g., force push to same SHA).
69+
if [[ "${{ inputs.base_sha }}" == "${{ inputs.head_sha }}" ]]; then
70+
echo "Base SHA is the same as Head SHA. No file changes. Assuming no code changes for skipping purposes."
71+
echo "has_code_changes=false" >> "$GITHUB_OUTPUT"
72+
exit 0
73+
fi
74+
75+
# Ensure SHAs are valid before attempting diff
76+
# (git rev-parse --verify will exit with non-zero if SHA is not found)
77+
git rev-parse --verify ${{ inputs.base_sha }}^{commit} >/dev/null 2>&1 || { echo "Error: Base SHA ${{ inputs.base_sha }} not found or invalid."; exit 1; }
78+
git rev-parse --verify ${{ inputs.head_sha }}^{commit} >/dev/null 2>&1 || { echo "Error: Head SHA ${{ inputs.head_sha }} not found or invalid."; exit 1; }
79+
80+
81+
# Determine the diff command based on the event type
82+
if [[ "${{ inputs.event_name }}" == "pull_request" ]]; then
83+
# For pull requests, use three-dot diff (A...B).
84+
# This shows changes on the PR branch (inputs.head_sha)
85+
# since it diverged from the target branch (inputs.base_sha).
86+
# inputs.base_sha is github.event.pull_request.base.sha
87+
# inputs.head_sha is github.event.pull_request.head.sha
88+
echo "Pull Request: Diffing ${{ inputs.base_sha }}...${{ inputs.head_sha }}"
89+
git diff --name-only --no-renames ${{ inputs.base_sha }}...${{ inputs.head_sha }} > changed_files.txt
90+
else # For 'push' and potentially other events not explicitly handled above
91+
# For pushes, use two-dot diff (A B).
92+
# inputs.base_sha is github.event.before
93+
# inputs.head_sha is github.sha
94+
echo "Push or other event: Diffing ${{ inputs.base_sha }} ${{ inputs.head_sha }}"
95+
git diff --name-only --no-renames ${{ inputs.base_sha }} ${{ inputs.head_sha }} > changed_files.txt
96+
fi
97+
98+
echo "Changed files:"
99+
cat changed_files.txt
100+
101+
if [ ! -s changed_files.txt ]; then # Check if changed_files.txt is empty
102+
echo "No files changed in the diff."
103+
echo "has_code_changes=false" >> "$GITHUB_OUTPUT"
104+
elif grep -q -v -E '\.md$' changed_files.txt; then
105+
echo "Non-markdown code changes detected."
106+
echo "has_code_changes=true" >> "$GITHUB_OUTPUT"
107+
else
108+
echo "Only markdown changes detected or no non-markdown changes found in diff."
109+
echo "has_code_changes=false" >> "$GITHUB_OUTPUT"
110+
fi
111+
shell: bash

.github/workflows/_docs.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
type: string
1212
description: Runner type for the test
1313
default: linux.4xlarge
14+
has_code_changes:
15+
required: false
16+
type: string
17+
description: Whether to run full workflow or not
18+
default: 'true'
1419
secrets:
1520
torchxla-bot-token:
1621
required: true
@@ -24,42 +29,50 @@ jobs:
2429
BRANCH_NAME: ${{ github.ref_name }}
2530
steps:
2631
- name: Fetch wheels
32+
if: inputs.has_code_changes == 'true'
2733
uses: actions/download-artifact@v4
2834
with:
2935
name: torch-xla-wheels
3036
path: /tmp/wheels/
3137
- name: Install wheels
38+
if: inputs.has_code_changes == 'true'
3239
shell: bash
3340
run: |
3441
pip install /tmp/wheels/*.whl
3542
- name: Checkout PyTorch/XLA Repo
43+
if: inputs.has_code_changes == 'true'
3644
uses: actions/checkout@v4
3745
with:
3846
path: pytorch/xla
3947
- name: Build docs
48+
if: inputs.has_code_changes == 'true'
4049
shell: bash
4150
run: |
4251
cd pytorch/xla/docs
4352
pip install -r requirements.txt
4453
sphinx-build -b html source build
4554
- name: Checkout GitHub Pages
55+
if: inputs.has_code_changes == 'true'
4656
uses: actions/checkout@v4
4757
with:
4858
path: gh-pages
4959
ref: gh-pages
5060
token: ${{ github.event_name == 'push' && secrets.torchxla-bot-token || github.token }}
5161
- name: Merge changes
62+
if: inputs.has_code_changes == 'true'
5263
shell: bash
5364
run: |
5465
subdir=${{ env.BRANCH_NAME == 'master' && 'master' || format('{0}/{1}', 'release', env.BRANCH_NAME) }}
5566
mkdir -p gh-pages/$subdir
5667
cp -fR pytorch/xla/docs/build/* gh-pages/$subdir
5768
- name: Upload preview as artifact
69+
if: inputs.has_code_changes == 'true'
5870
uses: actions/upload-artifact@v4
5971
with:
6072
name: github-pages
6173
path: pytorch/xla/docs/build/
6274
- name: Deploy
75+
if: inputs.has_code_changes == 'true' && github.event_name == 'push'
6376
shell: bash
6477
run: |
6578
cd gh-pages
@@ -68,4 +81,7 @@ jobs:
6881
git add . -v
6982
git diff --cached --exit-code || git commit -m "Update doc from commit ${{ github.sha }}"
7083
git push origin gh-pages
71-
if: github.event_name == 'push'
84+
- name: Report no code changes
85+
if: inputs.has_code_changes == 'false'
86+
run: |
87+
echo "No code changes were detected that require running the full test suite."

0 commit comments

Comments
 (0)