-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathcompare-build-output-to.sh
executable file
·89 lines (61 loc) · 1.63 KB
/
compare-build-output-to.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
set -euo pipefail
upstream=$1
comparison="${RUNNER_TEMP:-/tmp}/comparison_checkout"
root=$(git rev-parse --show-toplevel)
temp=$(mktemp --tmpdir="${RUNNER_TEMP:-/tmp}")
trap 'rm -f "$temp"' EXIT
patterndiff(){
cd dist || { echo "dist folder not found"; exit 1; }
count=0
while IFS= read -r -d '' file
do
if ! filediff="$(diff <(tr "'" '"' < "$comparison/dist/$file") <(tr "'" '"' < "$root/dist/$file") -w)"; then
(( count++ ))
echo "$file"
if [[ "$file" == *.min.* ]]; then
echo "> Minified file differs."
else
echo "$filediff"
fi
fi
done >"$temp" < <(find . -name "$1" -print0)
output="$(cat <"$temp")"
cat <<EOF
## differences in $1 files
<details>
<summary>
### $count files with differences
</summary>
\`\`\`diff
$output
\`\`\`
</details>
EOF
cd ..
}
[ -z "$upstream" ] && { echo "need upstream argument"; exit 1; }
git worktree add --force --detach --checkout "$comparison" "$upstream" || { cd "$comparison" && git checkout "$upstream"; } || exit 1
cd "$comparison" || { echo "checkout failed"; exit 1; }
cp -r "$root/node_modules" .
npm i >&2
git status >&2
npm run build >&2
cd "$root" || exit 1
git status >&2
npm run build >&2
set +e
patterndiff "*.js"
patterndiff "*.cjs"
patterndiff "*.d.ts"
cat <<EOF
## differences in other files
<details>
<summary>
### $(diff -qr "$comparison/dist" "dist" -x "*.map" -x "*.native.*" -x "*.js" -x "*.cjs" -x "*.d.ts" -w | wc -l) files with differences
</summary>
\`\`\`diff
$(diff -r "$comparison/dist" "dist" -x "*.map" -x "*.native.*" -x "*.js" -x "*.cjs" -x "*.d.ts" -w)
\`\`\`
</details>
EOF