Compare commits

...

8 Commits

Author SHA1 Message Date
0faebd38ba tc 2025-10-16 12:46:29 -07:00
195c4ea8d7 tc 2025-10-16 11:32:11 -07:00
764e715b0a tc 2025-10-16 11:20:36 -07:00
55853de122 tc 2025-10-16 10:49:02 -07:00
f0a9e15fd6 tc 2025-10-16 10:29:42 -07:00
21d3a579a7 tc 2025-10-16 10:25:02 -07:00
6eb66a117b tc 2025-10-16 10:22:03 -07:00
031e486fd4 tc 2025-10-16 10:20:46 -07:00
3 changed files with 103 additions and 95 deletions

View File

@ -0,0 +1,63 @@
name: Get changed files
description: >-
Returns a space-separated list of changed files for a PR, or '*' when not in a PR.
Mirrors the logic from the original workflow but packaged as a reusable composite action.
inputs:
all_files:
description: 'Whether to return all files instead of just changed files'
required: false
default: 'false'
outputs:
changed-files:
description: "List of changed files (space-separated) or '*' if not in a PR"
value: ${{ steps.get-files.outputs.changed-files }}
runs:
using: composite
steps:
- id: get-files
name: Get changed files (bash)
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
# Call the bundled entrypoint script. Running via bash avoids needing execute bit set.
# Check if we're in a pull request context
if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event_name }}" = "pull_request_target" ]; then
echo "Running in PR context"
# Get the PR number from the github context
PR_NUMBER="${{ github.event.number }}"
# Check if all_files is requested
if [ "${{ inputs.all_files }}" = "true" ]; then
echo "all_files input is true, returning all files"
echo "changed-files=*" >> "$GITHUB_OUTPUT"
else
# Use gh CLI to get changed files in the PR with explicit repo
CHANGED_FILES=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files --paginate --jq '.[] | select(.status != "removed") | .filename' | tr '\n' ' ' | sed 's/ $//')
# See https://github.com/pytorch/pytorch/pull/134215#issuecomment-2332128790
PYI_FILES_TO_ADD=""
for file in ${CHANGED_FILES}; do
if [[ "${file}" == *".pyi.in" ]]; then
PYI_FILES_TO_ADD="${PYI_FILES_TO_ADD} ${file//.in/}"
fi
done
CHANGED_FILES="${CHANGED_FILES}${PYI_FILES_TO_ADD}"
if [ -z "$CHANGED_FILES" ]; then
echo "No changed files found, setting to '*'"
CHANGED_FILES="*"
fi
echo "Changed files: $CHANGED_FILES"
echo "changed-files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
fi
else
echo "Not in PR context, setting changed files to '*'"
echo "changed-files=*" >> "$GITHUB_OUTPUT"
fi

View File

@ -1,64 +0,0 @@
name: Get Changed Files
on:
workflow_call:
inputs:
all_files:
description: "Whether to return all files instead of just changed files"
required: false
type: boolean
default: false
outputs:
changed-files:
description: "List of changed files (space-separated) or '*' if not in a PR"
value: ${{ jobs.get-changed-files.outputs.changed-files }}
jobs:
get-changed-files:
runs-on: ubuntu-latest
outputs:
changed-files: ${{ steps.get-files.outputs.changed-files }}
steps:
- name: Get changed files
id: get-files
env:
GH_TOKEN: ${{ github.token }}
run: |
# Check if we're in a pull request context
if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event_name }}" = "pull_request_target" ]; then
echo "Running in PR context"
# Get the PR number from the github context
PR_NUMBER="${{ github.event.number }}"
# Check if all_files is requested
if [ "${{ inputs.all_files }}" = "true" ]; then
echo "all_files input is true, returning all files"
echo "changed-files=*" >> "$GITHUB_OUTPUT"
else
# Use gh CLI to get changed files in the PR with explicit repo
CHANGED_FILES=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files --paginate --jq '.[] | select(.status != "removed") | .filename' | tr '\n' ' ' | sed 's/ $//')
# See https://github.com/pytorch/pytorch/pull/134215#issuecomment-2332128790
PYI_FILES_TO_ADD=""
for file in ${CHANGED_FILES}; do
if [[ "${file}" == *".pyi.in" ]]; then
PYI_FILES_TO_ADD="${PYI_FILES_TO_ADD} ${file//.in/}"
fi
done
CHANGED_FILES="${CHANGED_FILES}${PYI_FILES_TO_ADD}"
if [ -z "$CHANGED_FILES" ]; then
echo "No changed files found, setting to '*'"
CHANGED_FILES="*"
fi
echo "Changed files: $CHANGED_FILES"
echo "changed-files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
fi
else
echo "Not in PR context, setting changed files to '*'"
echo "changed-files=*" >> "$GITHUB_OUTPUT"
fi

View File

@ -12,7 +12,6 @@ on:
- landchecks/*
tags:
- ciflow/pull/*
- ciflow/trunk/*
workflow_dispatch:
permissions: read-all
@ -31,30 +30,36 @@ jobs:
get-changed-files:
if: github.repository_owner == 'pytorch'
name: Get changed files
uses: ./.github/workflows/_get-changed-files.yml
with:
all_files: ${{ contains(github.event.pull_request.labels.*.name, 'lint-all-files') || contains(github.event.pull_request.labels.*.name, 'Reverted') || github.event_name == 'push' }}
runs-on: ubuntu-latest
outputs:
changed-files-matrix: ${{ steps.output-test-matrix.outputs.changed-files-matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: false
- name: Get changed files
id: get-changed-files
uses: ./.github/actions/get-changed-files
with:
all_files: ${{ contains(github.event.pull_request.labels.*.name, 'lint-all-files') || contains(github.event.pull_request.labels.*.name, 'Reverted') || github.event_name == 'push' }}
- name: Output test-matrix
id: output-test-matrix
run: |
set -euox pipefail
MATRIX=$(jq -n '[{"changed-files": "${{ steps.get-changed-files.outputs.changed-files }}"}, {"changed-files": "*"}]' | jq -c 'unique')
echo "changed-files-matrix={\"include\":$MATRIX}" >> "$GITHUB_OUTPUT"
lintrunner-clang:
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
# Needed to prevent deduping on HUD
name: lintrunner-clang-${{ needs.get-changed-files.outputs.changed-files == '*' && 'all' || 'partial' }}
name: lintrunner-clang-${{ matrix.changed-files == '*' && 'all' || 'partial' }}
needs: [get-label-type, get-changed-files]
strategy:
matrix: ${{ fromJson(needs.get-changed-files.outputs.changed-files-matrix) }}
# Only run if there are changed files relevant to clangtidy / clangformat
if: |
github.repository_owner == 'pytorch' && (
needs.get-changed-files.outputs.changed-files == '*' ||
contains(needs.get-changed-files.outputs.changed-files, '.h') ||
contains(needs.get-changed-files.outputs.changed-files, '.cpp') ||
contains(needs.get-changed-files.outputs.changed-files, '.cc') ||
contains(needs.get-changed-files.outputs.changed-files, '.cxx') ||
contains(needs.get-changed-files.outputs.changed-files, '.hpp') ||
contains(needs.get-changed-files.outputs.changed-files, '.hxx') ||
contains(needs.get-changed-files.outputs.changed-files, '.cu') ||
contains(needs.get-changed-files.outputs.changed-files, '.cuh') ||
contains(needs.get-changed-files.outputs.changed-files, '.mm') ||
contains(needs.get-changed-files.outputs.changed-files, '.metal')
)
if: github.repository_owner == 'pytorch'
with:
timeout: 120
runner: "${{ needs.get-label-type.outputs.label-type }}linux.2xlarge"
@ -65,7 +70,7 @@ jobs:
submodules: true
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
script: |
CHANGED_FILES="${{ needs.get-changed-files.outputs.changed-files }}"
CHANGED_FILES="${{ matrix.changed-files }}"
if [ "$CHANGED_FILES" = "*" ]; then
export ADDITIONAL_LINTRUNNER_ARGS="--take CLANGTIDY,CLANGFORMAT --all-files"
else
@ -78,15 +83,12 @@ jobs:
# fails to find types when it should
lintrunner-mypy:
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
name: lintrunner-mypy-${{ needs.get-changed-files.outputs.changed-files == '*' && 'all' || 'partial' }}
name: lintrunner-mypy-${{ matrix.changed-files == '*' && 'all' || 'partial' }}
needs: [get-label-type, get-changed-files]
# Only run if there are changed files relevant to mypy
if: |
github.repository_owner == 'pytorch' && (
needs.get-changed-files.outputs.changed-files == '*' ||
contains(needs.get-changed-files.outputs.changed-files, '.py') ||
contains(needs.get-changed-files.outputs.changed-files, '.pyi')
)
if: github.repository_owner == 'pytorch'
strategy:
matrix: ${{ fromJson(needs.get-changed-files.outputs.changed-files-matrix) }}
with:
timeout: 120
runner: "${{ needs.get-label-type.outputs.label-type }}linux.2xlarge"
@ -97,13 +99,20 @@ jobs:
submodules: true
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
script: |
CHANGED_FILES="${{ needs.get-changed-files.outputs.changed-files }}"
echo "Running mypy"
ADDITIONAL_LINTRUNNER_ARGS="--take MYPY,MYPYSTRICT --all-files" .github/scripts/lintrunner.sh
CHANGED_FILES="${{ matrix.changed-files }}"
if [[ "$CHANGED_FILES" == *".py"* || "$CHANGED_FILES" == "*" ]]; then
ADDITIONAL_LINTRUNNER_ARGS="--take MYPY,MYPYSTRICT --all-files" .github/scripts/lintrunner.sh
else
echo "No .py files changed, skipping mypy"
fi
lintrunner-noclang:
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
name: lintrunner-noclang-${{ needs.get-changed-files.outputs.changed-files == '*' && 'all' || 'partial' }}
strategy:
matrix: ${{ fromJson(needs.get-changed-files.outputs.changed-files-matrix) }}
name: lintrunner-noclang-${{ matrix.changed-files == '*' && 'all' || 'partial' }}
needs: [get-label-type, get-changed-files]
with:
timeout: 120
@ -115,7 +124,7 @@ jobs:
submodules: true
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
script: |
CHANGED_FILES="${{ needs.get-changed-files.outputs.changed-files }}"
CHANGED_FILES="${{ matrix.changed-files }}"
echo "Running all other linters"
if [ "$CHANGED_FILES" = '*' ]; then
ADDITIONAL_LINTRUNNER_ARGS="--skip CLANGTIDY,CLANGFORMAT,MYPY,MYPYSTRICT --all-files" .github/scripts/lintrunner.sh