diff --git a/.github/workflows/ci-ratel.yml b/.github/workflows/ci-ratel.yml new file mode 100644 index 0000000..59b7796 --- /dev/null +++ b/.github/workflows/ci-ratel.yml @@ -0,0 +1,81 @@ +name: Ratel-tests + +on: + push: + branches: [ master ] + paths-ignore: + - '**.md' + pull_request: + branches: [ master ] + paths-ignore: + - '**.md' + +jobs: + test: + name: Test on node 14 and Ubuntu + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [1.x] + env: + GOPATH: ${{ github.workspace }}/go + + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 1 + path: go/src/github.com/${{ github.repository }} + + - name: Use Node.js 14 + uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: Get dependencies + run: | + cd go/src/github.com/${{ github.repository }} + go get github.com/jteeuwen/go-bindata/go-bindata + go get -v -t -d ./... + if [ -f go.mod ]; then + go mod tidy + fi + + - name: Install Dgraph + run: sudo curl https://get.dgraph.io -sSf | bash -s -- --accept-license + + - name: Get npm cache directory + id: npm-cache + run: | + echo "::set-output name=dir::$(npm config get cache)" + - uses: actions/cache@v2 + with: + path: ${{ steps.npm-cache.outputs.dir }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: => Building client files... + shell: bash + env: + CI: "" + run: | + cd go/src/github.com/${{ github.repository }}/client + yarn cleanup + yarn install + yarn build:prod + + - name: Build Ratel Binary + run: | + cd go/src/github.com/${{ github.repository }} + bash scripts/build.prod.sh --skip + + - name: Run e2e tests + run: | + cd go/src/github.com/${{ github.repository }} + bash scripts/runDgraph.sh && sleep 2 & bash scripts/testGA.sh diff --git a/client/package.json b/client/package.json index 6a24f34..20014ef 100644 --- a/client/package.json +++ b/client/package.json @@ -16,6 +16,7 @@ "scripts": { "start": "node scripts/start.js", "build": "node scripts/build.js", + "cleanup": "rm -rf node_modules build", "build:prod": "node scripts/build.js", "build:local": "node scripts/build.js", "prettier": "prettier --write \"src/**/*.{js,jsx,mjs,json,scss}\"", diff --git a/scripts/runDgraph.sh b/scripts/runDgraph.sh new file mode 100644 index 0000000..a7dd2b8 --- /dev/null +++ b/scripts/runDgraph.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +# Set the script directory +script_dir=$(dirname "$0") + +# Change to the script directory +cd "$script_dir" + +# Create a random secret for ACL +head -c 1024 /dev/random > ./data/acl-secret.txt + +# Start Dgraph Zero +dgraph zero & +# Wait for 2 seconds to allow Zero to initialize +sleep 2 + +# Start Dgraph Alpha with the generated ACL secret file +dgraph alpha --acl_secret_file=./data/acl-secret.txt & + +# Start Ratel using the build in the parent directory +../build/ratel diff --git a/scripts/testGA.sh b/scripts/testGA.sh new file mode 100644 index 0000000..38032f3 --- /dev/null +++ b/scripts/testGA.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Run Dgraph cluster and prod-build of Ratel to run Ratel tests +# (including end-to-end tests). +# The script returns with exit-code 0 if the tests pass, and non-zero +# exit code if the tests fail. +# You must have Puppeteer installed locally for these tests to run. +# "npm test" runs on the local machine. + +# Function to wait for a URL to return 200 OK +wait_for_healthy() { + local url=$1 + echo "Waiting for $url to return 200 OK" + local tries=0 + + until curl -sL -w "%{http_code}\\n" "$url" -o /dev/null | grep -q 200; do + tries=$((tries + 1)) + if [[ $tries -gt 300 ]]; then + echo "Took longer than 1 minute to be healthy. Waiting stopped." + return 1 + fi + sleep 0.2 + done + echo "Done waiting for $url." +} + +# Determine script and project directories +script_dir="$( cd "$( echo "${BASH_SOURCE[0]%/*}" )" && pwd )" +root_dir="$script_dir/.." +client_dir="$root_dir/client" +compose_dir="$client_dir/src/e2etests" + +cd "$root_dir" + +# Wait for Ratel and Dgraph to be healthy +wait_for_healthy "localhost:8080/health" +wait_for_healthy "localhost:8000" + +# Run tests +pushd "$client_dir" > /dev/null +TEST_DGRAPH_SERVER="http://localhost:8080" TEST_RATEL_URL="http://localhost:8000?local" npm test -- --runInBand --testTimeout 40000 +test_results="$?" +popd > /dev/null + +# Exit with test results status code +exit $test_results