Skip to content

Commit 18b2445

Browse files
committed
Merge branch 't3/ci-merge-small-jobs' into t3/ci-sticky-deps
2 parents d2aa97b + 3d2ff9d commit 18b2445

2 files changed

Lines changed: 19 additions & 39 deletions

File tree

‎.github/actions/ci-changes/action.yml‎

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ runs:
2525
- id: detect
2626
shell: bash
2727
env:
28-
GH_TOKEN: ${{ github.token }}
29-
PR_NUMBER: ${{ github.event.pull_request.number }}
28+
EVENT_NAME: ${{ github.event_name }}
3029
BEFORE_SHA: ${{ github.event.before }}
3130
run: |
3231
set -uo pipefail
@@ -41,41 +40,24 @@ runs:
4140
decide
4241
}
4342
44-
count_rows() {
45-
printf '%s\n' "$1" | grep -c . || true
46-
}
47-
48-
# One row per changed file, holding the new path and, for a rename,
49-
# the path it replaced: renaming a file out of a package changes that
50-
# package just like editing it.
51-
row='[.filename, (.previous_filename // empty)] | @tsv'
52-
53-
if [[ -n "${PR_NUMBER}" ]]; then
54-
# The PR files endpoint stops at 3000 files and pagination cannot
55-
# extend it, so cross-check against the count the PR itself reports.
56-
expected=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" --jq '.changed_files') \
57-
|| fail_open "Could not read the pull request."
58-
rows=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" --paginate --jq ".[] | ${row}") \
59-
|| fail_open "Could not resolve changed files."
60-
61-
listed=$(count_rows "$rows")
62-
if [[ "$listed" -lt "$expected" ]]; then
63-
fail_open "GitHub listed only ${listed} of ${expected} changed files."
64-
fi
43+
# Reads the change from git rather than the REST API: every job that
44+
# runs this shares the repository's 1,000 requests/hour GITHUB_TOKEN quota.
45+
if [[ "$EVENT_NAME" == pull_request ]]; then
46+
# A pull request checks out GitHub's merge commit with fetch-depth: 2,
47+
# so its first parent is the base branch and the diff is the PR's change.
48+
base=HEAD^1
6549
mode=()
6650
else
67-
rows=$(gh api "repos/${GITHUB_REPOSITORY}/compare/${BEFORE_SHA}...${GITHUB_SHA}" --jq ".files[]? | ${row}") \
68-
|| fail_open "Could not resolve changed files."
69-
70-
# The compare endpoint reports at most 300 files and pagination does
71-
# not extend that list, so a full list may be hiding changes.
72-
listed=$(count_rows "$rows")
73-
if [[ "$listed" -ge 300 ]]; then
74-
fail_open "GitHub listed ${listed} changed files, the compare endpoint maximum."
75-
fi
51+
base=$BEFORE_SHA
52+
git fetch --quiet --no-tags --depth=1 --filter=blob:none origin "$base" \
53+
|| fail_open "Could not fetch ${base}."
7654
# main keeps a full run as the backstop for anything the gate misses.
7755
mode=(--full)
7856
fi
7957
80-
tr '\t' '\n' <<< "$rows" > "$RUNNER_TEMP/changed-paths"
58+
# --no-renames lists a rename as its old and new path: renaming a file out
59+
# of a package changes that package just like editing it. It also keeps
60+
# git from fetching file contents to score renames.
61+
git diff --name-only --no-renames "$base" HEAD > "$RUNNER_TEMP/changed-paths" \
62+
|| fail_open "Could not diff against ${base}."
8163
decide --paths "$RUNNER_TEMP/changed-paths" "${mode[@]}"

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ jobs:
2424
name: Changes
2525
runs-on: blacksmith-2vcpu-ubuntu-2404
2626
timeout-minutes: 5
27-
permissions:
28-
contents: read
29-
pull-requests: read
3027
outputs:
3128
typecheck: ${{ steps.detect.outputs.typecheck }}
3229
build: ${{ steps.detect.outputs.build }}
@@ -39,9 +36,11 @@ jobs:
3936
mobile_native: ${{ steps.detect.outputs.mobile_native }}
4037
steps:
4138
# Only the package manifests the script reads to build the dependency graph.
39+
# Depth 2 brings the base commit the change is diffed against.
4240
- name: Checkout
4341
uses: actions/checkout@v6
4442
with:
43+
fetch-depth: 2
4544
sparse-checkout: |
4645
/pnpm-workspace.yaml
4746
/.github/scripts/ci-changes.cjs
@@ -277,17 +276,16 @@ jobs:
277276
name: Test Server ${{ matrix.shard }}
278277
runs-on: blacksmith-4vcpu-ubuntu-2404
279278
timeout-minutes: 10
280-
permissions:
281-
contents: read
282-
pull-requests: read
283279
strategy:
284280
fail-fast: false
285281
matrix:
286282
shard: [1, 2, 3, 4, 5, 6]
287283
steps:
284+
# Depth 2 brings the base commit the change is diffed against.
288285
- name: Checkout
289286
uses: actions/checkout@v6
290287
with:
288+
fetch-depth: 2
291289
sparse-checkout: |
292290
/*
293291
!/.repos/

0 commit comments

Comments
 (0)