Skip to content

Commit

Permalink
Merge pull request #11228 from mkurz/scripts_more_user_friendly_2.8.x
Browse files Browse the repository at this point in the history
[2.8.x] Make scripts more userfriendly if running outside of CI
  • Loading branch information
mkurz committed Apr 7, 2022
2 parents a898ec0 + 4802142 commit ca957d4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 24 deletions.
6 changes: 6 additions & 0 deletions scripts/it-test
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions scripts/local-pr-validation.sh
Expand Up @@ -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"
Expand Down
25 changes: 17 additions & 8 deletions scripts/publish-local
Expand Up @@ -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
13 changes: 13 additions & 0 deletions scripts/scriptLib
Expand Up @@ -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
6 changes: 6 additions & 0 deletions scripts/test
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions scripts/test-docs
Expand Up @@ -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"
Expand Down
43 changes: 29 additions & 14 deletions scripts/test-scripted
Expand Up @@ -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.
Expand All @@ -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"

0 comments on commit ca957d4

Please sign in to comment.