-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy path.cirrus.format.yml
More file actions
64 lines (56 loc) · 2.2 KB
/
.cirrus.format.yml
File metadata and controls
64 lines (56 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
## Cirrus CI: PR-only Linux FormatCheck
task:
name: FormatCheck
only_if: $CIRRUS_PR != ''
container:
image: debian:bookworm-slim
cpu: 2
memory: 2G
format_check_script: |
set -euo pipefail
echo "[FormatCheck] Installing build dependencies..."
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
build-essential git ca-certificates perl python3 meson ninja-build pkg-config flex bison
echo "[FormatCheck] Configuring minimal Meson build..."
meson setup build --buildtype=release --auto-features=disabled
echo "[FormatCheck] Building pg_bsd_indent via Meson..."
ninja -C build src/tools/pg_bsd_indent/pg_bsd_indent || ninja -C build pg_bsd_indent || ninja -C build
echo "[FormatCheck] Determining changed files..."
HEAD_SHA=$(git rev-parse HEAD)
BASE_BRANCH="${CIRRUS_BASE_BRANCH:-}"
if [ -z "$BASE_BRANCH" ]; then
BASE_BRANCH=$(git remote show origin 2>/dev/null | sed -n '/HEAD branch/s/.*: //p')
fi
BASE=""
if [ -n "$BASE_BRANCH" ]; then
git fetch --quiet origin "$BASE_BRANCH" || true
BASE=$(git merge-base HEAD "origin/$BASE_BRANCH" || true)
fi
if [ -z "$BASE" ]; then
BASE="${CIRRUS_BASE_SHA:-}"
fi
if [ -z "$BASE" ] || [ "$BASE" = "$HEAD_SHA" ]; then
BASE=$(git rev-parse HEAD~1 2>/dev/null || echo "$HEAD_SHA")
fi
echo "HEAD=$HEAD_SHA BASE_BRANCH=$BASE_BRANCH BASE=$BASE"
files=$(git diff --name-only "$BASE"..HEAD | grep -E -i '\.(c|h|cpp|hpp)$' | grep -v '^src/tools/pg_bsd_indent/' || true)
if [ -z "$files" ]; then
echo "[FormatCheck] No C/C++ changes detected; skipping."
exit 0
fi
export PGTYPEDEFS=$(pwd)/src/tools/pgindent/typedefs.list
export PGINDENT=$(pwd)/build/src/tools/pg_bsd_indent/pg_bsd_indent
export LANG=C.UTF-8
export LC_ALL=C.UTF-8
echo "[FormatCheck] Running pgindent --check..."
set +e
./src/tools/pgindent/pgindent --check $files
rc=$?
set -e
if [ $rc -ne 0 ]; then
echo "[FormatCheck] Unformatted changes detected; suggested patch below:"
./src/tools/pgindent/pgindent --diff $files || true
exit $rc
fi
echo "[FormatCheck] Passed."