Skip to content

Commit 3d1062c

Browse files
authored
Use GH built-in runner for link check workflow (#17682)
Reduce the job time from 6 minutes to 10 seconds. Replace `pytorch/test-infra` reusable workflow + Docker image with direct `ubuntu-latest` runner for `_link_check.yml`. The lint scripts only need standard tools (`curl`, `jq`, `perl`, `git`, `grep`, `sed`) already on GH hosted runners. Saves server run hours and cost. - Switch all three jobs (`lint-urls`, `lint-xrefs`, `lint-file-size`) from `linux_job_v2.yml` + `executorch-ubuntu-22.04-linter` Docker image to `runs-on: ubuntu-latest` with `actions/checkout@v4` - Remove `id-token: write` permission (not needed; calling workflow doesn't grant it) - Replace `fetch-depth: 0` (full clone) with shallow checkout + targeted `git fetch --depth=1` of the base SHA - Replace three-dot (`...`) with two-dot (`..`) in `git diff` across `lint_urls.sh`, `lint_xrefs.sh`, `lint_file_size.sh` — direct base-to-head diff, no merge-base lookup needed
1 parent 7e1e6b4 commit 3d1062c

4 files changed

Lines changed: 88 additions & 64 deletions

File tree

.github/workflows/_link_check.yml

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,76 +8,100 @@ on:
88
jobs:
99
lint-urls:
1010
if: ${{ github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'skip-url-lint') }}
11-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
12-
with:
13-
runner: linux.2xlarge
14-
docker-image: ci-image:executorch-ubuntu-22.04-linter
15-
submodules: false
16-
fetch-depth: 0
17-
ref: ${{ inputs.ref }}
18-
timeout: 120
19-
script: |
20-
./scripts/lint_urls.sh $(
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
timeout-minutes: 120
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
ref: ${{ inputs.ref }}
19+
- name: Fetch base ref
20+
run: |
2121
if [ "${{ github.event_name }}" = "pull_request" ]; then
22-
echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}"
22+
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
2323
else
24-
echo "${{ github.event.before }}" "${{ github.sha }}"
24+
git fetch --no-tags --depth=1 origin "${{ github.event.before }}"
2525
fi
26-
) || {
27-
echo
28-
echo "URL lint failed."
29-
echo "If this is a transient outage, you can bypass it by adding the \`skip-url-lint\` label to your PR."
30-
echo "Or add \`@lint-ignore\` somewhere on the same line as the URL you want to skip checking."
31-
exit 1
32-
}
26+
- name: Lint URLs
27+
run: |
28+
./scripts/lint_urls.sh $(
29+
if [ "${{ github.event_name }}" = "pull_request" ]; then
30+
echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}"
31+
else
32+
echo "${{ github.event.before }}" "${{ github.sha }}"
33+
fi
34+
) || {
35+
echo
36+
echo "URL lint failed."
37+
echo "If this is a transient outage, you can bypass it by adding the \`skip-url-lint\` label to your PR."
38+
echo "Or add \`@lint-ignore\` somewhere on the same line as the URL you want to skip checking."
39+
exit 1
40+
}
3341
3442
lint-xrefs:
3543
if: ${{ github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'skip-xref-lint') }}
36-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
37-
with:
38-
runner: linux.2xlarge
39-
docker-image: ci-image:executorch-ubuntu-22.04-linter
40-
submodules: false
41-
fetch-depth: 0
42-
ref: ${{ inputs.ref }}
43-
timeout: 60
44-
script: |
45-
./scripts/lint_xrefs.sh $(
44+
runs-on: ubuntu-latest
45+
permissions:
46+
contents: read
47+
timeout-minutes: 60
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
ref: ${{ inputs.ref }}
52+
- name: Fetch base ref
53+
run: |
4654
if [ "${{ github.event_name }}" = "pull_request" ]; then
47-
echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}"
55+
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
4856
else
49-
echo "${{ github.event.before }}" "${{ github.sha }}"
57+
git fetch --no-tags --depth=1 origin "${{ github.event.before }}"
5058
fi
51-
) || {
52-
echo
53-
echo "Xref lint failed."
54-
echo "If this is a transient outage, you can bypass it by adding the \`skip-xref-lint\` label to your PR."
55-
echo "Or add \`@lint-ignore\` somewhere on the same line as the reference you want to skip checking."
56-
exit 1
57-
}
59+
- name: Lint cross-references
60+
run: |
61+
./scripts/lint_xrefs.sh $(
62+
if [ "${{ github.event_name }}" = "pull_request" ]; then
63+
echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}"
64+
else
65+
echo "${{ github.event.before }}" "${{ github.sha }}"
66+
fi
67+
) || {
68+
echo
69+
echo "Xref lint failed."
70+
echo "If this is a transient outage, you can bypass it by adding the \`skip-xref-lint\` label to your PR."
71+
echo "Or add \`@lint-ignore\` somewhere on the same line as the reference you want to skip checking."
72+
exit 1
73+
}
5874
5975
lint-file-size:
6076
if: ${{ github.event_name == 'pull_request' }}
61-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
62-
with:
63-
runner: linux.2xlarge
64-
docker-image: ci-image:executorch-ubuntu-22.04-linter
65-
submodules: false
66-
fetch-depth: 0
67-
ref: ${{ inputs.ref }}
68-
timeout: 30
69-
script: |
70-
chmod +x ./scripts/lint_file_size.sh
71-
./scripts/lint_file_size.sh $(
77+
runs-on: ubuntu-latest
78+
permissions:
79+
contents: read
80+
timeout-minutes: 30
81+
steps:
82+
- uses: actions/checkout@v4
83+
with:
84+
ref: ${{ inputs.ref }}
85+
- name: Fetch base ref
86+
run: |
7287
if [ "${{ github.event_name }}" = "pull_request" ]; then
73-
echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}"
88+
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
7489
else
75-
echo "${{ github.event.before }}" "${{ github.sha }}"
90+
git fetch --no-tags --depth=1 origin "${{ github.event.before }}"
7691
fi
77-
) || {
78-
echo
79-
echo "File size lint failed: some files exceed the 1 MB limit."
80-
echo "If you really need large files, consider using Git LFS or storing them elsewhere."
81-
echo "If you really need to get unblocked and check in the file, can add it to the EXCEPTIONS list in scripts/lint_file_size.sh."
82-
exit 1
83-
}
92+
- name: Lint file sizes
93+
run: |
94+
chmod +x ./scripts/lint_file_size.sh
95+
./scripts/lint_file_size.sh $(
96+
if [ "${{ github.event_name }}" = "pull_request" ]; then
97+
echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}"
98+
else
99+
echo "${{ github.event.before }}" "${{ github.sha }}"
100+
fi
101+
) || {
102+
echo
103+
echo "File size lint failed: some files exceed the 1 MB limit."
104+
echo "If you really need large files, consider using Git LFS or storing them elsewhere."
105+
echo "If you really need to get unblocked and check in the file, can add it to the EXCEPTIONS list in scripts/lint_file_size.sh."
106+
exit 1
107+
}

scripts/lint_file_size.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ is_exception() {
4040
if [ $# -eq 2 ]; then
4141
base=$1
4242
head=$2
43-
echo "Checking changed files between $base...$head"
44-
files=$(git diff --name-only "$base...$head")
43+
echo "Checking changed files between $base..$head"
44+
files=$(git diff --name-only "$base..$head")
4545
else
4646
echo "Checking all files in repository"
4747
files=$(git ls-files)

scripts/lint_urls.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ done < <(
7979
':(exclude,glob)**/third_party/**'
8080
)
8181
if [ $# -eq 2 ]; then
82-
for filename in $(git diff --name-only --unified=0 "$1...$2"); do
83-
git diff --unified=0 "$1...$2" -- "$filename" "${excludes[@]}" \
82+
for filename in $(git diff --name-only --unified=0 "$1..$2"); do
83+
git diff --unified=0 "$1..$2" -- "$filename" "${excludes[@]}" \
8484
| grep -E '^\+' \
8585
| grep -Ev '^\+\+\+' \
8686
| perl -nle 'print for m#'"$pattern"'#g' \

scripts/lint_xrefs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ done < <(
3535
':(exclude,glob)**/third_party/**'
3636
)
3737
if [ $# -eq 2 ]; then
38-
for filename in $(git diff --name-only --unified=0 "$1...$2"); do
39-
git diff --unified=0 "$1...$2" -- "$filename" "${excludes[@]}" \
38+
for filename in $(git diff --name-only --unified=0 "$1..$2"); do
39+
git diff --unified=0 "$1..$2" -- "$filename" "${excludes[@]}" \
4040
| grep -E '^\+' \
4141
| grep -Ev '^\+\+\+' \
4242
| perl -nle 'print for m#'"$pattern"'#g' \

0 commit comments

Comments
 (0)