diff --git a/.github/actions/get-hugegraph-commit/action.yml b/.github/actions/get-hugegraph-commit/action.yml new file mode 100644 index 000000000..f6cf438d7 --- /dev/null +++ b/.github/actions/get-hugegraph-commit/action.yml @@ -0,0 +1,37 @@ +name: 'Get HugeGraph stable commit id' +description: 'Fetch the latest HugeGraph release commit SHA and expose it as output and env variable' + +outputs: + commit_id: + description: 'The commit SHA of the latest HugeGraph release' + value: ${{ steps.get-commit.outputs.commit_id }} + +runs: + using: composite + steps: + - name: Get HugeGraph stable commit id + id: get-commit + uses: actions/github-script@v7 + with: + script: | + const owner = 'apache'; + const repo = 'hugegraph'; + try { + const { data: release } = await github.rest.repos.getLatestRelease({ owner, repo }); + const tagName = release.tag_name; + const { data: ref } = await github.rest.git.getRef({ + owner, repo, ref: `tags/${tagName}` + }); + let sha = ref.object.sha; + if (ref.object.type === 'tag') { + const { data: tag } = await github.rest.git.getTag({ owner, repo, tag_sha: sha }); + sha = tag.object.sha; + } else if (ref.object.type !== 'commit') { + throw new Error(`Unexpected ref type: ${ref.object.type}`); + } + core.exportVariable('COMMIT_ID', sha); + core.setOutput('commit_id', sha); + console.log(`Using HugeGraph release ${tagName} (${sha})`); + } catch (error) { + core.setFailed(`Failed to get HugeGraph commit: ${error.message}`); + } diff --git a/.github/actions/setup-hugegraph-server/action.yml b/.github/actions/setup-hugegraph-server/action.yml new file mode 100644 index 000000000..ff142ed1a --- /dev/null +++ b/.github/actions/setup-hugegraph-server/action.yml @@ -0,0 +1,18 @@ +name: 'Setup HugeGraph Server' +description: 'Prepare environment and install HugeGraph server from source' + +inputs: + travis-dir: + description: 'Path to the Travis assembly directory containing install scripts' + required: true + commit-id: + description: 'HugeGraph commit SHA to install' + required: true + +runs: + using: composite + steps: + - name: Prepare env and service + shell: bash + run: | + ${{ inputs.travis-dir }}/install-hugegraph-from-source.sh ${{ inputs.commit-id }} diff --git a/.github/actions/setup-java-env/action.yml b/.github/actions/setup-java-env/action.yml new file mode 100644 index 000000000..18b136123 --- /dev/null +++ b/.github/actions/setup-java-env/action.yml @@ -0,0 +1,33 @@ +name: 'Setup Java and Maven Environment' +description: 'Install JDK, cache Maven packages, and optionally apply staged Maven repository settings' + +inputs: + java-version: + description: 'Java version to install' + required: false + default: '11' + distribution: + description: 'JDK distribution' + required: false + default: 'zulu' + use-stage: + description: 'Whether to apply staged Maven repository settings' + required: false + default: 'true' + +runs: + using: composite + steps: + - name: Install JDK ${{ inputs.java-version }} + uses: actions/setup-java@v4 + with: + java-version: ${{ inputs.java-version }} + distribution: ${{ inputs.distribution }} + cache: 'maven' + + - name: Use staged maven repo settings + if: ${{ inputs.use-stage == 'true' }} + shell: bash + run: | + cp $HOME/.m2/settings.xml /tmp/settings.xml + mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml diff --git a/.github/actions/upload-coverage/action.yml b/.github/actions/upload-coverage/action.yml new file mode 100644 index 000000000..7b07b84f2 --- /dev/null +++ b/.github/actions/upload-coverage/action.yml @@ -0,0 +1,20 @@ +name: 'Upload Coverage to Codecov' +description: 'Upload test coverage report to Codecov' + +inputs: + token: + description: 'Codecov upload token' + required: true + file: + description: 'Path to the coverage report file' + required: false + default: 'target/jacoco.xml' + +runs: + using: composite + steps: + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ inputs.token }} + file: ${{ inputs.file }} diff --git a/.github/workflows/client-ci.yml b/.github/workflows/client-ci.yml index 0551d6ad5..9ed4e723f 100644 --- a/.github/workflows/client-ci.yml +++ b/.github/workflows/client-ci.yml @@ -24,9 +24,6 @@ jobs: env: USE_STAGE: 'true' # Whether to include the stage repository. TRAVIS_DIR: hugegraph-client/assembly/travis - # TODO: replace it with the (latest - n) commit id (n >= 15) - # hugegraph commit date: 2025-11-4 - COMMIT_ID: b7998c1 strategy: fail-fast: false matrix: @@ -39,39 +36,22 @@ jobs: with: fetch-depth: 2 - # TODO: do we need it? (need test) - - name: Cache Maven packages - uses: actions/cache@v4 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven- - - - name: Install JDK 11 for graph server - uses: actions/setup-java@v4 - with: - java-version: '11' - distribution: 'zulu' - cache: 'maven' + - name: Get HugeGraph stable commit id + id: get-commit + uses: ./.github/actions/get-hugegraph-commit - - name: Prepare env and service - run: | - # TODO(@Thespica): test both servers of supporting gs and not supporting gs - # when the server supports gs - $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID - - - name: Install Java ${{ matrix.JAVA_VERSION }} for client - uses: actions/setup-java@v4 + - name: Setup Java environment + uses: ./.github/actions/setup-java-env with: java-version: ${{ matrix.JAVA_VERSION }} distribution: 'zulu' - cache: 'maven' + use-stage: ${{ env.USE_STAGE }} - - name: Use staged maven repo - if: ${{ env.USE_STAGE == 'true' }} - run: | - cp $HOME/.m2/settings.xml /tmp/settings.xml - mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml + - name: Setup HugeGraph server + uses: ./.github/actions/setup-hugegraph-server + with: + travis-dir: ${{ env.TRAVIS_DIR }} + commit-id: ${{ steps.get-commit.outputs.commit_id }} - name: Compile run: | @@ -85,7 +65,7 @@ jobs: mvn test -Dtest=FuncTestSuite - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: ./.github/actions/upload-coverage with: token: ${{ secrets.CODECOV_TOKEN }} file: target/jacoco.xml diff --git a/.github/workflows/client-go-ci.yml b/.github/workflows/client-go-ci.yml index 45064073d..9c14711e9 100644 --- a/.github/workflows/client-go-ci.yml +++ b/.github/workflows/client-go-ci.yml @@ -23,9 +23,6 @@ jobs: env: USE_STAGE: 'true' # Whether to include the stage repository. TRAVIS_DIR: hugegraph-client/assembly/travis - # TODO: replace it with the (latest - n) commit id (n >= 15) - # FIXME: hugegraph commit date: 2025-10-30 - COMMIT_ID: 8c1ee71 # 5b3d295 strategy: fail-fast: false matrix: @@ -37,36 +34,31 @@ jobs: with: fetch-depth: 2 - - name: Install JDK 11 - uses: actions/setup-java@v3 + - name: Get HugeGraph stable commit id + id: get-commit + uses: ./.github/actions/get-hugegraph-commit + + - name: Setup Java environment + uses: ./.github/actions/setup-java-env with: java-version: ${{ matrix.JAVA_VERSION }} distribution: 'zulu' + use-stage: ${{ env.USE_STAGE }} - - name: Cache Maven packages - uses: actions/cache@v3 + - name: Setup HugeGraph server + uses: ./.github/actions/setup-hugegraph-server with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: Use staged maven repo - if: ${{ env.USE_STAGE == 'true' }} - run: | - cp $HOME/.m2/settings.xml /tmp/settings.xml - mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml - - - name: Prepare env and service - run: | - $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID + travis-dir: ${{ env.TRAVIS_DIR }} + commit-id: ${{ steps.get-commit.outputs.commit_id }} - name: Init Go env - uses: actions/setup-go@v2.1.3 - with: {go-version: '1.x'} + uses: actions/setup-go@v5 + with: + go-version: '1.x' - name: Go test run: | - go version + go version sudo swapoff -a sudo sysctl -w vm.swappiness=1 sudo sysctl -w fs.file-max=262144 diff --git a/.github/workflows/hubble-ci.yml b/.github/workflows/hubble-ci.yml index 4cd3f7780..2b09e74ff 100644 --- a/.github/workflows/hubble-ci.yml +++ b/.github/workflows/hubble-ci.yml @@ -23,9 +23,6 @@ on: env: TRAVIS_DIR: hugegraph-hubble/hubble-dist/assembly/travis - # TODO: replace it with the (latest - n) commit id (n >= 15) - # FIXME: hugegraph commit date: 2025-10-30 - COMMIT_ID: 8c1ee71 # 5b3d295 jobs: hubble-ci: @@ -44,11 +41,16 @@ jobs: with: fetch-depth: 2 - - name: Install JDK 11 - uses: actions/setup-java@v3 + - name: Get HugeGraph stable commit id + id: get-commit + uses: ./.github/actions/get-hugegraph-commit + + - name: Setup Java environment + uses: ./.github/actions/setup-java-env with: java-version: ${{ matrix.JAVA_VERSION }} distribution: 'adopt' + use-stage: ${{ env.USE_STAGE }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -56,21 +58,6 @@ jobs: python-version: ${{ matrix.python-version }} cache: 'pip' - # we also should cache python & yarn & downloads to avoid useless work - - name: Cache Maven packages - uses: actions/cache@v3 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: use staged maven repo settings - if: ${{ env.USE_STAGE == 'true' }} - run: | - cp $HOME/.m2/settings.xml /tmp/settings.xml - mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml - - name: Compile run: | mvn install -pl hugegraph-client,hugegraph-loader -am -Dmaven.javadoc.skip=true -DskipTests -ntp @@ -78,8 +65,9 @@ jobs: mvn -e compile -Dmaven.javadoc.skip=true -ntp - name: Prepare env and service + env: + COMMIT_ID: ${{ steps.get-commit.outputs.commit_id }} run: | - python -m pip install -r ${TRAVIS_DIR}/requirements.txt cd hugegraph-hubble mvn package -Dmaven.test.skip=true @@ -102,7 +90,7 @@ jobs: hubble-dist/assembly/travis/run-api-test.sh - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: ./.github/actions/upload-coverage with: token: ${{ secrets.CODECOV_TOKEN }} file: target/site/jacoco/*.xml diff --git a/.github/workflows/loader-ci.yml b/.github/workflows/loader-ci.yml index d992117b4..a7b085ab3 100644 --- a/.github/workflows/loader-ci.yml +++ b/.github/workflows/loader-ci.yml @@ -26,9 +26,6 @@ jobs: USE_STAGE: 'true' # Whether to include the stage repository. TRAVIS_DIR: hugegraph-loader/assembly/travis STATIC_DIR: hugegraph-loader/assembly/static - # TODO: replace it with the (latest - n) commit id (n >= 15) - # hugegraph commit date: 2025-10-30 - COMMIT_ID: 5b3d295 DB_USER: root DB_PASS: root DB_DATABASE: load_test @@ -50,18 +47,16 @@ jobs: with: fetch-depth: 2 - - name: Install JDK 11 - uses: actions/setup-java@v4 + - name: Get HugeGraph stable commit id + id: get-commit + uses: ./.github/actions/get-hugegraph-commit + + - name: Setup Java environment + uses: ./.github/actions/setup-java-env with: java-version: ${{ matrix.JAVA_VERSION }} distribution: 'adopt' - - - name: Cache Maven packages - uses: actions/cache@v4 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 + use-stage: ${{ env.USE_STAGE }} - name: Cache Hadoop uses: actions/cache@v4 @@ -72,20 +67,16 @@ jobs: - name: Cache HugeGraph Server uses: actions/cache@v4 with: - path: ~/hugegraph-cache-${{ env.COMMIT_ID }} - key: ${{ runner.os }}-hugegraph-server-${{ env.COMMIT_ID }} - - - name: use staged maven repo settings - if: ${{ env.USE_STAGE == 'true' }} - run: | - cp $HOME/.m2/settings.xml /tmp/settings.xml - mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml + path: ~/hugegraph-cache-${{ steps.get-commit.outputs.commit_id }} + key: ${{ runner.os }}-hugegraph-server-${{ steps.get-commit.outputs.commit_id }} - name: Compile run: | mvn install -pl hugegraph-client,hugegraph-loader -am -Dmaven.javadoc.skip=true -DskipTests -ntp - name: Prepare env and service + env: + COMMIT_ID: ${{ steps.get-commit.outputs.commit_id }} run: | $TRAVIS_DIR/install-hadoop.sh $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID @@ -100,7 +91,7 @@ jobs: mvn test -P kafka - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + uses: ./.github/actions/upload-coverage with: token: ${{ secrets.CODECOV_TOKEN }} file: target/jacoco.xml diff --git a/.github/workflows/spark-connector-ci.yml b/.github/workflows/spark-connector-ci.yml index 4c077e9e3..b61b56e2f 100644 --- a/.github/workflows/spark-connector-ci.yml +++ b/.github/workflows/spark-connector-ci.yml @@ -25,8 +25,6 @@ jobs: env: USE_STAGE: 'true' # Whether to include the stage repository. TRAVIS_DIR: hugegraph-spark-connector/assembly/travis - # hugegraph commit date: 2025-10-30 - COMMIT_ID: 5b3d295 strategy: matrix: JAVA_VERSION: [ '11' ] @@ -37,32 +35,26 @@ jobs: with: fetch-depth: 2 - - name: Install JDK 11 - uses: actions/setup-java@v4 - with: - java-version: '11' - distribution: 'adopt' + - name: Get HugeGraph stable commit id + id: get-commit + uses: ./.github/actions/get-hugegraph-commit - - name: Cache Maven packages - uses: actions/cache@v3 + - name: Setup Java environment + uses: ./.github/actions/setup-java-env with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: use staged maven repo settings - if: ${{ env.USE_STAGE == 'true' }} - run: | - cp $HOME/.m2/settings.xml /tmp/settings.xml - mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml + java-version: ${{ matrix.JAVA_VERSION }} + distribution: 'adopt' + use-stage: ${{ env.USE_STAGE }} - name: Compile run: | mvn install -pl hugegraph-client,hugegraph-spark-connector -am -Dmaven.javadoc.skip=true -DskipTests -ntp - - name: Prepare env and service - run: | - $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID + - name: Setup HugeGraph server + uses: ./.github/actions/setup-hugegraph-server + with: + travis-dir: ${{ env.TRAVIS_DIR }} + commit-id: ${{ steps.get-commit.outputs.commit_id }} - name: Run test run: | diff --git a/.github/workflows/tools-ci.yml b/.github/workflows/tools-ci.yml index 2ee9143cd..dda37f3e3 100644 --- a/.github/workflows/tools-ci.yml +++ b/.github/workflows/tools-ci.yml @@ -1,4 +1,5 @@ name: "tools-ci" + on: workflow_dispatch: push: @@ -24,10 +25,6 @@ jobs: env: USE_STAGE: 'true' # Whether to include the stage repository. TRAVIS_DIR: hugegraph-tools/assembly/travis - # TODO: could we use one param to unify it? or use a action template (could use one ci file) - # TODO: replace it with the (latest - n) commit id (n >= 15) - # hugegraph commit date: 2025-11-4 - COMMIT_ID: b7998c1 strategy: matrix: JAVA_VERSION: [ '11' ] @@ -38,38 +35,33 @@ jobs: with: fetch-depth: 2 - - name: Install JDK 11 - uses: actions/setup-java@v3 + - name: Get HugeGraph stable commit id + id: get-commit + uses: ./.github/actions/get-hugegraph-commit + + - name: Setup Java environment + uses: ./.github/actions/setup-java-env with: java-version: ${{ matrix.JAVA_VERSION }} distribution: 'adopt' - - name: Cache Maven packages - uses: actions/cache@v3 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: use staged maven repo settings - if: ${{ env.USE_STAGE == 'true' }} - run: | - cp $HOME/.m2/settings.xml /tmp/settings.xml - mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml + use-stage: ${{ env.USE_STAGE }} - name: Compile run: | mvn install -pl hugegraph-client,hugegraph-tools -am -Dmaven.javadoc.skip=true -DskipTests -ntp - - name: Prepare env and service - run: | - $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID + - name: Setup HugeGraph server + uses: ./.github/actions/setup-hugegraph-server + with: + travis-dir: ${{ env.TRAVIS_DIR }} + commit-id: ${{ steps.get-commit.outputs.commit_id }} - name: Run test run: | mvn test -Dtest=FuncTestSuite -pl hugegraph-tools -ntp - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: ./.github/actions/upload-coverage with: token: ${{ secrets.CODECOV_TOKEN }} file: target/jacoco.xml diff --git a/hugegraph-client-go/api/v1/gremlin/gemlin.go b/hugegraph-client-go/api/v1/gremlin/gemlin.go index a2c3112bf..c6ddd04e2 100644 --- a/hugegraph-client-go/api/v1/gremlin/gemlin.go +++ b/hugegraph-client-go/api/v1/gremlin/gemlin.go @@ -83,19 +83,13 @@ type PostRequest struct { gremlin string bindings map[string]string language string - aliases struct { - //Graph string `json:"graph"` - //G string `json:"g"` - } + aliases map[string]string } type PostRequestData struct { Gremlin string `json:"gremlin"` Bindings map[string]string `json:"bindings,omitempty"` Language string `json:"language,omitempty"` - Aliases struct { - //Graph string `json:"graph"` - //G string `json:"g"` - } `json:"aliases,omitempty"` + Aliases map[string]string `json:"aliases,omitempty"` } type PostResponse struct { StatusCode int `json:"-"` @@ -132,6 +126,22 @@ func (g Post) WithGremlin(gremlin string) func(request *PostRequest) { } } +func buildDefaultAliases(transport api.Transport) map[string]string { + cfg := transport.GetConfig() + graphSpace := cfg.GraphSpace + if graphSpace == "" { + graphSpace = "DEFAULT" + } + if cfg.Graph == "" { + cfg.Graph = "hugegraph" + } + full := graphSpace + "-" + cfg.Graph + return map[string]string{ + "graph": full, + "g": "__g_" + full, + } +} + func (g GetRequest) Do(ctx context.Context, transport api.Transport) (*GetResponse, error) { url := "/gremlin" @@ -195,6 +205,10 @@ func (g PostRequest) Do(ctx context.Context, transport api.Transport) (*PostResp g.language = "gremlin-groovy" } + if g.aliases == nil { + g.aliases = buildDefaultAliases(transport) + } + gd := &PostRequestData{ Gremlin: g.gremlin, Bindings: g.bindings, diff --git a/hugegraph-client-go/api/v1/gremlin/gemlin_test.go b/hugegraph-client-go/api/v1/gremlin/gemlin_test.go index d880c8878..5ab2d8ab6 100644 --- a/hugegraph-client-go/api/v1/gremlin/gemlin_test.go +++ b/hugegraph-client-go/api/v1/gremlin/gemlin_test.go @@ -31,22 +31,17 @@ func TestGremlin(t *testing.T) { if err != nil { log.Println(err) } - respGet, err := client.Gremlin.Get( - client.Gremlin.Get.WithGremlin("hugegraph.traversal().V().limit(3)"), - ) - if err != nil { - log.Fatalln(err) - } - if respGet.StatusCode != 200 { - t.Error("client.Gremlin.GremlinGet error ") - } respPost, err := client.Gremlin.Post( - client.Gremlin.Post.WithGremlin("hugegraph.traversal().V().limit(3)"), + client.Gremlin.Post.WithGremlin("g.V().limit(3)"), ) if err != nil { log.Fatalln(err) } + if respPost.StatusCode != 200 { + t.Errorf("client.Gremlin.Post http_status=%d, gremlin_status=%d, message=%s", + respPost.StatusCode, respPost.Data.Status.Code, respPost.Data.Status.Message) + } fmt.Println(respPost.Data.Result.Data) } diff --git a/hugegraph-client-go/hugegraph.go b/hugegraph-client-go/hugegraph.go index 5e5a5f305..a1797842c 100644 --- a/hugegraph-client-go/hugegraph.go +++ b/hugegraph-client-go/hugegraph.go @@ -92,11 +92,12 @@ func NewCommonClient(cfg Config) (*CommonClient, error) { Host: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port), Scheme: "http", }, - Username: cfg.Username, - Password: cfg.Password, - Graph: cfg.Graph, - Transport: cfg.Transport, - Logger: cfg.Logger, + Username: cfg.Username, + Password: cfg.Password, + GraphSpace: cfg.GraphSpace, + Graph: cfg.Graph, + Transport: cfg.Transport, + Logger: cfg.Logger, }) return &CommonClient{