Skip to content

Commit 6f142a1

Browse files
committed
Comparison aid
1 parent 30b48a7 commit 6f142a1

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/sh
2+
# compare-standalone-to-monorepo.sh
3+
#
4+
# Compare POM, Java source, and Java properties files between the
5+
# standalone copilot-sdk-java repo and the monorepo's java/ directory.
6+
#
7+
# Usage:
8+
# ./scripts/compare-standalone-to-monorepo.sh /path/to/standalone /path/to/monorepo [--diff]
9+
#
10+
# The standalone path should point to the root of copilot-sdk-java.
11+
# The monorepo path should point to the root of copilot-sdk (the java/ subdir
12+
# is appended automatically).
13+
#
14+
# Compatible with macOS zsh and POSIX sh/bash.
15+
16+
set -e
17+
18+
# ── Parse arguments ──────────────────────────────────────────────────
19+
SHOW_DIFF=false
20+
STANDALONE=""
21+
MONOREPO=""
22+
23+
for arg in "$@"; do
24+
case "$arg" in
25+
--diff)
26+
SHOW_DIFF=true
27+
;;
28+
*)
29+
if [ -z "$STANDALONE" ]; then
30+
STANDALONE="$arg"
31+
elif [ -z "$MONOREPO" ]; then
32+
MONOREPO="$arg"
33+
else
34+
echo "Error: unexpected argument: $arg" >&2
35+
echo "Usage: $0 <standalone-path> <monorepo-path> [--diff]" >&2
36+
exit 1
37+
fi
38+
;;
39+
esac
40+
done
41+
42+
if [ -z "$STANDALONE" ] || [ -z "$MONOREPO" ]; then
43+
echo "Usage: $0 <standalone-path> <monorepo-path> [--diff]" >&2
44+
exit 1
45+
fi
46+
47+
MONO_JAVA="${MONOREPO}/java"
48+
49+
if [ ! -d "$STANDALONE" ]; then
50+
echo "Error: standalone directory does not exist: $STANDALONE" >&2
51+
exit 1
52+
fi
53+
54+
if [ ! -d "$MONO_JAVA" ]; then
55+
echo "Error: monorepo java directory does not exist: $MONO_JAVA" >&2
56+
exit 1
57+
fi
58+
59+
# ── Collect comparable files from the standalone repo ────────────────
60+
# Excludes: target/, node_modules/, temporary-prompts/, scripts/codegen/
61+
# (these are build artifacts or standalone-only content)
62+
TMPFILE=$(mktemp)
63+
trap 'rm -f "$TMPFILE"' EXIT
64+
65+
(cd "$STANDALONE" && find . -type f \( -name "pom.xml" -o -name "*.java" -o -name "*.properties" \) \
66+
| grep -v '/target/' \
67+
| grep -v '/node_modules/' \
68+
| grep -v '^\./temporary-prompts/' \
69+
| grep -v '^\./scripts/codegen/' \
70+
| sed 's|^\./||' \
71+
| sort) > "$TMPFILE"
72+
73+
# ── Compare ──────────────────────────────────────────────────────────
74+
DIFFER_COUNT=0
75+
MISSING_COUNT=0
76+
SAME_COUNT=0
77+
DIFFER_LIST=""
78+
MISSING_LIST=""
79+
80+
while IFS= read -r relpath; do
81+
standalone_file="${STANDALONE}/${relpath}"
82+
mono_file="${MONO_JAVA}/${relpath}"
83+
84+
if [ ! -f "$mono_file" ]; then
85+
MISSING_COUNT=$((MISSING_COUNT + 1))
86+
MISSING_LIST="${MISSING_LIST}${relpath}
87+
"
88+
elif ! diff -q "$standalone_file" "$mono_file" >/dev/null 2>&1; then
89+
DIFFER_COUNT=$((DIFFER_COUNT + 1))
90+
DIFFER_LIST="${DIFFER_LIST}${relpath}
91+
"
92+
else
93+
SAME_COUNT=$((SAME_COUNT + 1))
94+
fi
95+
done < "$TMPFILE"
96+
97+
TOTAL_COUNT=$(wc -l < "$TMPFILE" | tr -d ' ')
98+
99+
# ── Output ───────────────────────────────────────────────────────────
100+
echo "Compared ${TOTAL_COUNT} files (pom.xml, *.java, *.properties)"
101+
echo " Identical: ${SAME_COUNT}"
102+
echo " Differ: ${DIFFER_COUNT}"
103+
echo " Missing from monorepo: ${MISSING_COUNT}"
104+
echo ""
105+
106+
if [ "$DIFFER_COUNT" -gt 0 ]; then
107+
echo "The following files differ between the standalone and monorepo:"
108+
echo ""
109+
printf '%s' "$DIFFER_LIST" | while IFS= read -r f; do
110+
[ -n "$f" ] && echo " $f"
111+
done
112+
echo ""
113+
fi
114+
115+
if [ "$MISSING_COUNT" -gt 0 ]; then
116+
echo "The following files exist in standalone but NOT in monorepo:"
117+
echo ""
118+
printf '%s' "$MISSING_LIST" | while IFS= read -r f; do
119+
[ -n "$f" ] && echo " $f"
120+
done
121+
echo ""
122+
fi
123+
124+
if [ "$DIFFER_COUNT" -eq 0 ] && [ "$MISSING_COUNT" -eq 0 ]; then
125+
echo "All files are identical."
126+
fi
127+
128+
# ── Optional unified diffs ───────────────────────────────────────────
129+
if [ "$SHOW_DIFF" = true ] && [ "$DIFFER_COUNT" -gt 0 ]; then
130+
echo "================================================================================"
131+
echo "Unified diffs for differing files:"
132+
echo "================================================================================"
133+
printf '%s' "$DIFFER_LIST" | while IFS= read -r f; do
134+
if [ -n "$f" ]; then
135+
echo ""
136+
echo "--- standalone/$f"
137+
echo "+++ monorepo/java/$f"
138+
diff -u "${STANDALONE}/${f}" "${MONO_JAVA}/${f}" || true
139+
fi
140+
done
141+
fi

0 commit comments

Comments
 (0)