From 587a13c07ae50c329400f304cb0acfc69cc1745f Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Thu, 27 Jan 2022 15:03:15 +0100 Subject: [PATCH 1/2] chore: use cache to avoid building specs everytime --- scripts/generate.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/generate.sh b/scripts/generate.sh index befdfc4e70c..d19c0951dee 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -13,7 +13,21 @@ GENERATOR="$1-$2" # 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=$(find specs/$CLIENT -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ') + # 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=$(find specs/$CLIENT -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ') + echo $cache > $cacheFile } # Run the pre generation script if it exists. From 39750225b87b2d42e26b0a302cadaaf60ca2222a Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Thu, 27 Jan 2022 15:12:54 +0100 Subject: [PATCH 2/2] compare common also --- scripts/generate.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/generate.sh b/scripts/generate.sh index d19c0951dee..cdf5a52056c 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -11,12 +11,18 @@ 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=$(find specs/$CLIENT -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ') + cache=$(compute_hash) # compare with stored cache if [[ -f $cacheFile && $(cat $cacheFile) == $cache ]]; then echo "> Skipped building spec because the files did not change..." @@ -26,7 +32,7 @@ build_spec() { yarn build:specs $CLIENT # store hash - cache=$(find specs/$CLIENT -type f -print0 | xargs -0 sha1sum | sha1sum | tr -d ' ') + cache=$(compute_hash) echo $cache > $cacheFile }