Skip to content

Commit

Permalink
Build only changed examples and do it parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ihostage committed Mar 7, 2024
1 parent c176e19 commit 698bd4d
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 83 deletions.
125 changes: 93 additions & 32 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 0 additions & 9 deletions play-java-chatroom-example/scripts/test-gradle

This file was deleted.

6 changes: 0 additions & 6 deletions play-java-chatroom-example/scripts/test-sbt

This file was deleted.

121 changes: 85 additions & 36 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 698bd4d

Please sign in to comment.