From 480214248c365782a68fa92cbd047c4dfd0c4636 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Thu, 7 Apr 2022 18:46:49 +0200 Subject: [PATCH] Make scripts more userfriendly if running outside of CI --- scripts/it-test | 6 +++++ scripts/local-pr-validation.sh | 11 +++++++-- scripts/publish-local | 25 +++++++++++++------- scripts/scriptLib | 13 ++++++++++ scripts/test | 6 +++++ scripts/test-docs | 6 +++++ scripts/test-scripted | 43 +++++++++++++++++++++++----------- 7 files changed, 86 insertions(+), 24 deletions(-) diff --git a/scripts/it-test b/scripts/it-test index be7e0f0a337..f095a4c1817 100755 --- a/scripts/it-test +++ b/scripts/it-test @@ -6,6 +6,12 @@ . "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/scriptLib" SCALA_VERSION=$1 + +if [ -z $SCALA_VERSION ]; then + echo "You need to pass the Scala version as argument to this script" + exit 1 +fi + shift cd "$BASEDIR" diff --git a/scripts/local-pr-validation.sh b/scripts/local-pr-validation.sh index 4b655e2e713..5ae0693e627 100755 --- a/scripts/local-pr-validation.sh +++ b/scripts/local-pr-validation.sh @@ -6,14 +6,21 @@ . "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/scriptLib" start validation "RUNNING FRAMEWORK VALIDATION" -sbt headerCheck test:headerCheck javafmtCheckAll scalafmtCheckAll scalafmtSbtCheck +sbt headerCheck test:headerCheck javafmtCheckAll scalafmtCheckAll scalafmtSbtCheck || ( + echo "WARN: Format and/or license headers validaton failed." + echo "You need to run in sbt ';headerCreate ;Test/headerCreate ;javafmtAll ;scalafmtAll ;scalafmtSbt'" + echo "then commit the new changes or amend the existing commit." + echo "See more information about amending commits in our docs:" + echo "https://playframework.com/documentation/latest/WorkingWithGit" + false +) start validation "FRAMEWORK VALIDATION DONE" pushd "$DOCUMENTATION" start doc-validation "RUNNING DOCUMENTATION VALIDATION" sbt headerCheck test:headerCheck javafmtCheckAll scalafmtCheckAll scalafmtSbtCheck || ( echo "WARN: Format and/or license headers validaton failed." - echo "You need to run in sbt ';headerCreate ;test:headerCreate ;javafmtAll ;scalafmtAll ;scalafmtSbt'" + echo "Inside the documentation/ folder you need to run in sbt ';headerCreate ;test:headerCreate ;javafmtAll ;scalafmtAll ;scalafmtSbt'" echo "then commit the new changes or amend the existing commit." echo "See more information about amending commits in our docs:" echo "https://playframework.com/documentation/latest/WorkingWithGit" diff --git a/scripts/publish-local b/scripts/publish-local index 42909eced1f..4edc71cca85 100755 --- a/scripts/publish-local +++ b/scripts/publish-local @@ -8,18 +8,27 @@ cd "$BASEDIR" start clean "CLEANING IVY LOCAL REPO" -rm -rf $HOME/.ivy2/local +if [ "$TRAVIS" = "true" ]; then + rm -rf $HOME/.ivy2/local +else + # When running locally we want to keep other non play related artifacts + rm -rf $HOME/.ivy2/local/com.typesafe.play/ +fi end clean "CLEANED IVY LOCAL REPO" start publish-local "CROSS-PUBLISHING PLAY LOCALLY FOR SBT SCRIPTED TESTS" runSbt ";crossScalaVersions;crossSbtVersions;+publishLocal" end publish-local "CROSS-PUBLISHED PLAY LOCALLY FOR SBT SCRIPTED TESTS" -start save-akka-version "SAVING AKKA_VERSION AND AKKA_HTTP_VERSION" -echo "$AKKA_VERSION" > $HOME/.ivy2/local/com.typesafe.play/AKKA_VERSION -echo "$AKKA_HTTP_VERSION" > $HOME/.ivy2/local/com.typesafe.play/AKKA_HTTP_VERSION -end save-akka-version "SAVED AKKA_VERSION AND AKKA_HTTP_VERSION" +if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then + start save-akka-version "SAVING AKKA_VERSION AND AKKA_HTTP_VERSION" + echo "$AKKA_VERSION" > $HOME/.ivy2/local/com.typesafe.play/AKKA_VERSION + echo "$AKKA_HTTP_VERSION" > $HOME/.ivy2/local/com.typesafe.play/AKKA_HTTP_VERSION + end save-akka-version "SAVED AKKA_VERSION AND AKKA_HTTP_VERSION" +fi -start save-git-commit-hash "SAVING GIT COMMIT HASH" -git rev-parse HEAD > $HOME/.ivy2/local/com.typesafe.play/PUBLISHED_LOCAL_COMMIT_HASH -end save-git-commit-hash "SAVED GIT COMMIT HASH" +if [ "$TRAVIS" = "true" ]; then + start save-git-commit-hash "SAVING GIT COMMIT HASH" + git rev-parse HEAD > $HOME/.ivy2/local/com.typesafe.play/PUBLISHED_LOCAL_COMMIT_HASH + end save-git-commit-hash "SAVED GIT COMMIT HASH" +fi diff --git a/scripts/scriptLib b/scripts/scriptLib index f0f851c8ed2..030c6620e6a 100755 --- a/scripts/scriptLib +++ b/scripts/scriptLib @@ -76,3 +76,16 @@ setShellScalaVersionFromSbtVersion() { *) echo "Aborting: Failed to determine scala version for sbt $SBT_VERSION" >&2; exit 1 ;; esac } + +if [ "$TRAVIS" = "true" ]; then + start debug-env "SHOW FILES RELEVANT FOR THIS JOB AND ALL ENV VARIABLES" + echo "$ cat /etc/sbt/jvmopts" + cat /etc/sbt/jvmopts + echo "" + echo "$ cat /etc/sbt/sbtopts" + cat /etc/sbt/sbtopts + echo "" + echo "$ env" + env + end debug-env "SHOWED FILES RELEVANT FOR THIS JOB AND ALL ENV VARIABLES" +fi diff --git a/scripts/test b/scripts/test index d9f2c459bf0..1c6a86f24f0 100755 --- a/scripts/test +++ b/scripts/test @@ -6,6 +6,12 @@ . "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/scriptLib" SCALA_VERSION=$1 + +if [ -z $SCALA_VERSION ]; then + echo "You need to pass the Scala version as argument to this script" + exit 1 +fi + shift cd "$BASEDIR" diff --git a/scripts/test-docs b/scripts/test-docs index 66971cd9aae..a4b4595107b 100755 --- a/scripts/test-docs +++ b/scripts/test-docs @@ -6,6 +6,12 @@ . "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/scriptLib" SCALA_VERSION=$1 + +if [ -z $SCALA_VERSION ]; then + echo "You need to pass the Scala version as argument to this script" + exit 1 +fi + shift cd "$DOCUMENTATION" diff --git a/scripts/test-scripted b/scripts/test-scripted index 9632ae5aeb8..eebec2b2f08 100755 --- a/scripts/test-scripted +++ b/scripts/test-scripted @@ -6,9 +6,21 @@ . "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/scriptLib" SBT_VERSION=$1 + +if [ -z $SBT_VERSION ]; then + echo "You need to pass the sbt version as first and the Scala version as second argument to this script" + exit 1 +fi + shift SCALA_VERSION=$1 + +if [ -z $SCALA_VERSION ]; then + echo "You need to pass the Scala version as second argument to this script" + exit 1 +fi + shift # Set the $SCALA_VERSION_SHELL variable. @@ -23,19 +35,22 @@ cd "$BASEDIR" start scripted "RUNNING SCRIPTED TESTS FOR SBT $SBT_VERSION AND SCALA $SCALA_VERSION" -# Make sure scripted tests run with the same git commit that was used for the publish-local job. -# For each CI job the CI server always clones the latest up-to-date base branch and, if the current job is for a pull request, -# then "fetches" the current pull request on top of it (just look at the logs of a PR job, you will see "git fetch origin +refs/pull/<#PR>/merge"). -# Now if another pull request gets merged in the time window during the publish-local and a scripted job, the base branches moves forward -# and the CI server will now clone that newer base branch before "fetching" the current PR on it. Of course now the commit hash has changed and -# the distance from the latest tag has increased, so the Play version set by dynver will be different than the one used for publish-local, resulting -# in "unresolved dependencies" errors. -PUBLISHED_LOCAL_COMMIT_HASH=$(cat $HOME/.ivy2/local/com.typesafe.play/PUBLISHED_LOCAL_COMMIT_HASH) -git fetch origin ${PUBLISHED_LOCAL_COMMIT_HASH} -git checkout ${PUBLISHED_LOCAL_COMMIT_HASH} -echo "Checked out git commit ${PUBLISHED_LOCAL_COMMIT_HASH} which was used for publish-local in previous job" - -ls -alFhR ~/.ivy2 | grep play | grep jar -ls -alFhR ~/.cache/coursier | grep play | grep jar +if [ "$TRAVIS" = "true" ]; then + # Make sure scripted tests run with the same git commit that was used for the publish-local job. + # For each CI job the CI server always clones the latest up-to-date base branch and, if the current job is for a pull request, + # then "fetches" the current pull request on top of it (just look at the logs of a PR job, you will see "git fetch origin +refs/pull/<#PR>/merge"). + # Now if another pull request gets merged in the time window during the publish-local and a scripted job, the base branches moves forward + # and the CI server will now clone that newer base branch before "fetching" the current PR on it. Of course now the commit hash has changed and + # the distance from the latest tag has increased, so the Play version set by dynver will be different than the one used for publish-local, resulting + # in "unresolved dependencies" errors. + PUBLISHED_LOCAL_COMMIT_HASH=$(cat $HOME/.ivy2/local/com.typesafe.play/PUBLISHED_LOCAL_COMMIT_HASH) + git fetch origin ${PUBLISHED_LOCAL_COMMIT_HASH} + git checkout ${PUBLISHED_LOCAL_COMMIT_HASH} + echo "Checked out git commit ${PUBLISHED_LOCAL_COMMIT_HASH} which was used for publish-local in previous job" + + # This is just for "debugging" + ls -alFhR ~/.ivy2 | grep play | grep jar + ls -alFhR ~/.cache/coursier | grep play | grep jar +fi runSbt ";project Sbt-Plugin;set scriptedSbt := \"${SBT_VERSION}\";set scriptedLaunchOpts += \"-Dscala.version=${SCALA_VERSION}\";++$SCALA_VERSION_SHELL;show scriptedSbt;show scriptedLaunchOpts;scripted $@" end scripted "ALL SCRIPTED TESTS PASSED"