Skip to content

Commit

Permalink
chore: use cache to avoid building specs everytime APIC-283 (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Jan 27, 2022
1 parent 795035b commit 9c1d656
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,29 @@ LANGUAGE=$1
CLIENT=$2
GENERATOR="$1-$2"

compute_hash() {
cacheSpec=$(find specs/$CLIENT -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ')
cacheCommon=$(find specs/common -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ')
echo "$cacheSpec$cacheCommon"
}

# build spec before generating client
build_spec() {
# check if file and cache exist
cacheFile="specs/dist/$CLIENT.cache"
if [[ -f specs/dist/$CLIENT.yml ]]; then
cache=$(compute_hash)
# compare with stored cache
if [[ -f $cacheFile && $(cat $cacheFile) == $cache ]]; then
echo "> Skipped building spec because the files did not change..."
return
fi
fi
yarn build:specs $CLIENT

# store hash
cache=$(compute_hash)
echo $cache > $cacheFile
}

# Run the pre generation script if it exists.
Expand Down

0 comments on commit 9c1d656

Please sign in to comment.