Skip to content

Commit 6fd55d9

Browse files
authored
Merge pull request Expensify#67587 from ikevin127/ikevin127-checkCoverageChangesUpdate
2 parents df6ff73 + 75852fa commit 6fd55d9

2 files changed

Lines changed: 55 additions & 26 deletions

File tree

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,76 @@
11
#!/bin/bash
2+
set -euo pipefail
23

3-
# Ensure upstream/main exists
4-
git fetch --depth=50 upstream main:upstream/main
4+
# -----------------------------
5+
# 1. Ensure upstream remote exists
6+
# -----------------------------
7+
# The PR branch comes from either the base repo or a fork.
8+
# We need the base repository's main branch for comparison.
9+
git remote add upstream "https://github.com/${GITHUB_REPOSITORY}.git" 2>/dev/null || true
510

6-
# Determine diff range safely
7-
if git merge-base upstream/main HEAD >/dev/null 2>&1; then
8-
DIFF_RANGE="upstream/main...HEAD"
9-
else
10-
echo "No merge base with upstream/main; falling back to comparing HEAD against upstream/main"
11-
DIFF_RANGE="upstream/main HEAD"
11+
# -----------------------------
12+
# 2. Attempt shallow fetch first
13+
# -----------------------------
14+
# Start with a depth of 50 commits, which covers most PRs.
15+
DEPTH=50
16+
echo "Fetching upstream/main with depth=$DEPTH..."
17+
git fetch upstream main --depth=$DEPTH
18+
19+
# -----------------------------
20+
# 3. Check if a merge-base exists
21+
# -----------------------------
22+
# merge-base finds the common ancestor between the PR branch and main.
23+
# If this fails, it means our shallow history didn't go back far enough.
24+
if ! git merge-base upstream/main HEAD >/dev/null 2>&1; then
25+
echo "No merge base found with depth=$DEPTH, fetching full history..."
26+
27+
# Try unshallowing the entire repo (pulls full commit history).
28+
# If already full, this will be a no-op.
29+
git fetch --unshallow upstream || git fetch upstream main
1230
fi
1331

14-
# Get changed files in src directory
15-
readarray -t ALL_CHANGED_FILES < <(git diff --name-only "$DIFF_RANGE" | grep '^src/' | grep -E '\.(ts|tsx|js|jsx)$' || true)
32+
# -----------------------------
33+
# 4. Define the diff range
34+
# -----------------------------
35+
# Using three-dot notation (A...B) shows only the commits in HEAD
36+
# that aren't in upstream/main (i.e. just the PR changes).
37+
DIFF_RANGE="upstream/main...HEAD"
38+
39+
# -----------------------------
40+
# 5. Collect changed src/ files
41+
# -----------------------------
42+
readarray -t ALL_CHANGED_FILES < <(
43+
git diff --name-only "$DIFF_RANGE" \
44+
| grep '^src/' \
45+
| grep -E '\.(ts|tsx|js|jsx)$' || true
46+
)
1647

17-
# Filter out excluded directories and files
48+
# -----------------------------
49+
# 6. Filter excluded files/dirs
50+
# -----------------------------
1851
CHANGED_FILES=()
1952
for file in "${ALL_CHANGED_FILES[@]}"; do
20-
# Skip excluded directories
53+
# Exclude directories
2154
if [[ "$file" =~ ^src/(CONST|languages|setup|stories|styles|types)/ ]]; then
22-
echo "Skipping excluded directory: $file"
55+
echo "Skipping excluded directory: \"$file\""
2356
continue
2457
fi
25-
26-
# Skip excluded files in src root
27-
filename=$(basename "$file")
58+
59+
# Exclude specific files in src root
60+
filename="$(basename "$file")"
2861
if [[ "$filename" =~ ^(App\.tsx|CONFIG\.ts|Expensify\.tsx|HybridAppHandler\.tsx|NAICS\.ts|NAVIGATORS\.ts|ONYXKEYS\.ts|ROUTES\.ts|SCREENS\.ts|SplashScreenStateContext\.tsx|TIMEZONES\.ts)$ ]]; then
29-
echo "Skipping excluded file: $file"
62+
echo "Skipping excluded file: \"$file\""
3063
continue
3164
fi
3265

33-
# Add to coverage collection
3466
CHANGED_FILES+=("$file")
3567
done
3668

37-
# Check if any files remain for coverage
69+
# -----------------------------
70+
# 7. Output results
71+
# -----------------------------
3872
if [ ${#CHANGED_FILES[@]} -eq 0 ]; then
39-
echo "No relevant src files changed (all changes were in excluded directories/files), skipping coverage"
73+
echo "No relevant src files changed, skipping coverage"
4074
echo "run_coverage=false" >> "$GITHUB_OUTPUT"
4175
exit 0
4276
fi
@@ -45,5 +79,5 @@ echo "Changed src files for coverage:"
4579
printf '%s\n' "${CHANGED_FILES[@]}"
4680
echo "run_coverage=true" >> "$GITHUB_OUTPUT"
4781

48-
# Save changed files for coverage collection
82+
# Save changed files for later coverage steps
4983
printf '%s\n' "${CHANGED_FILES[@]}" > changed_files.txt

.github/workflows/testCoverage.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ jobs:
4545
repository: ${{ steps.get_pr.outputs.repo }}
4646
ref: ${{ steps.get_pr.outputs.ref }}
4747

48-
- name: Fetch Upstream Remote for Base Repository
49-
run: |
50-
git remote add upstream https://github.com/${{ github.repository }}.git
51-
git fetch upstream main
52-
5348
- name: Setup Git for OSBotify
5449
uses: Expensify/GitHub-Actions/setupGitForOSBotify@main
5550
id: setupGitForOSBotify

0 commit comments

Comments
 (0)