-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10023 from murdos/feat/custom-jhlite-test-scripts
feat(custom-jhlite): add shell scripts for helping testing generated apps in ci
- Loading branch information
Showing
7 changed files
with
169 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/resources/generator/server/springboot/custom-jhlite/tests-ci/generate.sh.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env bash | ||
|
||
show_syntax() { | ||
echo "Usage: $0 <application> <java-build-tool> <spring-configuration-format>" >&2 | ||
exit 1 | ||
} | ||
|
||
if [ "$#" -ne 3 ]; then | ||
show_syntax | ||
fi | ||
|
||
if test -f "modulePayload.json"; then | ||
payloadFile="modulePayload.json" | ||
elif test -f tests-ci/modulePayload.json; then | ||
payloadFile=tests-ci/modulePayload.json | ||
fi | ||
|
||
application=$1 | ||
java_build_tool=$2 | ||
configuration_format=$3 | ||
|
||
applyModules() { | ||
for module in $@ | ||
do | ||
local payload="$(sed -e "s/APP_NAME/$application/g;s/SPRING_CONFIG_FORMAT/$configuration_format/g" $payloadFile)" | ||
local api="/api/modules/$module/apply-patch" | ||
|
||
echo "curl -o /dev/null -s -w "%{http_code}\n" \ | ||
-X POST \ | ||
-H "accept: */*" \ | ||
-H "Content-Type: application/json" \ | ||
-d "$payload" \ | ||
"http://localhost:{{serverPort}}""$api"" | ||
|
||
local status_code=$(curl -o /dev/null -s -w "%{http_code}\n" \ | ||
-X POST \ | ||
-H "accept: */*" \ | ||
-H "Content-Type: application/json" \ | ||
-d "$payload" \ | ||
"http://localhost:{{serverPort}}""$api") | ||
|
||
if [[ $status_code == '40'* || $status_code == '50'* ]]; then | ||
echo "Error when calling API:" "$status_code" "$api" | ||
exit 1 | ||
fi; | ||
done | ||
} | ||
|
||
init_server() { | ||
applyModules \ | ||
"init" \ | ||
"${java_build_tool}-wrapper" \ | ||
"${java_build_tool}-java" | ||
} | ||
|
||
if [[ $application == 'fullapp' ]]; then | ||
init_server | ||
# apply here your custom modules | ||
|
||
else | ||
echo "*** Unknown configuration..." | ||
exit 1 | ||
fi | ||
|
||
echo "" | ||
cat "$payloadFile" | ||
echo "" | ||
sleep 5 |
14 changes: 14 additions & 0 deletions
14
.../resources/generator/server/springboot/custom-jhlite/tests-ci/modulePayload.json.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"projectFolder": "/tmp/jhlite/APP_NAME", | ||
"commit": true, | ||
"parameters": { | ||
"projectName": "Chips Project", | ||
"serverPort": 8081, | ||
"baseName": "APP_NAME", | ||
"packageName": "{{packageName}}.APP_NAME", | ||
"jwtBase64Secret": "NmE2NDhmMmQ5OWQzYzk4NmE4NjNlMmQzNmU3ZTU4ZDY2MmUxOWEwZGI4YTk4NDY0MTk4MmQyMWZlNDNlM2FjYg==", | ||
"date": "2021-12-03T10:15:30.00Z", | ||
"kafkaClusterId": "7870e9ec-dd1f-4562-86a2-df2199d5db1a", | ||
"springConfigurationFormat": "SPRING_CONFIG_FORMAT" | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/resources/generator/server/springboot/custom-jhlite/tests-ci/start.sh.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
PORT=$1 | ||
if [[ $PORT == '' ]]; then | ||
echo "*** Using default port {{serverPort}}" | ||
PORT='{{serverPort}}' | ||
fi | ||
|
||
echo "*** Waiting 5sec to be sure the Jar is here" | ||
sleep 5 | ||
|
||
echo "*** List folder" | ||
ls -al | ||
|
||
if test -f "mvnw"; then | ||
JAR_DIRECTORY="target" | ||
elif test -f "gradlew"; then | ||
JAR_DIRECTORY="build/libs/" | ||
fi | ||
|
||
echo "*** Identifying application executable..." | ||
export EXEC_JAR=$(\ | ||
find ${JAR_DIRECTORY} -maxdepth 1 -name "*-exec.jar" | grep . \ | ||
|| find ${JAR_DIRECTORY} -maxdepth 1 -name "*.jar" | grep -v "\-javadoc" | grep -v "\-sources" | grep -v "\-tests" | grep -v "\-plain" \ | ||
) | ||
|
||
echo "*** Starting application using ${EXEC_JAR}..." | ||
java \ | ||
-jar ${EXEC_JAR} \ | ||
--logging.level.ROOT=OFF & > /dev/null | ||
echo $! > .pid-jhlite | ||
|
||
retryCount=1 | ||
maxRetry=30 | ||
httpUrl="http://localhost:"$PORT"/management/health" | ||
|
||
rep=$(curl -v "$httpUrl") | ||
status=$? | ||
while [ "$status" -ne 0 ] && [ "$retryCount" -le "$maxRetry" ]; do | ||
echo "*** [$(date)] Application not reachable yet. Sleep and retry - retryCount =" $retryCount "/" $maxRetry | ||
retryCount=$((retryCount+1)) | ||
sleep 5 | ||
rep=$(curl -v "$httpUrl") | ||
status=$? | ||
done | ||
|
||
if [ "$status" -ne 0 ]; then | ||
echo "*** [$(date)] Not connected after" $retryCount " retries." | ||
exit 1 | ||
fi |
5 changes: 5 additions & 0 deletions
5
src/main/resources/generator/server/springboot/custom-jhlite/tests-ci/stop.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "*** Stopping JHipster Lite in 5sec..." | ||
sleep 5 | ||
kill $(cat .pid-jhlite) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters