From 698bd4dc3130d2c823a3d5747ecfb3f87a5b3d2c Mon Sep 17 00:00:00 2001 From: Sergey Morgunov Date: Fri, 1 Mar 2024 15:28:20 +0300 Subject: [PATCH] Build only changed examples and do it parallel --- .github/workflows/build-test.yml | 125 +++++++++++++----- .../scripts/test-gradle | 9 -- play-java-chatroom-example/scripts/test-sbt | 6 - test.sh | 121 ++++++++++++----- 4 files changed, 178 insertions(+), 83 deletions(-) delete mode 100755 play-java-chatroom-example/scripts/test-gradle delete mode 100755 play-java-chatroom-example/scripts/test-sbt diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 697aa109b..9b065b902 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -19,43 +19,104 @@ jobs: # with: # cmd: sbt validateCode - tests-pekko-http: - name: Sbt Tests Pekko HTTP -# needs: -# - "check-code-style" - uses: playframework/.github/.github/workflows/cmd.yml@v3 - with: - java: 17, 11 - scala: 2.13.x, 3.x - cmd: | - # sudo add-apt-repository -y ppa:ondrej/php && sudo apt-get -qq update && sudo apt-get install -y libsodium-dev # for secure session examples - ./test.sh - - tests-netty-http: - name: Sbt Tests Netty HTTP -# needs: -# - "check-code-style" - uses: playframework/.github/.github/workflows/cmd.yml@v3 - with: - java: 17, 11 - scala: 2.13.x, 3.x - cmd: | - ./test.sh --netty + changes: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + examples: ${{ steps.filter.outputs.changes }} + steps: + # For pull requests it's not necessary to checkout the code + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + java-chatroom: play-java-chatroom-example/** + java-compile-di: play-java-compile-di-example/** + java-dagger2: play-java-dagger2-example/** + java-ebean: play-java-ebean-example/** + java-fileupload: play-java-fileupload-example/** + java-forms: play-java-forms-example/** + java-grpc: play-java-grpc-example/** + java-hello-world: play-java-hello-world-tutorial/** + java-jpa: play-java-jpa-example/** + java-pekko-cluster: play-java-pekko-cluster-example/** + java-rest-api: play-java-rest-api-example/** + java-starter: play-java-starter-example/** + java-streaming: play-java-streaming-example/** + java-websocket: play-java-websocket-example/** + scala-anorm: play-scala-anorm-example/** + scala-chatroom: play-scala-chatroom-example/** + scala-compile-di: play-scala-compile-di-example/** + scala-fileupload: play-scala-fileupload-example/** + scala-forms: play-scala-forms-example/** + scala-grpc: play-scala-grpc-example/** + scala-hello-world: play-scala-hello-world-tutorial/** + scala-isolated-slick: play-scala-isolated-slick-example/** + scala-log4j2: play-scala-log4j2-example/** + scala-macwire-di: play-scala-macwire-di-example/** + scala-rest-api: play-scala-rest-api-example/** + scala-secure-session: play-scala-secure-session-example/** + scala-slick: play-scala-slick-example/** + scala-starter: play-scala-starter-example/** + scala-streaming: play-scala-streaming-example/** + scala-tls: play-scala-tls-example/** + scala-websocket: play-scala-websocket-example/** - gradle-tests: - name: Gradle Tests - uses: playframework/.github/.github/workflows/cmd.yml@v3 + java-chatroom: + name: "Java :: Chatroom" + uses: playframework/.github/.github/workflows/cmd.yml@v4 + needs: changes + if: ${{ (github.event_name != 'pull_request' && !failure() && !cancelled()) || contains(fromJSON(needs.changes.outputs.examples), 'java-chatroom')}} with: - java: 17, 11 + java: 17, 21 scala: 2.13.x, 3.x + gradle-build-root: play-java-chatroom-example + add-dimensions: >- + { "server": [ "pekko", "netty"] } cmd: | - ./test-gradle.sh + ./test.sh --sample=play-java-chatroom-example --backend-server=$MATRIX_SERVER + ./test.sh --sample=play-java-chatroom-example --backend-server=$MATRIX_SERVER --build-tool=gradle + +# tests-pekko-http: +# name: Sbt Tests Pekko HTTP +## needs: +## - "check-code-style" +# uses: playframework/.github/.github/workflows/cmd.yml@v3 +# with: +# java: 17, 11 +# scala: 2.13.x, 3.x +# cmd: | +# # sudo add-apt-repository -y ppa:ondrej/php && sudo apt-get -qq update && sudo apt-get install -y libsodium-dev # for secure session examples +# ./test.sh + +# tests-netty-http: +# name: Sbt Tests Netty HTTP +## needs: +## - "check-code-style" +# uses: playframework/.github/.github/workflows/cmd.yml@v3 +# with: +# java: 17, 11 +# scala: 2.13.x, 3.x +# cmd: | +# ./test.sh --netty + +# gradle-tests: +# name: Gradle Tests +# uses: playframework/.github/.github/workflows/cmd.yml@v3 +# with: +# java: 17, 11 +# scala: 2.13.x, 3.x +# cmd: | +# ./test-gradle.sh finish: name: Finish - if: github.event_name == 'pull_request' + if: ${{ github.event_name == 'pull_request' && !failure() && !cancelled() }} needs: # Should be last - - "tests-pekko-http" - - "tests-netty-http" - - "gradle-tests" - uses: playframework/.github/.github/workflows/rtm.yml@v3 +# - "tests-pekko-http" +# - "tests-netty-http" +# - "gradle-tests" + - "java-chatroom" + uses: playframework/.github/.github/workflows/rtm.yml@v4 diff --git a/play-java-chatroom-example/scripts/test-gradle b/play-java-chatroom-example/scripts/test-gradle deleted file mode 100755 index 5db141cd7..000000000 --- a/play-java-chatroom-example/scripts/test-gradle +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o pipefail - -echo "+-------------------------------+" -echo "| Executing tests using Gradle |" -echo "+-------------------------------+" -./gradlew -Dscala.version="$MATRIX_SCALA" check diff --git a/play-java-chatroom-example/scripts/test-sbt b/play-java-chatroom-example/scripts/test-sbt deleted file mode 100755 index 1b9abfac6..000000000 --- a/play-java-chatroom-example/scripts/test-sbt +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -echo "+----------------------------+" -echo "| Executing tests using sbt |" -echo "+----------------------------+" -sbt ++$MATRIX_SCALA test diff --git a/test.sh b/test.sh index 662a86baf..25b56c3ae 100755 --- a/test.sh +++ b/test.sh @@ -3,40 +3,89 @@ if [ -z "$MATRIX_SCALA" ]; then echo "Error: the environment variable MATRIX_SCALA is not set" exit 1 fi -if [[ $* == --netty ]]; then - find -name build.sbt | xargs sed -i 's/\/\/.enablePlugins(PlayNettyServer)/.enablePlugins(PlayNettyServer)/g' -fi -pushd play-java-chatroom-example && scripts/test-sbt && popd -pushd play-java-compile-di-example && scripts/test-sbt && popd -pushd play-java-dagger2-example && scripts/test-sbt && popd -pushd play-java-ebean-example && scripts/test-sbt && popd -pushd play-java-fileupload-example && scripts/test-sbt && popd -pushd play-java-forms-example && scripts/test-sbt && popd -pushd play-java-grpc-example && scripts/test-sbt && popd -pushd play-java-hello-world-tutorial && scripts/test-sbt && popd -pushd play-java-jpa-example && scripts/test-sbt && popd -pushd play-java-rest-api-example && scripts/test-sbt && popd -pushd play-java-starter-example && scripts/test-sbt && popd -pushd play-java-streaming-example && scripts/test-sbt && popd -pushd play-java-websocket-example && scripts/test-sbt && popd -pushd play-java-pekko-cluster-example && scripts/test-sbt && popd -#pushd play-scala-anorm-example && scripts/test-sbt && popd -pushd play-scala-chatroom-example && scripts/test-sbt && popd -pushd play-scala-compile-di-example && scripts/test-sbt && popd -pushd play-scala-fileupload-example && scripts/test-sbt && popd -pushd play-scala-forms-example && scripts/test-sbt && popd -pushd play-scala-grpc-example && scripts/test-sbt && popd -pushd play-scala-hello-world-tutorial && scripts/test-sbt && popd -pushd play-scala-isolated-slick-example && scripts/test-sbt && popd -pushd play-scala-log4j2-example && scripts/test-sbt && popd -pushd play-scala-macwire-di-example && scripts/test-sbt && popd -pushd play-scala-rest-api-example && scripts/test-sbt && popd -# Uses libsodium -pushd play-scala-secure-session-example && scripts/test-sbt && popd -pushd play-scala-slick-example && scripts/test-sbt && popd -pushd play-scala-starter-example && scripts/test-sbt && popd -pushd play-scala-streaming-example && scripts/test-sbt && popd -# uses vanilla sbt -pushd play-scala-tls-example && scripts/test-sbt && popd -pushd play-scala-websocket-example && scripts/test-sbt && popd +# Initialize variables +sample="" +backend_server="pekko" +build_tool="sbt" + +# Parse command line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --build-tool=*) build_tool="${1#*=}" ;; # Extract the value right of the equal sign + --backend-server=*) backend_server="${1#*=}" ;; # Extract the value right of the equal sign + --sample=*) sample="${1#*=}" ;; # Extract the value right of the equal sign + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift # Move to next argument +done + +function buildSample() { + local dir=$1 + pushd $dir + if [[ $build_tool == "gradle" ]]; then + if [ ! -f scripts/test-gradle ]; then + scripts/test-gradle + else + echo "+-----------------------------------------+" + echo "| Executing tests using Gradle (Default) |" + echo "+-----------------------------------------+" + ./gradlew -Dscala.version="$MATRIX_SCALA" check + fi + elif [[ $build_tool == "sbt" ]]; then + if [[ $backend_server == "netty" ]]; then + find . -name build.sbt | xargs sed -i '' 's/\/\/.enablePlugins(PlayNettyServer)/.enablePlugins(PlayNettyServer)/g' + fi + if [ ! -f scripts/test-sbt ]; then + scripts/test-sbt + else + echo "+----------------------------+" + echo "| Executing tests using sbt |" + echo "+----------------------------+" + sbt ++$MATRIX_SCALA test + fi + fi + popd > /dev/null +} + +if [ -n "$sample" ]; then + # Sample is set and not empty + buildSample $sample +else + # sample not set, therefore run all samples + buildSample play-java-chatroom-example + buildSample play-java-compile-di-example + buildSample play-java-chatroom-example + buildSample play-java-compile-di-example + buildSample play-java-dagger2-example + buildSample play-java-ebean-example + buildSample play-java-fileupload-example + buildSample play-java-forms-example + buildSample play-java-hello-world-tutorial + buildSample play-java-jpa-example + buildSample play-java-rest-api-example + buildSample play-java-starter-example + buildSample play-java-streaming-example + buildSample play-java-websocket-example + buildSample play-java-pekko-cluster-example + buildSample play-scala-rest-api-example + if [[ $build_tool == "sbt" ]]; then +# buildSample play-scala-anorm-example + buildSample play-java-grpc-example + buildSample play-scala-chatroom-example + buildSample play-scala-compile-di-example + buildSample play-scala-fileupload-example + buildSample play-scala-forms-example + buildSample play-scala-grpc-example + buildSample play-scala-hello-world-tutorial + buildSample play-scala-isolated-slick-example + buildSample play-scala-log4j2-example + buildSample play-scala-macwire-di-example + buildSample play-scala-secure-session-example + buildSample play-scala-slick-example + buildSample play-scala-starter-example + buildSample play-scala-streaming-example + buildSample play-scala-tls-example + buildSample play-scala-websocket-example + fi +fi