Skip to content

Commit

Permalink
Merge pull request #9 from JeremyEastham/master
Browse files Browse the repository at this point in the history
feat: Run Core Script, Script Options, Script Consolidation
  • Loading branch information
rishabhpoddar authored Apr 24, 2022
2 parents c2ec044 + 2472498 commit d7b0cf1
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 388 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ releasePassword
install
install.bat
LICENSE.md
.testEnvRunning



Expand Down
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Run_All_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/runConfigurations/Run_Core.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Start_Testing_Environment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Docker image for testing

- the script `createPostgresqlImage.sh` here is used to create docker image with postgresql plugin.
- Before the user runs this script, they need to start the testing env (i.e. `./startTestingEnv --wait`).
- Before the user runs this script, they need to start the testing env (i.e. `./startTestEnv --wait`).
- This script can only be used for postgresql plugin. No other plugin is supported. So before running the script, make sure to switch to postgresql-plugin in the `modules.txt`.


Expand Down
52 changes: 52 additions & 0 deletions runCore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

function cleanup {
kill %1 > /dev/null # Send exit to startTestEnv
}

usage="Usage: runCore [--help] [--silent] [--cicd] [--force]"
silent=false
cicd=false
force=false

# Based on https://stackoverflow.com/a/33826763/11827673
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) echo "$usage"; exit ;;
-s|--silent) silent=true ;;
-c|--cicd) cicd=true ;;
-f|--force) force=true ;;
*) echo "Unknown parameter passed: $1"; echo "$usage"; exit 1 ;;
esac
shift
done

if [[ $force = true && -f .testEnvRunning ]]; then
[[ $silent = false ]] && echo "Removing previous testing environment..."
if [[ $cicd = true ]]; then
./utils/cleanTestEnv --cicd
else
./utils/cleanTestEnv --local
fi
fi

trap cleanup EXIT

./startTestEnv --wait --silent & # Run in background

[[ $silent = false ]] && echo "Waiting for testing environment to start..."
until [[ -f .testEnvRunning ]]
do
sleep 1
done
[[ $silent = false ]] && echo "Test environment started!"
cp ./temp/config.yaml .
[[ $silent = false ]] && echo "Starting core..."

classpath="./core/*:./plugin-interface/*"

if which cygpath > /dev/null; then # Convert path to Windows-style if using Git Bash
classpath="$(cygpath -C ANSI -w -p "${classpath}")"
fi

java -classpath "${classpath}" io.supertokens.Main ./ DEV
55 changes: 55 additions & 0 deletions startTestEnv
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

function cleanup {
if [[ $cicd = true ]]; then
./utils/cleanTestEnv --cicd
else
./utils/cleanTestEnv --local
fi
}

usage="Usage: startTestEnv [--help] [--wait] [--silent] [--cicd] [--force]"
wait=false
silent=false
cicd=false
force=false

# Based on https://stackoverflow.com/a/33826763/11827673
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) echo "$usage"; exit ;;
-w|--wait) wait=true ;;
-s|--silent) silent=true ;;
-c|--cicd) cicd=true ;;
-f|--force) force=true ;;
*) echo "Unknown parameter passed: $1"; echo "$usage"; exit 1 ;;
esac
shift
done

if [[ $force = true && -f .testEnvRunning ]]; then
[[ $silent = false ]] && echo "Removing previous testing environment..."
cleanup
fi

trap cleanup EXIT

[[ $silent = false ]] && echo "Setting up testing environment..."
if [[ $cicd = true ]]; then
./utils/setupTestEnv --cicd
else
./utils/setupTestEnv --local
fi


if [[ $wait = true ]]; then
[[ $silent = false ]] && echo "Test environment started! Leave this script running while running tests."
# Wait for the user to end the session
while true; do
sleep 1
done
else
[[ $silent = false ]] && echo "Running all tests..."
# Tests are run relative to the project's folder
./gradlew test
fi
48 changes: 4 additions & 44 deletions startTestingEnv
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
#!/bin/bash

function cleanup {
if [[ $1 = "--cicd" ]]
then
./utils/cleanTestEnvCicd
else
./utils/cleanTestEnvLocal
fi
}

trap cleanup EXIT

wait=false

if [[ $1 = "--cicd" ]]
then
if [[ $2 = "--wait" ]]
then
wait=true
fi
./utils/setupTestEnvCicd
else
if [[ $1 = "--wait" ]]
then
wait=true
fi
./utils/setupTestEnvLocal
fi


if [[ $wait = "true" ]]
then
echo "Test environment started! Leave this script running while running tests."
# we wait for user to end the session
while [[ true ]]
do
echo "Test environment running..."
sleep 2
done
else
echo "Running all tests..."
# ../ because the tests are run relative to the project's folder.
./gradlew test
fi
RED="\033[0;31m"
NC="\033[0m"
printf "${RED}WARNING: startTestingEnv is DEPRECATED! Use startTestEnv instead.${NC}\n" >&2
./startTestEnv "$@" # Pass all arguments
30 changes: 30 additions & 0 deletions utils/cleanTestEnv
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

usage="Usage: cleanTestEnv [--help] [ [--cicd] | [--local] ] [--silent]"
cicd=false
silent=false

# Based on https://stackoverflow.com/a/33826763/11827673
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) echo "$usage"; exit ;;
-c|--cicd) cicd=true ;;
-l|--local) cicd=false ;;
-s|--silent) silent=true ;;
*) echo "Unknown parameter passed: $1"; echo "$usage"; exit 1 ;;
esac
shift
done

rm -rf core
rm -rf plugin-interface
rm -rf plugin
rm -rf cli
rm -rf downloader
rm version.yaml
rm -rf temp
rm install
rm install.bat
rm LICENSE.md
rm .testEnvRunning
[[ $silent = false ]] && echo "Testing environment destroyed."
15 changes: 4 additions & 11 deletions utils/cleanTestEnvCicd
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#!/bin/bash
rm -rf core
rm -rf plugin-interface
rm -rf plugin
rm -rf cli
rm -rf downloader
rm version.yaml
rm -rf temp
rm install
rm install.bat
rm LICENSE.md
rm .testEnvRunning
RED="\033[0;31m"
NC="\033[0m"
printf "${RED}WARNING: cleanTestEnvCicd is DEPRECATED! Use cleanTestEnv --cicd instead.${NC}\n" >&2
./utils/cleanTestEnv --cicd "$@" # Pass all arguments
15 changes: 4 additions & 11 deletions utils/cleanTestEnvLocal
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#!/bin/bash
rm -rf core
rm -rf plugin-interface
rm -rf plugin
rm -rf cli
rm -rf downloader
rm version.yaml
rm -rf temp
rm install
rm install.bat
rm LICENSE.md
rm .testEnvRunning
RED="\033[0;31m"
NC="\033[0m"
printf "${RED}WARNING: cleanTestEnvLocal is DEPRECATED! Use cleanTestEnv instead.${NC}\n" >&2
./utils/cleanTestEnv --local "$@" # Pass all arguments
34 changes: 16 additions & 18 deletions utils/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# get current version----------

version=`cat build.gradle | grep -e "version =" -e "version="`
Expand Down Expand Up @@ -27,40 +31,34 @@ branch_name=${branch_name##refs/heads/}

if [ $branch_name == "master" ]
then
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
printf "${YELLOW}committing to MASTER${NC}\n"
printf "${YELLOW}Committing to MASTER${NC}\n"
elif [[ $version == $branch_name* ]]
then
continue=1
elif ! [[ $branch_name =~ ^[0-9].[0-9]$ ]]
then
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
printf "${YELLOW}Not committing to master or version branches${NC}\n"
printf "${YELLOW}Not committing to master or version branches${NC}\n"
else
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "${RED}Pushing to wrong branch. Stopping commit${NC}\n"
exit 1
printf "${RED}Pushing to wrong branch. Stopping commit${NC}\n"
exit 1
fi

(cd ../ && ./gradlew spotlessCheck < /dev/null)
if [[ $? -ne 0 ]]
then
printf "${RED}Linting FAILED, please run './gradlew spotlessApply' in supertokens-root or the 'Lint' run configuration in IntelliJ IDEA${NC}\n"
exit 1
fi

./runBuild

if [[ $? -ne 0 ]]
then
echo "Failed to build"
printf "${RED}Build FAILED${NC}"
exit 1
fi

# We have to do git restore twice like this other jar changes in ./jar/* do not get reset
# We also have to maintain this order since in some projects ./**/jar/ does not exist
git restore "./**/jar/*" > /dev/null 2>&1
git restore "./jar/*" > /dev/null 2>&1

(cd ../ && ./gradlew spotlessCheck < /dev/null)
if [[ $? -ne 0 ]]
then
echo "Linting failed, please run './gradlew spotlessApply' in supertokens-root"
exit 1
fi
Loading

0 comments on commit d7b0cf1

Please sign in to comment.