From af637db181a43552d962189f28468bb098f01709 Mon Sep 17 00:00:00 2001 From: liningrui Date: Wed, 23 Jun 2021 20:46:53 +0800 Subject: [PATCH] Use github action to run ci Change-Id: Ic77c4ee09f3375252b611c8f3e282a5be5499dcd --- .github/workflows/ci.yml | 61 +++++++++++++++++++ .../baidu/hugegraph/api/graph/EdgeAPI.java | 2 +- .../src/assembly/travis/build-report.sh | 2 + .../src/assembly/travis/install-backend.sh | 10 ++- .../travis/install-mysql-via-docker.sh | 16 +++++ .../travis/install-postgresql-via-docker.sh | 23 +++++++ .../src/assembly/travis/run-api-test.sh | 6 +- .../src/assembly/travis/run-unit-test.sh | 2 + .../src/assembly/travis/start-server.sh | 1 + 9 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100755 hugegraph-dist/src/assembly/travis/install-mysql-via-docker.sh create mode 100755 hugegraph-dist/src/assembly/travis/install-postgresql-via-docker.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..c3d2b1c0a6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,61 @@ +name: hugegraph ci + +on: + push: + branches: + - master + - /^release-.*$/ + - /^test-.*$/ + pull_request: + branches: + - master + - /^release-.*$/ + - /^test-.*$/ + +jobs: + build: + runs-on: ubuntu-16.04 + env: + TRAVIS_DIR: hugegraph-dist/src/assembly/travis + strategy: + fail-fast: false + matrix: + BACKEND: [memory, cassandra, scylladb, hbase, rocksdb] + steps: + - name: Install JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 2 + + - name: Compile + run: | + mvn compile -Dmaven.javadoc.skip=true | grep -v "Downloading\|Downloaded" + + - name: Prepare env and service + run: | + $TRAVIS_DIR/install-backend.sh ${{ matrix.BACKEND }} + + - name: Run test + run: | + mvn test -P core-test,${{ matrix.BACKEND }} + $TRAVIS_DIR/run-api-test.sh ${{ matrix.BACKEND }} + $TRAVIS_DIR/run-unit-test.sh ${{ matrix.BACKEND }} + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1.0.2 + with: + token: ${{secrets.CODECOV_TOKEN}} + file: target/site/jacoco/jacoco.xml diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java index c146e9e449..e2913a7247 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java @@ -403,7 +403,7 @@ private static Vertex getVertex(HugeGraph graph, throw new IllegalArgumentException(String.format( "Invalid vertex id '%s'", id)); } - if (!vertex.label().equals(label)) { + if (label != null && !vertex.label().equals(label)) { throw new IllegalArgumentException(String.format( "The label of vertex '%s' is unmatched, users expect " + "label '%s', actual label stored is '%s'", diff --git a/hugegraph-dist/src/assembly/travis/build-report.sh b/hugegraph-dist/src/assembly/travis/build-report.sh index 71f70cc016..06720debbe 100755 --- a/hugegraph-dist/src/assembly/travis/build-report.sh +++ b/hugegraph-dist/src/assembly/travis/build-report.sh @@ -2,6 +2,8 @@ set -ev +BACKEND=$1 + OPTION_CLASS_FILES_BACKEND="--classfiles hugegraph-$BACKEND/target/classes/com/baidu/hugegraph" if [ "$BACKEND" == "memory" ]; then # hugegraph-memory is the same as hugegraph-core diff --git a/hugegraph-dist/src/assembly/travis/install-backend.sh b/hugegraph-dist/src/assembly/travis/install-backend.sh index 75a53e612c..a7c8c50025 100755 --- a/hugegraph-dist/src/assembly/travis/install-backend.sh +++ b/hugegraph-dist/src/assembly/travis/install-backend.sh @@ -2,6 +2,12 @@ set -ev +if [[ $# -ne 1 ]]; then + echo "Must pass BACKEND type of hugegraph" + exit 1 +fi + +BACKEND=$1 TRAVIS_DIR=`dirname $0` if [ ! -d $HOME/downloads ]; then @@ -19,10 +25,10 @@ case $BACKEND in $TRAVIS_DIR/install-hbase.sh ;; mysql) - $TRAVIS_DIR/install-mysql.sh + $TRAVIS_DIR/install-mysql-via-docker.sh ;; postgresql) - $TRAVIS_DIR/install-postgresql.sh + $TRAVIS_DIR/install-postgresql-via-docker.sh ;; *) # don't need to install for other backends diff --git a/hugegraph-dist/src/assembly/travis/install-mysql-via-docker.sh b/hugegraph-dist/src/assembly/travis/install-mysql-via-docker.sh new file mode 100755 index 0000000000..b98876c5c2 --- /dev/null +++ b/hugegraph-dist/src/assembly/travis/install-mysql-via-docker.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -ev + +TRAVIS_DIR=`dirname $0` + +# Need speed up it +CONF=hugegraph-test/src/main/resources/hugegraph.properties +MYSQL_USERNAME=root +MYSQL_PASSWORD=123456 +# Set MySQL configurations +sed -i "s/jdbc.username=.*/jdbc.username=$MYSQL_USERNAME/" $CONF +sed -i "s/jdbc.password=.*/jdbc.password=$MYSQL_PASSWORD/" $CONF + +docker pull mysql:5.7 +docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7 diff --git a/hugegraph-dist/src/assembly/travis/install-postgresql-via-docker.sh b/hugegraph-dist/src/assembly/travis/install-postgresql-via-docker.sh new file mode 100755 index 0000000000..13879d2fd9 --- /dev/null +++ b/hugegraph-dist/src/assembly/travis/install-postgresql-via-docker.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -ev + +TRAVIS_DIR=`dirname $0` +CONF=hugegraph-test/src/main/resources/hugegraph.properties + +POSTGRESQL_DRIVER=org.postgresql.Driver +POSTGRESQL_URL=jdbc:postgresql://localhost:5432/ +POSTGRESQL_USERNAME=postgres +POSTGRESQL_PASSWORD=123456 + +# Set PostgreSQL configurations +sed -i "s/jdbc.driver=.*/jdbc.driver=$POSTGRESQL_DRIVER/" $CONF +sed -i "s?jdbc.url=.*?jdbc.url=$POSTGRESQL_URL?" $CONF +sed -i "s/jdbc.username=.*/jdbc.username=$POSTGRESQL_USERNAME/" $CONF +sed -i "s/jdbc.password=.*/jdbc.password=$POSTGRESQL_PASSWORD/" $CONF + +sudo service postgresql stop 9.2 + +docker pull postgres:9.6 +docker volume create pgdata +docker run --rm -v pgdata:/var/lib/postgresql/data -p 5432:5432 -e POSTGRES_PASSWORD=123456 -d postgres:9.6 diff --git a/hugegraph-dist/src/assembly/travis/run-api-test.sh b/hugegraph-dist/src/assembly/travis/run-api-test.sh index 87db73782e..0629307f91 100755 --- a/hugegraph-dist/src/assembly/travis/run-api-test.sh +++ b/hugegraph-dist/src/assembly/travis/run-api-test.sh @@ -2,6 +2,8 @@ set -ev +BACKEND=$1 + TRAVIS_DIR=`dirname $0` VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` SERVER_DIR=hugegraph-$VERSION @@ -26,9 +28,9 @@ authentication: { config: {tokens: conf/rest-server.properties} }" >> $GREMLIN_SERVER_CONF -$TRAVIS_DIR/start-server.sh $SERVER_DIR || (cat $SERVER_DIR/logs/hugegraph-server.log && exit 1) +$TRAVIS_DIR/start-server.sh $SERVER_DIR $BACKEND || (cat $SERVER_DIR/logs/hugegraph-server.log && exit 1) # run api-test mvn test -P api-test,$BACKEND || (cat $SERVER_DIR/logs/hugegraph-server.log && exit 1) -$TRAVIS_DIR/build-report.sh +$TRAVIS_DIR/build-report.sh $BACKEND $TRAVIS_DIR/stop-server.sh diff --git a/hugegraph-dist/src/assembly/travis/run-unit-test.sh b/hugegraph-dist/src/assembly/travis/run-unit-test.sh index 1ae3877b12..8991d986d6 100755 --- a/hugegraph-dist/src/assembly/travis/run-unit-test.sh +++ b/hugegraph-dist/src/assembly/travis/run-unit-test.sh @@ -2,6 +2,8 @@ set -ev +BACKEND=$1 + if [[ "$BACKEND" == "memory" ]]; then mvn test -P unit-test fi diff --git a/hugegraph-dist/src/assembly/travis/start-server.sh b/hugegraph-dist/src/assembly/travis/start-server.sh index ccda32728b..42537a62de 100755 --- a/hugegraph-dist/src/assembly/travis/start-server.sh +++ b/hugegraph-dist/src/assembly/travis/start-server.sh @@ -5,6 +5,7 @@ set -ev HOME_DIR=`pwd` TRAVIS_DIR=`dirname $0` BASE_DIR=$1 +BACKEND=$2 BIN=$BASE_DIR/bin CONF=$BASE_DIR/conf/hugegraph.properties REST_CONF=$BASE_DIR/conf/rest-server.properties