diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE deleted file mode 100644 index 67d94fd..0000000 --- a/.github/ISSUE_TEMPLATE +++ /dev/null @@ -1 +0,0 @@ -**GitHub Issues are deprecated. Use [Discuss Issues](https://discuss.dgraph.io/c/issues/35/clients/46) for reporting issues about this repository.** diff --git a/.github/workflows/ci-aqua-security-trivy-tests.yml b/.github/workflows/ci-aqua-security-trivy-tests.yml new file mode 100644 index 0000000..20e5e0b --- /dev/null +++ b/.github/workflows/ci-aqua-security-trivy-tests.yml @@ -0,0 +1,33 @@ +name: ci-aqua-security-trivy-tests +on: + push: + branches: + - master + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + branches: + - master + schedule: + - cron: "0 * * * *" +jobs: + build: + name: trivy-tests + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + scan-type: 'fs' + scan-ref: '.' + format: 'sarif' + output: 'trivy-results.sarif' + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: 'trivy-results.sarif' diff --git a/.github/workflows/ci-dgraph-js.yml b/.github/workflows/ci-dgraph-js.yml index ed1299e..68728d8 100644 --- a/.github/workflows/ci-dgraph-js.yml +++ b/.github/workflows/ci-dgraph-js.yml @@ -1,6 +1,4 @@ - name: ci-dgraph-js-tests - on: push: branches: @@ -13,27 +11,49 @@ on: - ready_for_review branches: - master - jobs: - build: - + dgraph-js-tests: runs-on: ubuntu-20.04 - strategy: + fail-fast: false matrix: - node-version: [18.x, 19.x] + node-version: [16.x, 18.x, 19.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} + - name: Checkout dgraph-js repo + uses: actions/checkout@v3 + with: + path: dgraph-js + repository: dgraph-io/dgraph-js + ref: ${{ github.ref }} + - name: Checkout dgraph repo + uses: actions/checkout@v3 + with: + path: dgraph + repository: dgraph-io/dgraph + ref: main + - name: Get Go Version + run: | + #!/bin/bash + cd dgraph + GOVERSION=$({ [ -f .go-version ] && cat .go-version; }) + echo "GOVERSION=$GOVERSION" >> $GITHUB_ENV + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GOVERSION }} + - name: Build dgraph binary + run: cd dgraph && make docker-image # also builds dgraph binary + - name: Move dgraph binary to gopath + run: cd dgraph && mv dgraph/dgraph ~/go/bin/dgraph + - name: Setup node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'npm' - - name: Install Dependencies - run: bash ./scripts/install_dgraph.sh - - name: run tests + cache-dependency-path: dgraph-js/package-lock.json + - name: Run dgraph-js tests + working-directory: dgraph-js run: | npm ci --legacy-peer-deps - bash ./scripts/build.sh + bash scripts/run-tests.sh diff --git a/hmac-secret b/hmac-secret deleted file mode 100644 index 0c50847..0000000 --- a/hmac-secret +++ /dev/null @@ -1 +0,0 @@ -vZMu1Snb6t66aFKEPQYTxvejObeNkfEf diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index bb61bf6..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -e -set -x - -source ./scripts/functions.sh - -init -startZero -start - -sleep 10 # Dgraph need some time to create Groot user - -npm run build - -curl http://localhost:8080/health - -npm test - -quit 0 diff --git a/scripts/functions.sh b/scripts/functions.sh deleted file mode 100644 index 9648bb7..0000000 --- a/scripts/functions.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -sleepTime=5 - -function quit { - echo "Shutting down Dgraph alpha and zero." - curl -s localhost:8080/admin/shutdown #TODO In the future this endpoint won't work anymore, in favor of GraphQL. We should prepare it. - - kill -9 $(pgrep -f "dgraph zero") > /dev/null # Kill Dgraph zero. - kill -9 $(pgrep -f "dgraph alpha") > /dev/null # I don't wanna wait "clean shutdown" on this context. Let's kill it please... - - if pgrep -x dgraph > /dev/null - then - echo "Sleeping for 5 secs so that Dgraph can shutdown." - sleep 5 - fi - - echo "Clean shutdown done." - return $1 -} - -function start { - echo -e "Starting Dgraph alpha." - head -c 1024 /dev/random > ./scripts/data/acl-secret.txt - dgraph alpha -p ./scripts/data/p -w ./scripts/data/w --bindall --my localhost:7080 --acl "access-ttl=1h; refresh-ttl=1d; secret-file=./scripts/data/acl-secret.txt"> ./scripts/data/alpha.log 2>&1 & - # Wait for membership sync to happen. - sleep $sleepTime - return 0 -} - -function startZero { - echo -e "Starting Dgraph zero.\n" - dgraph zero --my localhost:5080 --bindall -w ./scripts/data/wz> ./scripts/data/zero.log 2>&1 & - # To ensure Dgraph doesn't start before Dgraph zero. - sleep $sleepTime -} - -function init { - echo -e "Initializing.\n" - mkdir ./scripts/data -} diff --git a/scripts/install_dgraph.sh b/scripts/install_dgraph.sh deleted file mode 100644 index 72067e3..0000000 --- a/scripts/install_dgraph.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -curl https://get.dgraph.io -sSf | bash -s -- -y diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100644 index 0000000..f5cbf5b --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +sleepTime=5 + +function wait-for-healthy() { + printf 'wait-for-healthy: waiting for %s to return 200 OK\n' "$1" + tries=0 + until curl -sL -w "%{http_code}\\n" "$1" -o /dev/null | grep -q 200; do + tries=$tries+1 + if [[ $tries -gt 300 ]]; then + printf "wait-for-healthy: Took longer than 1 minute to be healthy.\n" + printf "wait-for-healthy: Waiting stopped.\n" + return 1 + fi + sleep 0.2 + done + printf "wait-for-healthy: done.\n" +} + +function errorCheck { + EXIT_CODE=$1 + ERROR_MESSAGE=$2 + + if [[ EXIT_CODE -ne 0 ]]; then + echo $ERROR_MESSAGE + stopCluster + exit $EXIT_CODE + fi + return 0 +} + +function stopCluster { + echo "shutting down dgraph alpha and zero..." + kill -9 $(pgrep -f "dgraph zero") > /dev/null # kill dgraph zero + kill -9 $(pgrep -f "dgraph alpha") > /dev/null # kill dgraph alpha + + if pgrep -x dgraph > /dev/null + then + echo "sleeping for 5 seconds so dgraph can shutdown" + sleep 5 + fi + + echo "cluster teardown complete" + return 0 +} + +function startAlpha { + echo -e "starting dgraph alpha..." + head -c 1024 /dev/random > $SRCDIR/dgraph-local-data/acl-secret.txt + dgraph alpha -p $SRCDIR/dgraph-local-data/p \ + -w $SRCDIR/dgraph-local-data/w \ + --bindall \ + --my localhost:7080 \ + --acl "access-ttl=1h; refresh-ttl=1d; secret-file=$SRCDIR/dgraph-local-data/acl-secret.txt" \ + > $SRCDIR/dgraph-local-data/alpha.log 2>&1 & + + # wait for alpha to be healthy + ALPHA_HTTP_ADDR="localhost:8080" + wait-for-healthy $ALPHA_HTTP_ADDR/health + errorCheck $? "dgraph alpha could not come up" + sleep $sleepTime + return 0 +} + +function startZero { + echo -e "starting dgraph zero..." + dgraph zero --my localhost:5080 --bindall \ + -w $SRCDIR/dgraph-local-data/wz > $SRCDIR/dgraph-local-data/zero.log 2>&1 & + + # wait for zero to be healthy + ZERO_HTTP_ADDR="localhost:6080" + wait-for-healthy $ZERO_HTTP_ADDR/health + errorCheck $? "dgraph zero could not come up" + sleep $sleepTime +} + +function init { + echo -e "initializing..." + rm -rf $SRCDIR/dgraph-local-data + mkdir $SRCDIR/dgraph-local-data +} + +# find parent directory of test script +readonly _SRCDIR=$(readlink -f ${BASH_SOURCE[0]%/*}) +SRCDIR=$(dirname $_SRCDIR) + +init +startZero +startAlpha +sleep 10 # need time to create Groot user + +npm run build + +npm test +errorCheck $? "dgraph-js-http client tests FAILED" + +stopCluster +rm -rf $SRCDIR/local-dgraph-data +exit 0