File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 88 branches-ignore :
99 - ' q/*/**'
1010
11+ pull_request :
12+ branches-ignore :
13+ - ' q/*/**'
14+
1115env :
1216 # Secrets
1317 azurebackend_AZURE_STORAGE_ACCESS_KEY : >-
8084 steps :
8185 - name : Checkout
8286 uses : actions/checkout@v4
87+ with :
88+ fetch-depth : 0
8389 - uses : actions/setup-node@v4
8490 with :
8591 node-version : ' 22'
8995 run : yarn global add typescript@4.9.5
9096 - name : install dependencies
9197 run : yarn install --frozen-lockfile --network-concurrency 1
98+ - name : Prettier (changed files)
99+ run : scripts/format-changed.sh
100+ env :
101+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
102+ BASE_REF : ${{ github.event.pull_request.base.ref }}
103+ if : ${{ github.event_name == 'pull_request' }}
92104 - uses : actions/setup-python@v5
93105 with :
94106 python-version : ' 3.9'
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ # Run Prettier only on files changed against a base ref/commit
5+ ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd) "
6+ cd " $ROOT_DIR "
7+
8+ # Inputs that can be provided by CI
9+ BASE_SHA=" ${BASE_SHA:- } "
10+ BASE_REF=" ${BASE_REF:- ${GITHUB_BASE_REF:- } } "
11+ DEFAULT_BASE=" ${DEFAULT_BASE:- origin/ main} "
12+
13+ if [[ -n " $BASE_SHA " ]]; then
14+ DIFF_BASE=" $BASE_SHA "
15+ elif [[ -n " $BASE_REF " ]]; then
16+ DIFF_BASE=" origin/${BASE_REF# origin/ } "
17+ else
18+ DIFF_BASE=" $DEFAULT_BASE "
19+ fi
20+
21+ # Ensure the base ref exists locally
22+ if ! git rev-parse --verify " ${DIFF_BASE} ^{commit}" > /dev/null 2>&1 ; then
23+ git fetch --no-tags --prune --depth=1 origin " ${DIFF_BASE# origin/ } " > /dev/null 2>&1 || true
24+ fi
25+
26+ # If still missing, bail out gracefully to avoid blocking CI
27+ if ! git rev-parse --verify " ${DIFF_BASE} ^{commit}" > /dev/null 2>&1 ; then
28+ echo " Base ref ${DIFF_BASE} not found; skipping Prettier check." >&2
29+ exit 0
30+ fi
31+
32+ mapfile -t CHANGED < <( git diff --name-only " ${DIFF_BASE} ...HEAD" --diff-filter=ACMRT \
33+ | grep -E ' \\.(js|cjs|mjs|ts|tsx|json|ya?ml|md)$' || true)
34+
35+ if [[ ${# CHANGED[@]} -eq 0 ]]; then
36+ echo " No supported files changed; skipping Prettier check."
37+ exit 0
38+ fi
39+
40+ echo " Running Prettier check on ${# CHANGED[@]} file(s):"
41+ printf ' - %s\n' " ${CHANGED[@]} "
42+
43+ yarn run --silent prettier --check " ${CHANGED[@]} "
You can’t perform that action at this time.
0 commit comments