Skip to content

Setup GHA repository cache. #4

Setup GHA repository cache.

Setup GHA repository cache. #4

name: build-torch-xla

Check failure on line 1 in .github/workflows/_build_torch_xla.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/_build_torch_xla.yml

Invalid workflow file

(Line: 57, Col: 24): Unexpected symbol: '"WORKSPACE"'. Located at position 11 within expression: hashFiles("WORKSPACE")
on:
workflow_call:
inputs:
dev-image:
required: true
type: string
description: Base image for builds
runner:
required: false
type: string
description: Runner type for the test
default: linux.12xlarge
timeout-minutes:
required: false
type: number
description: Timeout in minutes for the build job
default: 45 # Takes ~20m as of 2025/5/30.
has_code_changes:
required: false
type: string
description: Whether to run full workflow or not
default: "true"
secrets:
gcloud-service-key:
required: true
description: Secret to access Bazel build cache
jobs:
build:
runs-on: ${{ inputs.runner }}
timeout-minutes: ${{ inputs.timeout-minutes }}
container:
image: ${{ inputs.dev-image }}
env:
GCLOUD_SERVICE_KEY: ${{ secrets.gcloud-service-key }}
BAZEL_REMOTE_CACHE: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
BAZEL_JOBS: "" # Let bazel decide the parallelism based on the number of CPUs.
BAZEL_REPOSITORY_CACHE_RELATIVE_DIR: ".cache/repository-cache"
BUILD_CPP_TESTS: 1
steps:
# 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
- name: "Cache: Bazel Repository Cache"
uses: actions/cache@v4
with:
key: bazel-repository-cache-${{ hashFiles("WORKSPACE") }}
path: ${{ env.BAZEL_REPOSITORY_CACHE_RELATIVE_DIR }}
enableCrossOsArchive: true
- name: Build
if: inputs.has_code_changes == 'true'
env:
# Actual environment variable that is read by our build_utils.py for setting
# the repository cache. Since we will be changing directories, we need to
# provide the absolute path.
BAZEL_REPOSITORY_CACHE_DIR: "${{ github.workspace }}/${{ env.BAZEL_REPOSITORY_CACHE_RELATIVE_DIR }}"
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."