Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(CI): add CI #307

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/ci-ratel.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"",
Expand Down
23 changes: 23 additions & 0 deletions scripts/runDgraph.sh
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions scripts/testGA.sh
Original file line number Diff line number Diff line change
@@ -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