Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only re-fetch and re-install if needed #3

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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