Skip to content

Commit 47fedf5

Browse files
committed
fixup! add ci prettier changed-file check
1 parent 4812867 commit 47fedf5

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

scripts/format-changed.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# Purpose:
5+
# - Run Prettier in CI only on files changed in the current branch/PR.
6+
# - Avoid blocking PRs because of legacy formatting in untouched files.
7+
#
8+
# It works by:
9+
# 1) Resolving a diff base from BASE_SHA, BASE_REF, or DEFAULT_BASE.
10+
# 2) Ensuring that base commit exists locally (fetch shallow history when needed).
11+
# 3) Listing changed files between base..HEAD, keeping only supported extensions.
12+
# 4) Running `prettier --check` on that filtered list.
13+
# 5) Exiting 0 when no supported files changed.
14+
415
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
516
cd "$ROOT_DIR"
617

@@ -9,10 +20,13 @@ BASE_REF="${BASE_REF:-${GITHUB_BASE_REF:-}}"
920
DEFAULT_BASE="${DEFAULT_BASE:-origin/main}"
1021

1122
if [[ -n "$BASE_SHA" ]]; then
23+
# Preferred in PR CI: exact base commit SHA
1224
DIFF_BASE="$BASE_SHA"
1325
elif [[ -n "$BASE_REF" ]]; then
26+
# Fallback: base branch name (e.g. main)
1427
DIFF_BASE="origin/${BASE_REF#origin/}"
1528
else
29+
# Local default when no CI vars are provided
1630
DIFF_BASE="$DEFAULT_BASE"
1731
fi
1832

0 commit comments

Comments
 (0)