Skip to content

Commit 9c1d656

Browse files
authored
chore: use cache to avoid building specs everytime APIC-283 (#109)
1 parent 795035b commit 9c1d656

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/generate.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,29 @@ LANGUAGE=$1
1111
CLIENT=$2
1212
GENERATOR="$1-$2"
1313

14+
compute_hash() {
15+
cacheSpec=$(find specs/$CLIENT -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ')
16+
cacheCommon=$(find specs/common -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ')
17+
echo "$cacheSpec$cacheCommon"
18+
}
19+
1420
# build spec before generating client
1521
build_spec() {
22+
# check if file and cache exist
23+
cacheFile="specs/dist/$CLIENT.cache"
24+
if [[ -f specs/dist/$CLIENT.yml ]]; then
25+
cache=$(compute_hash)
26+
# compare with stored cache
27+
if [[ -f $cacheFile && $(cat $cacheFile) == $cache ]]; then
28+
echo "> Skipped building spec because the files did not change..."
29+
return
30+
fi
31+
fi
1632
yarn build:specs $CLIENT
33+
34+
# store hash
35+
cache=$(compute_hash)
36+
echo $cache > $cacheFile
1737
}
1838

1939
# Run the pre generation script if it exists.

0 commit comments

Comments
 (0)