diff --git a/scripts/frontend/download_fixtures.sh b/scripts/frontend/download_fixtures.sh index 47a57401bb95f9551e4ed75ab5b106e4ee0ce854..c508c991bbf04a57121cd63fcb18394c61aaf389 100755 --- a/scripts/frontend/download_fixtures.sh +++ b/scripts/frontend/download_fixtures.sh @@ -7,6 +7,11 @@ source scripts/packages/helpers.sh +mkdir -p "tmp/tests/frontend" +VERSION_CACHE="tmp/tests/frontend/.fixtures_version" +NO_ARCHIVE_CACHE="tmp/tests/frontend/.no_archive" +CURRENT_VERSION="$(cat "$VERSION_CACHE" 2>/dev/null)" + print_help() { echo "Usage: scripts/frontend/download_fixtures.sh [--branch ] [--max-commits ]" echo @@ -18,6 +23,15 @@ print_help() { return } +# Function to clean old entries (e.g., keep only last max items) +cleanup_no_archive_cache() { + local max=$1 + + if [ -f "$NO_ARCHIVE_CACHE" ] && [ $(wc -l < "$NO_ARCHIVE_CACHE") -gt $max ]; then + tail -n $max "$NO_ARCHIVE_CACHE" > "$NO_ARCHIVE_CACHE.tmp" && mv "$NO_ARCHIVE_CACHE.tmp" "$NO_ARCHIVE_CACHE" + fi +} + branch="HEAD" max_commits_count=50 @@ -39,18 +53,37 @@ while [ $# -gt 0 ]; do shift done +# Cache max 100 SHAs without archive. +cleanup_no_archive_cache 100 + for commit_sha in $(git rev-list ${branch} --max-count="${max_commits_count}"); do API_PACKAGES_BASE_URL=https://gitlab.com/api/v4/projects/278964/packages/generic FIXTURES_PACKAGE="fixtures-${commit_sha}.tar.gz" FIXTURES_PACKAGE_URL="${API_PACKAGES_BASE_URL}/fixtures/${commit_sha}/${FIXTURES_PACKAGE}" - echo "Looking for frontend fixtures for commit ${commit_sha}..." + echo -n "Looking for frontend fixtures for commit ${commit_sha}..." + + if grep -qs "${commit_sha}" "${NO_ARCHIVE_CACHE}" 2>/dev/null; then + echo " cached - skipping." + continue + fi - if ! archive_doesnt_exist "${FIXTURES_PACKAGE_URL}" > /dev/null 2>&1; then + if archive_doesnt_exist "${FIXTURES_PACKAGE_URL}" > /dev/null 2>&1; then + echo " no archive found - caching." + echo "${commit_sha}" >> "$NO_ARCHIVE_CACHE" + else + if [ "$CURRENT_VERSION" = "$commit_sha" ]; then + echo " already downloaded - skipping." + break + fi + + echo echo "We have found frontend fixtures at ${FIXTURES_PACKAGE_URL}!" read_curl_package "${FIXTURES_PACKAGE_URL}" | extract_package + echo -n "$commit_sha" > "$VERSION_CACHE" + break fi done