File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22set -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+
415ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd) "
516cd " $ROOT_DIR "
617
@@ -9,10 +20,13 @@ BASE_REF="${BASE_REF:-${GITHUB_BASE_REF:-}}"
920DEFAULT_BASE=" ${DEFAULT_BASE:- origin/ main} "
1021
1122if [[ -n " $BASE_SHA " ]]; then
23+ # Preferred in PR CI: exact base commit SHA
1224 DIFF_BASE=" $BASE_SHA "
1325elif [[ -n " $BASE_REF " ]]; then
26+ # Fallback: base branch name (e.g. main)
1427 DIFF_BASE=" origin/${BASE_REF# origin/ } "
1528else
29+ # Local default when no CI vars are provided
1630 DIFF_BASE=" $DEFAULT_BASE "
1731fi
1832
You can’t perform that action at this time.
0 commit comments