From cc3b88ab30bd6a6ce8b939fce3bbc26fb3067ca6 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 5 Mar 2021 00:02:21 +0100 Subject: [PATCH] gradlew-fdroid: use gradle zipballs from local cachedir, if present --- .gitlab-ci.yml | 15 ++++++++++++++- gradlew-fdroid | 12 ++++++++---- tests/test-gradlew-fdroid | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1396220c..10d08696 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -143,6 +143,20 @@ arch_pip_install: - fdroid readmeta - fdroid update --help + +gradlew-fdroid: + image: debian:bullseye + <<: *apt-template + only: + changes: + - .gitlab-ci.yml + - gradlew-fdroid + - tests/test-gradlew-fdroid + script: + - apt-get install ca-certificates curl default-jdk-headless unzip + - ./tests/test-gradlew-fdroid + + lint_format_safety_bandit_checks: image: alpine:3.10 # cannot upgrade until bandit supports Python 3.8 variables: @@ -154,7 +168,6 @@ lint_format_safety_bandit_checks: - export EXITVALUE=0 - function set_error() { export EXITVALUE=1; printf "\x1b[31mERROR `history|tail -2|head -1|cut -b 6-500`\x1b[0m\n"; } - ./hooks/pre-commit || set_error - - ./tests/test-gradlew-fdroid || set_error - bandit -ii -s B110,B322,B404,B408,B410,B603,B607 diff --git a/gradlew-fdroid b/gradlew-fdroid index fd73b2a3..2ac3b678 100755 --- a/gradlew-fdroid +++ b/gradlew-fdroid @@ -8,8 +8,11 @@ if [ -z "$GRADLE_VERSION_DIR" ]; then else gradle_version_dir="$GRADLE_VERSION_DIR" fi +BUILDSERVER_CACHEDIR=/vagrant/cache if [ -n "$CACHEDIR" ]; then cachedir="$CACHEDIR" +elif [ -d $BUILDSERVER_CACHEDIR ]; then + cachedir=$BUILDSERVER_CACHEDIR fi args=("$@") @@ -34,11 +37,12 @@ download_gradle() { gradle_zip="${cachedir}/gradle-$1-bin.zip" else echo "Downloading missing gradle version $1" - if [ -n "${cachedir}" ]; then + echo cachedir $cachedir + if [[ -n "${cachedir}" && ! -d "${cachedir}" ]]; then + mkdir -p "${cachedir}" + fi + if [[ -n "${cachedir}" && -d "${cachedir}" && -w "${cachedir}" ]]; then tmpdir="${cachedir}" - if [ ! -d ${tmpdir} ]; then - mkdir -p "${cachedir}" - fi else tmpdir=$(mktemp -d) fi diff --git a/tests/test-gradlew-fdroid b/tests/test-gradlew-fdroid index 63f74e5e..3d6d6016 100755 --- a/tests/test-gradlew-fdroid +++ b/tests/test-gradlew-fdroid @@ -1,9 +1,12 @@ #!/bin/bash +red='\033[0;31m' +green='\033[0;32m' +nocolor='\033[0m' + +TEST_VALUE='HELLO WORLD!' + run_test() { - red='\033[0;31m' - green='\033[0;32m' - nocolor='\033[0m' cd $source_files/$1 printf "\n${1}:\n" if ($basedir/gradlew-fdroid 2>/dev/null || true) | grep -Fo "$2"; then @@ -15,6 +18,17 @@ run_test() { printf $nocolor } +download_cache_test() { + if $basedir/gradlew-fdroid helloWorld 2>/dev/null | grep -F "$TEST_VALUE"; then + printf "${green}passed: $1\n" + else + printf "${red}ERROR: \n" + $basedir/gradlew-fdroid helloWorld + ((exit_value++)) + fi + printf $nocolor +} + exit_value=0 basedir=$(cd $(dirname $0)/..; pwd) source_files=$basedir/tests/source-files @@ -39,4 +53,23 @@ source_files=$tmpdir run_test yuriykulikov/AlarmClock 5.1.1 run_test osmandapp/osmand 2.2.1 +cd $tmpdir +mkdir -p download_cache_test/gradle/wrapper +cd download_cache_test +echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-0.7-bin.zip' \ + > gradle/wrapper/gradle-wrapper.properties +printf "task helloWorld {\n\tdoLast {\n\t\tprintln '$TEST_VALUE'\n\t}\n}" > build.gradle + +export GRADLE_VERSION_DIR=$tmpdir/gradle/versions +mkdir -p $GRADLE_VERSION_DIR + +unset https_proxy +printf "download, unpack, and run: " +download_cache_test 0.7 +printf "unpack and run: " +rm -rf $GRADLE_VERSION_DIR/0.7/ +download_cache_test 0.7 +printf "just run: " +download_cache_test 0.7 + exit $exit_value