diff --git a/sync.sh b/sync.sh index 290d8db4..2e06d950 100755 --- a/sync.sh +++ b/sync.sh @@ -1,16 +1,28 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo pipefail -CURL_OPTS=(-fSL) +# Resolve paths relative to the repository root, so the script can be run from +# any working directory. +cd "$(dirname "${BASH_SOURCE[0]}")" + +defaultBaseUrl="https://fingerprintjs.github.io/openapi" +schemaUrl="${1:-$defaultBaseUrl/schemas/fingerprint-server-api-v4.yaml}" +examplesBaseUrl="${2:-$defaultBaseUrl/examples}" + +CURL_OPTS=(-fSL --retry 3 --proto-redir '=https' --connect-timeout 10 --max-time 300) if [[ "${TRACE:-}" != "true" && "${ACTIONS_STEP_DEBUG:-}" != "true" ]]; then CURL_OPTS+=(-s) fi -mkdir -p ./resources -curl "${CURL_OPTS[@]}" -o ./resources/fingerprint-server-api.yaml \ - https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/schemas/fingerprint-server-api-v4.yaml +schemaDestination="./resources/fingerprint-server-api.yaml" +exampleBaseDestination="./tests/mocked-responses-tests/mocked-responses-data" + +mkdir -p "$(dirname "$schemaDestination")" -examplesList=( +echo "Downloading $schemaUrl to $schemaDestination" +curl "${CURL_OPTS[@]}" -o "$schemaDestination" "$schemaUrl" + +examples=( 'webhook/webhook_event.json' 'events/get_event_200.json' 'events/get_event_ruleset_200.json' @@ -24,16 +36,13 @@ examplesList=( 'errors/409_state_not_ready.json' ) -baseDestination="./tests/mocked-responses-tests/mocked-responses-data" - -for example in "${examplesList[@]}"; do - destinationPath="$baseDestination/$example" - destinationDir="$(dirname "$destinationPath")" - - mkdir -p "$destinationDir" +for example in "${examples[@]}"; do + destinationPath="$exampleBaseDestination/$example" + mkdir -p "$(dirname "$destinationPath")" - echo "Downloading $example to $destinationPath" - curl "${CURL_OPTS[@]}" -o "$destinationPath" "https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/examples/$example" + exampleUrl="$examplesBaseUrl/$example" + echo "Downloading $exampleUrl to $destinationPath" + curl "${CURL_OPTS[@]}" -o "$destinationPath" "$exampleUrl" done -echo "All OpenAPI documentation downloads complete." +echo "All OpenAPI schema downloads complete."