Skip to content

Commit 19d4145

Browse files
chore(ci): cleanup CI workflow + add security scanning (#173)
* update ci workflow * remove issue template * update test script * remove secret and add security scanning
1 parent 7191f34 commit 19d4145

File tree

8 files changed

+166
-80
lines changed

8 files changed

+166
-80
lines changed

.github/ISSUE_TEMPLATE

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ci-aqua-security-trivy-tests
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
- ready_for_review
12+
branches:
13+
- master
14+
schedule:
15+
- cron: "0 * * * *"
16+
jobs:
17+
build:
18+
name: trivy-tests
19+
runs-on: ubuntu-20.04
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v3
23+
- name: Run Trivy vulnerability scanner
24+
uses: aquasecurity/trivy-action@master
25+
with:
26+
scan-type: 'fs'
27+
scan-ref: '.'
28+
format: 'sarif'
29+
output: 'trivy-results.sarif'
30+
- name: Upload Trivy scan results to GitHub Security tab
31+
uses: github/codeql-action/upload-sarif@v2
32+
with:
33+
sarif_file: 'trivy-results.sarif'

.github/workflows/ci-dgraph-js.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
21
name: ci-dgraph-js-tests
3-
42
on:
53
push:
64
branches:
@@ -13,27 +11,49 @@ on:
1311
- ready_for_review
1412
branches:
1513
- master
16-
1714
jobs:
18-
build:
19-
15+
dgraph-js-tests:
2016
runs-on: ubuntu-20.04
21-
2217
strategy:
18+
fail-fast: false
2319
matrix:
24-
node-version: [18.x, 19.x]
20+
node-version: [16.x, 18.x, 19.x, 20.x]
2521
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
26-
2722
steps:
28-
- uses: actions/checkout@v3
29-
- name: Use Node.js ${{ matrix.node-version }}
23+
- name: Checkout dgraph-js repo
24+
uses: actions/checkout@v3
25+
with:
26+
path: dgraph-js
27+
repository: dgraph-io/dgraph-js
28+
ref: ${{ github.ref }}
29+
- name: Checkout dgraph repo
30+
uses: actions/checkout@v3
31+
with:
32+
path: dgraph
33+
repository: dgraph-io/dgraph
34+
ref: main
35+
- name: Get Go Version
36+
run: |
37+
#!/bin/bash
38+
cd dgraph
39+
GOVERSION=$({ [ -f .go-version ] && cat .go-version; })
40+
echo "GOVERSION=$GOVERSION" >> $GITHUB_ENV
41+
- name: Set up Go
42+
uses: actions/setup-go@v3
43+
with:
44+
go-version: ${{ env.GOVERSION }}
45+
- name: Build dgraph binary
46+
run: cd dgraph && make docker-image # also builds dgraph binary
47+
- name: Move dgraph binary to gopath
48+
run: cd dgraph && mv dgraph/dgraph ~/go/bin/dgraph
49+
- name: Setup node.js ${{ matrix.node-version }}
3050
uses: actions/setup-node@v3
3151
with:
3252
node-version: ${{ matrix.node-version }}
3353
cache: 'npm'
34-
- name: Install Dependencies
35-
run: bash ./scripts/install_dgraph.sh
36-
- name: run tests
54+
cache-dependency-path: dgraph-js/package-lock.json
55+
- name: Run dgraph-js tests
56+
working-directory: dgraph-js
3757
run: |
3858
npm ci --legacy-peer-deps
39-
bash ./scripts/build.sh
59+
bash scripts/run-tests.sh

hmac-secret

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/build.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

scripts/functions.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

scripts/install_dgraph.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/run-tests.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
3+
sleepTime=5
4+
5+
function wait-for-healthy() {
6+
printf 'wait-for-healthy: waiting for %s to return 200 OK\n' "$1"
7+
tries=0
8+
until curl -sL -w "%{http_code}\\n" "$1" -o /dev/null | grep -q 200; do
9+
tries=$tries+1
10+
if [[ $tries -gt 300 ]]; then
11+
printf "wait-for-healthy: Took longer than 1 minute to be healthy.\n"
12+
printf "wait-for-healthy: Waiting stopped.\n"
13+
return 1
14+
fi
15+
sleep 0.2
16+
done
17+
printf "wait-for-healthy: done.\n"
18+
}
19+
20+
function errorCheck {
21+
EXIT_CODE=$1
22+
ERROR_MESSAGE=$2
23+
24+
if [[ EXIT_CODE -ne 0 ]]; then
25+
echo $ERROR_MESSAGE
26+
stopCluster
27+
exit $EXIT_CODE
28+
fi
29+
return 0
30+
}
31+
32+
function stopCluster {
33+
echo "shutting down dgraph alpha and zero..."
34+
kill -9 $(pgrep -f "dgraph zero") > /dev/null # kill dgraph zero
35+
kill -9 $(pgrep -f "dgraph alpha") > /dev/null # kill dgraph alpha
36+
37+
if pgrep -x dgraph > /dev/null
38+
then
39+
echo "sleeping for 5 seconds so dgraph can shutdown"
40+
sleep 5
41+
fi
42+
43+
echo "cluster teardown complete"
44+
return 0
45+
}
46+
47+
function startAlpha {
48+
echo -e "starting dgraph alpha..."
49+
head -c 1024 /dev/random > $SRCDIR/dgraph-local-data/acl-secret.txt
50+
dgraph alpha -p $SRCDIR/dgraph-local-data/p \
51+
-w $SRCDIR/dgraph-local-data/w \
52+
--bindall \
53+
--my localhost:7080 \
54+
--acl "access-ttl=1h; refresh-ttl=1d; secret-file=$SRCDIR/dgraph-local-data/acl-secret.txt" \
55+
> $SRCDIR/dgraph-local-data/alpha.log 2>&1 &
56+
57+
# wait for alpha to be healthy
58+
ALPHA_HTTP_ADDR="localhost:8080"
59+
wait-for-healthy $ALPHA_HTTP_ADDR/health
60+
errorCheck $? "dgraph alpha could not come up"
61+
sleep $sleepTime
62+
return 0
63+
}
64+
65+
function startZero {
66+
echo -e "starting dgraph zero..."
67+
dgraph zero --my localhost:5080 --bindall \
68+
-w $SRCDIR/dgraph-local-data/wz > $SRCDIR/dgraph-local-data/zero.log 2>&1 &
69+
70+
# wait for zero to be healthy
71+
ZERO_HTTP_ADDR="localhost:6080"
72+
wait-for-healthy $ZERO_HTTP_ADDR/health
73+
errorCheck $? "dgraph zero could not come up"
74+
sleep $sleepTime
75+
}
76+
77+
function init {
78+
echo -e "initializing..."
79+
rm -rf $SRCDIR/dgraph-local-data
80+
mkdir $SRCDIR/dgraph-local-data
81+
}
82+
83+
# find parent directory of test script
84+
readonly _SRCDIR=$(readlink -f ${BASH_SOURCE[0]%/*})
85+
SRCDIR=$(dirname $_SRCDIR)
86+
87+
init
88+
startZero
89+
startAlpha
90+
sleep 10 # need time to create Groot user
91+
92+
npm run build
93+
94+
npm test
95+
errorCheck $? "dgraph-js-http client tests FAILED"
96+
97+
stopCluster
98+
rm -rf $SRCDIR/local-dgraph-data
99+
exit 0

0 commit comments

Comments
 (0)