Skip to content

Commit

Permalink
Only re-fetch and re-install if needed
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Jul 31, 2024
1 parent 39d8932 commit 5ae69ac
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build/fetch: | build

.PHONY: prepare
prepare: collections | build/fetch
./scripts/collections-fetch.sh $(realpath $<) $(realpath $|)
./scripts/collections-fetch.sh $(realpath $<) $(realpath $|) $(realpath $(SCHEMAS))
./scripts/collections-install.sh $(realpath $<) $(realpath $|) $(realpath $(SCHEMAS))
$(JSONSCHEMA) fmt --verbose $(realpath $(SCHEMAS))
./scripts/generate-configuration.sh $(realpath $<) "$(BASE_URL)" > configuration.json
Expand Down
1 change: 1 addition & 0 deletions schemas/krakend/schema/.collection.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9f7ef952a1c213b1efead11d2a4da7aa
18 changes: 16 additions & 2 deletions scripts/collections-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
set -o errexit
set -o nounset

if [ $# -lt 2 ]
if [ $# -lt 3 ]
then
echo "Usage: $0 <directory> <output>" 1>&2
echo "Usage: $0 <directory> <output> <schemas>" 1>&2
exit 1
fi

DIRECTORY="$1"
OUTPUT="$2"
SCHEMAS="$3"

echo "-- Fetching collections from $DIRECTORY into $OUTPUT" 1>&2

Expand All @@ -23,6 +24,19 @@ do
TYPE="$(jq --raw-output '.type' "$collection")"
URL="$(jq --raw-output '.url' "$collection")"

HASH_PATH="$SCHEMAS/$NAMESPACE/$ID/.collection.md5"
COLLECTION_HASH="$(md5sum "$collection" | cut -d ' ' -f 1)"
if [ -f "$HASH_PATH" ]
then
echo "-- Found collection hash marker: $HASH_PATH" 1>&2
CURRENT_HASH="$(tr -d '\n\r' < "$HASH_PATH")"
if [ "$CURRENT_HASH" = "$COLLECTION_HASH" ]
then
echo "-- Hashes match. Skipping fetch" 1>&2
continue
fi
fi

echo "-- Fetching $collection ($TYPE) into $COLLECTION_OUTPUT" 1>&2
if [ "$TYPE" = "git" ]
then
Expand Down
15 changes: 15 additions & 0 deletions scripts/collections-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ do
ID="$(basename "$collection" .json)"
COLLECTION_OUTPUT="$OUTPUT/$NAMESPACE/$ID"

HASH_PATH="$COLLECTION_OUTPUT/.collection.md5"
COLLECTION_HASH="$(md5sum "$collection" | cut -d ' ' -f 1)"
if [ -f "$HASH_PATH" ]
then
echo "-- Found collection hash marker: $HASH_PATH" 1>&2
CURRENT_HASH="$(tr -d '\n\r' < "$HASH_PATH")"
if [ "$CURRENT_HASH" = "$COLLECTION_HASH" ]
then
echo "-- Hashes match. Skipping install" 1>&2
continue
fi
fi

echo "-- Installing $collection into $COLLECTION_OUTPUT" 1>&2

cd "$FETCH_DIRECTORY/$NAMESPACE/$ID"
Expand Down Expand Up @@ -61,4 +74,6 @@ do
done

cd - > /dev/null

echo "$COLLECTION_HASH" > "$HASH_PATH"
done

0 comments on commit 5ae69ac

Please sign in to comment.