Skip to content

Commit eb1099e

Browse files
authored
Improve lintrunner job runtime (#14240)
lintrunner is required to land, but it takes 10-15 minutes. This seems to improve on that by: - split out lintrunner-mypy job - copy pytorch/pytorch's changed files tracking - don't run `lintrunner init` unnecessarily
1 parent bd653ba commit eb1099e

File tree

2 files changed

+112
-7
lines changed

2 files changed

+112
-7
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Get Changed Files
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
changed-files:
7+
description: "List of changed files (space-separated) or '*' if not in a PR"
8+
value: ${{ jobs.get-changed-files.outputs.changed-files }}
9+
10+
jobs:
11+
get-changed-files:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
changed-files: ${{ steps.get-files.outputs.changed-files }}
15+
16+
steps:
17+
- name: Get changed files
18+
id: get-files
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
run: |
22+
# Check if we're in a pull request context
23+
if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event_name }}" = "pull_request_target" ]; then
24+
echo "Running in PR context"
25+
26+
# Get the PR number from the github context
27+
PR_NUMBER="${{ github.event.number }}"
28+
29+
# Use gh CLI to get changed files in the PR with explicit repo
30+
CHANGED_FILES=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files --paginate --jq '.[] | select(.status != "removed") | .filename' | tr '\n' ' ' | sed 's/ $//')
31+
32+
if [ -z "$CHANGED_FILES" ]; then
33+
echo "No changed files found, setting to '*'"
34+
CHANGED_FILES="*"
35+
fi
36+
37+
echo "Changed files: $CHANGED_FILES"
38+
echo "changed-files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
39+
40+
else
41+
echo "Not in PR context, setting changed files to '*'"
42+
echo "changed-files=*" >> "$GITHUB_OUTPUT"
43+
fi

.github/workflows/lint.yml

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,27 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18-
lintrunner:
18+
get-changed-files:
19+
if: github.repository_owner == 'pytorch'
20+
name: Get changed files
21+
uses: ./.github/workflows/_get-changed-files.yml
22+
23+
lintrunner-mypy:
1924
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
25+
needs: [get-changed-files]
2026
permissions:
2127
id-token: write
2228
contents: read
29+
if: |
30+
github.repository_owner == 'pytorch' && (
31+
needs.get-changed-files.outputs.changed-files == '*' ||
32+
contains(needs.get-changed-files.outputs.changed-files, '.py') ||
33+
contains(needs.get-changed-files.outputs.changed-files, '.pyi')
34+
)
2335
with:
2436
runner: linux.2xlarge
2537
docker-image: ci-image:executorch-ubuntu-22.04-linter
26-
submodules: 'recursive'
38+
submodules: true
2739
fetch-depth: 0
2840
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
2941
timeout: 90
@@ -45,14 +57,64 @@ jobs:
4557
cp -r "${CACHE_DIRECTORY}" . || true
4658
fi
4759
48-
# This has already been cached in the docker image
49-
lintrunner init
60+
RC=0
61+
# Run lintrunner on all files. pytorch/pytorch notes that mypy
62+
# in particular needs this.
63+
if ! lintrunner --force-color --all-files --take MYPY --tee-json=lint.json 2> /dev/null; then
64+
echo ""
65+
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner --take MYPY\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
66+
echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
67+
RC=1
68+
fi
69+
70+
# Use jq to massage the JSON lint output into GitHub Actions workflow commands.
71+
jq --raw-output \
72+
'"::\(if .severity == "advice" or .severity == "disabled" then "warning" else .severity end) file=\(.path),line=\(.line),col=\(.char),title=\(.code) \(.name)::" + (.description | gsub("\\n"; "%0A"))' \
73+
lint.json || true
74+
75+
exit $RC
76+
77+
lintrunner:
78+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
79+
needs: [get-changed-files]
80+
permissions:
81+
id-token: write
82+
contents: read
83+
with:
84+
runner: linux.2xlarge
85+
docker-image: ci-image:executorch-ubuntu-22.04-linter
86+
submodules: false
87+
fetch-depth: 0
88+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
89+
timeout: 90
90+
script: |
91+
# The generic Linux job chooses to use base env, not the one setup by the image
92+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
93+
conda activate "${CONDA_ENV}"
94+
95+
# Not sure why this isn't set up in the docker
96+
# image. lintrunner-mypy seems to work becaus setup-linux.sh
97+
# does this as part of install_executorch.
98+
pip install -r requirements-dev.txt
99+
100+
CACHE_DIRECTORY="/tmp/.lintbin"
101+
# Try to recover the cached binaries
102+
if [[ -d "${CACHE_DIRECTORY}" ]]; then
103+
# It's ok to fail this as lintrunner init would download these binaries
104+
# again if they do not exist
105+
cp -r "${CACHE_DIRECTORY}" . || true
106+
fi
50107
51108
RC=0
52-
# Run lintrunner on all files
53-
if ! lintrunner --force-color --all-files --tee-json=lint.json 2> /dev/null; then
109+
CHANGED_FILES="${{ needs.get-changed-files.outputs.changed-files }}"
110+
if [ "$CHANGED_FILES" = '*' ]; then
111+
LINTRUNNER_FILES="--all-files"
112+
else
113+
LINTRUNNER_FILES="${CHANGED_FILES}"
114+
fi
115+
if ! lintrunner --force-color ${LINTRUNNER_FILES} --skip MYPY --tee-json=lint.json 2> /dev/null; then
54116
echo ""
55-
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
117+
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner --skip MYPY\`. (If you don't get the same results, run \'lintrunner init\' to update your local linter)\e[0m"
56118
echo -e "\e[1m\e[36mSee https://github.com/pytorch/pytorch/wiki/lintrunner for setup instructions.\e[0m"
57119
RC=1
58120
fi

0 commit comments

Comments
 (0)