Skip to content

Disable running slow CI for doc-only changes #9072

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

Merged
merged 17 commits into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/_build_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ on:
type: number
description: Timeout in minutes for the build job
default: 120
has_code_changes:
required: false
type: string
description: Whether to run full workflow or not
default: 'true'
secrets:
gcloud-service-key:
required: true
Expand All @@ -32,23 +37,31 @@ jobs:
BAZEL_REMOTE_CACHE: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- name: Checkout actions
if: inputs.has_code_changes == 'true'
uses: actions/checkout@v4
with:
sparse-checkout: |
.github/workflows/setup
path: .actions
- name: Setup
if: inputs.has_code_changes == 'true'
uses: ./.actions/.github/workflows/setup
with:
torch-commit: ${{ inputs.torch-commit }}
cuda: true
- name: Build
if: inputs.has_code_changes == 'true'
shell: bash
run: |
cd pytorch/xla/infra/ansible
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
- name: Upload wheel
if: inputs.has_code_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: cuda-plugin
path: /dist/*.whl
- name: Report no code changes
if: inputs.has_code_changes == 'false'
run: |
echo "No code changes were detected that require running the full test suite."
13 changes: 13 additions & 0 deletions .github/workflows/_build_torch_with_cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ on:
type: number
description: Timeout in minutes for the build job
default: 120
has_code_changes:
required: false
type: string
description: Whether to run full workflow or not
default: 'true'
jobs:
build:
runs-on: ${{ inputs.runner }}
Expand All @@ -33,23 +38,31 @@ jobs:
MAX_JOBS: 24
steps:
- name: Checkout actions
if: inputs.has_code_changes == 'true'
uses: actions/checkout@v4
with:
sparse-checkout: |
.github/workflows/setup
path: .actions
- name: Setup
if: inputs.has_code_changes == 'true'
uses: ./.actions/.github/workflows/setup
with:
torch-commit: ${{ inputs.torch-commit }}
cuda: true
- name: Build PyTorch with CUDA enabled
if: inputs.has_code_changes == 'true'
shell: bash
run: |
cd pytorch
python setup.py bdist_wheel
- name: Upload wheel
if: inputs.has_code_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: torch-with-cuda
path: pytorch/dist/*.whl
- name: Report no code changes
if: inputs.has_code_changes == 'false'
run: |
echo "No code changes were detected that require running the full test suite."
15 changes: 15 additions & 0 deletions .github/workflows/_build_torch_xla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ on:
type: number
description: Timeout in minutes for the build job
default: 120
has_code_changes:
required: false
type: string
description: Whether to run full workflow or not
default: 'true'
secrets:
gcloud-service-key:
required: true
Expand All @@ -39,27 +44,37 @@ jobs:
# Need to check out local composite actions before using them
# https://github.com/orgs/community/discussions/11771
- name: Checkout actions
if: inputs.has_code_changes == 'true'
uses: actions/checkout@v4
with:
sparse-checkout: |
.github/workflows/setup
path: .actions
- name: Setup
if: inputs.has_code_changes == 'true'
uses: ./.actions/.github/workflows/setup
with:
torch-commit: ${{ inputs.torch-commit }}
- name: Build
if: inputs.has_code_changes == 'true'
shell: bash
run: |
cd pytorch/xla/infra/ansible
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
- name: Upload wheel
if: inputs.has_code_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: torch-xla-wheels
path: /dist/*.whl
- name: Upload CPP test binaries
if: inputs.has_code_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: cpp-test-bin
path: /tmp/test/bin
- name: Report no code changes
if: inputs.has_code_changes == 'false'
run: |
echo "No code changes were detected that require running the full test suite."

111 changes: 111 additions & 0 deletions .github/workflows/_check_code_changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Check Code Changes

on:
workflow_call:
inputs:
event_name:
required: true
type: string
# For pull_request, base_sha is github.event.pull_request.base.sha (target branch tip)
# For push, base_sha is github.event.before
base_sha:
required: true
type: string
# For pull_request, head_sha is github.event.pull_request.head.sha (PR branch tip)
# For push, head_sha is github.sha
head_sha:
required: true
type: string
outputs:
has_code_changes:
description: "True if non-markdown code files were changed or event is workflow_dispatch/schedule, false otherwise."
value: ${{ jobs.check_files.outputs.has_code_changes }}

jobs:
check_files:
runs-on: ubuntu-24.04
outputs:
has_code_changes: ${{ steps.perform_check.outputs.has_code_changes }}
steps:
- name: Checkout code for diff (if needed)
# Checkout only if a diff is actually needed
if: inputs.event_name != 'workflow_dispatch' && inputs.event_name != 'schedule'
uses: actions/checkout@v4
with:
# Fetch all history for all branches and tags.
# This is necessary for `git diff A...B` (three-dot diff) to find the merge base
# and correctly diff PR changes against the point where it diverged.
# It's also needed for `git diff A B` if A and B are far apart.
fetch-depth: 0

- name: Perform file content check
id: perform_check
run: |
echo "Event Name: ${{ inputs.event_name }}"
echo "Base SHA input (for PR: target branch; for Push: before SHA): ${{ inputs.base_sha }}"
echo "Head SHA input (for PR: PR head; for Push: current SHA): ${{ inputs.head_sha }}"

# Handle workflow_dispatch and schedule events first
if [[ "${{ inputs.event_name }}" == "workflow_dispatch" || "${{ inputs.event_name }}" == "schedule" ]]; then
echo "Event is ${{ inputs.event_name }}. Assuming code changes or full run needed."
echo "has_code_changes=true" >> "$GITHUB_OUTPUT"
exit 0 # Exit early, no diff needed
fi

# Handle initial push (base SHA is all zeros)
# For an initial push, all files in the head_sha are considered "changed" (new).
if [[ "${{ inputs.base_sha }}" == "0000000000000000000000000000000000000000" ]]; then
echo "Initial push (base SHA is zeros). Assuming code changes."
# We can list all files in the current commit (inputs.head_sha) if needed,
# but for simplicity, just assuming code changes is often sufficient.
# To be precise, one could do: git ls-tree -r --name-only ${{ inputs.head_sha }} > changed_files.txt
# And then apply the markdown filter. For now, we'll assume changes.
echo "has_code_changes=true" >> "$GITHUB_OUTPUT"
exit 0
fi

# Handle cases where base and head are the same (e.g., re-run on a specific commit, or a push with no new commits)
# 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).
if [[ "${{ inputs.base_sha }}" == "${{ inputs.head_sha }}" ]]; then
echo "Base SHA is the same as Head SHA. No file changes. Assuming no code changes for skipping purposes."
echo "has_code_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi

# Ensure SHAs are valid before attempting diff
# (git rev-parse --verify will exit with non-zero if SHA is not found)
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; }
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; }


# Determine the diff command based on the event type
if [[ "${{ inputs.event_name }}" == "pull_request" ]]; then
# For pull requests, use three-dot diff (A...B).
# This shows changes on the PR branch (inputs.head_sha)
# since it diverged from the target branch (inputs.base_sha).
# inputs.base_sha is github.event.pull_request.base.sha
# inputs.head_sha is github.event.pull_request.head.sha
echo "Pull Request: Diffing ${{ inputs.base_sha }}...${{ inputs.head_sha }}"
git diff --name-only --no-renames ${{ inputs.base_sha }}...${{ inputs.head_sha }} > changed_files.txt
else # For 'push' and potentially other events not explicitly handled above
# For pushes, use two-dot diff (A B).
# inputs.base_sha is github.event.before
# inputs.head_sha is github.sha
echo "Push or other event: Diffing ${{ inputs.base_sha }} ${{ inputs.head_sha }}"
git diff --name-only --no-renames ${{ inputs.base_sha }} ${{ inputs.head_sha }} > changed_files.txt
fi

echo "Changed files:"
cat changed_files.txt

if [ ! -s changed_files.txt ]; then # Check if changed_files.txt is empty
echo "No files changed in the diff."
echo "has_code_changes=false" >> "$GITHUB_OUTPUT"
elif grep -q -v -E '\.md$' changed_files.txt; then
echo "Non-markdown code changes detected."
echo "has_code_changes=true" >> "$GITHUB_OUTPUT"
else
echo "Only markdown changes detected or no non-markdown changes found in diff."
echo "has_code_changes=false" >> "$GITHUB_OUTPUT"
fi
shell: bash
18 changes: 17 additions & 1 deletion .github/workflows/_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
type: string
description: Runner type for the test
default: linux.4xlarge
has_code_changes:
required: false
type: string
description: Whether to run full workflow or not
default: 'true'
secrets:
torchxla-bot-token:
required: true
Expand All @@ -24,42 +29,50 @@ jobs:
BRANCH_NAME: ${{ github.ref_name }}
steps:
- name: Fetch wheels
if: inputs.has_code_changes == 'true'
uses: actions/download-artifact@v4
with:
name: torch-xla-wheels
path: /tmp/wheels/
- name: Install wheels
if: inputs.has_code_changes == 'true'
shell: bash
run: |
pip install /tmp/wheels/*.whl
- name: Checkout PyTorch/XLA Repo
if: inputs.has_code_changes == 'true'
uses: actions/checkout@v4
with:
path: pytorch/xla
- name: Build docs
if: inputs.has_code_changes == 'true'
shell: bash
run: |
cd pytorch/xla/docs
pip install -r requirements.txt
sphinx-build -b html source build
- name: Checkout GitHub Pages
if: inputs.has_code_changes == 'true'
uses: actions/checkout@v4
with:
path: gh-pages
ref: gh-pages
token: ${{ github.event_name == 'push' && secrets.torchxla-bot-token || github.token }}
- name: Merge changes
if: inputs.has_code_changes == 'true'
shell: bash
run: |
subdir=${{ env.BRANCH_NAME == 'master' && 'master' || format('{0}/{1}', 'release', env.BRANCH_NAME) }}
mkdir -p gh-pages/$subdir
cp -fR pytorch/xla/docs/build/* gh-pages/$subdir
- name: Upload preview as artifact
if: inputs.has_code_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: github-pages
path: pytorch/xla/docs/build/
- name: Deploy
if: inputs.has_code_changes == 'true' && github.event_name == 'push'
shell: bash
run: |
cd gh-pages
Expand All @@ -68,4 +81,7 @@ jobs:
git add . -v
git diff --cached --exit-code || git commit -m "Update doc from commit ${{ github.sha }}"
git push origin gh-pages
if: github.event_name == 'push'
- name: Report no code changes
if: inputs.has_code_changes == 'false'
run: |
echo "No code changes were detected that require running the full test suite."
Loading