| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| # |
| name: CI |
| |
| on: |
| push: |
| pull_request: |
| |
| # cancel in-progress runs for the same branch or PR |
| concurrency: |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| cancel-in-progress: true |
| |
| jobs: |
| license-check-and-import-format: |
| name: License Check and Import Format |
| runs-on: ubuntu-latest |
| steps: |
| - uses: actions/checkout@v5 |
| - name: Cache imports-formatter |
| id: cache-go-bin |
| uses: actions/cache@v4 |
| with: |
| path: ~/go/bin |
| key: ${{ runner.os }}-go-imports-formatter-${{ hashFiles('**/go.sum') }} |
| restore-keys: | |
| ${{ runner.os }}-go-imports-formatter- |
| |
| - name: Download imports-formatter if not cached |
| if: steps.cache-go-bin.outputs.cache-hit != 'true' |
| run: | |
| go install github.com/dubbogo/tools/cmd/imports-formatter@latest |
| |
| - name: Check License Header |
| uses: apache/skywalking-eyes/header@main # NOSONAR |
| |
| - name: Check Golang fmt |
| run: | |
| gofmt -s -w . |
| git diff --exit-code |
| |
| - name: Check Import Formatting |
| run: | |
| imports-formatter |
| git diff --exit-code |
| |
| golangci: |
| needs: license-check-and-import-format |
| name: Golang Lint |
| runs-on: ubuntu-latest |
| steps: |
| - uses: actions/checkout@v5 |
| - uses: actions/setup-go@v6 |
| with: |
| go-version-file: 'go.mod' |
| cache: true |
| - name: golangci-lint |
| uses: golangci/golangci-lint-action@v8 # NOSONAR |
| with: |
| version: v2.4.0 |
| |
| unit-test: |
| needs: golangci |
| name: Unit Test |
| runs-on: ubuntu-latest |
| steps: |
| - uses: actions/checkout@v5 |
| - uses: actions/setup-go@v6 |
| with: |
| go-version-file: 'go.mod' |
| cache: true |
| |
| - name: Cache Zookeeper JAR |
| id: cache-zk-jar |
| uses: actions/cache@v4 |
| with: |
| path: pkg/registry/zookeeper-4unittest/contrib/fatjar |
| key: ${{ runner.os }}-zookeeper-jar-3.4.9 |
| |
| - name: Download Zookeeper JAR if not cached |
| if: steps.cache-zk-jar.outputs.cache-hit != 'true' |
| run: | |
| echo "Cache miss. Downloading Zookeeper JAR..." |
| zkJarName="zookeeper-3.4.9-fatjar.jar" |
| remoteJarUrl="https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/${zkJarName}" |
| zkJarPath="pkg/registry/zookeeper-4unittest/contrib/fatjar" |
| mkdir -p ${zkJarPath} |
| wget -P "${zkJarPath}" ${remoteJarUrl} |
| |
| - name: Run Tests and Generate Coverage |
| run: | |
| go mod download |
| go test ./... -gcflags=-l -race -coverprofile=coverage.txt -covermode=atomic |
| |
| - name: Upload coverage to Codecov |
| uses: codecov/codecov-action@v4 # NOSONAR |
| with: |
| token: ${{ secrets.CODECOV_TOKEN }} |
| file: ./coverage.txt |
| flags: unittests |
| |
| integration-test: |
| needs: unit-test |
| name: Integration Test |
| runs-on: ubuntu-latest |
| outputs: |
| output1: ${{ steps.samples_head.outputs.sha }} |
| env: |
| SAMPLES_BRANCH: main |
| SAMPLES_REPO_URL: https://github.com/apache/dubbo-go-pixiu-samples.git |
| SAMPLES_CLONE_DIR: integrate_samples |
| steps: |
| - uses: actions/checkout@v5 |
| with: |
| persist-credentials: false |
| - uses: actions/setup-go@v6 |
| with: |
| go-version-file: 'go.mod' |
| cache: true |
| |
| - name: Resolve samples HEAD |
| id: samples_head |
| shell: bash |
| run: | |
| set -euo pipefail |
| head_sha="$(git ls-remote --heads "$SAMPLES_REPO_URL" "$SAMPLES_BRANCH" | awk '{print $1}')" |
| if [ -z "$head_sha" ]; then |
| echo "Failed to resolve HEAD of $SAMPLES_REPO_URL $SAMPLES_BRANCH" >&2 |
| exit 1 |
| fi |
| echo "sha=$head_sha" >> "$GITHUB_OUTPUT" |
| |
| - name: Cache dubbo-go-pixiu-samples |
| id: cache_samples |
| uses: actions/cache@v4 |
| with: |
| path: ${{ env.SAMPLES_CLONE_DIR }} |
| key: ${{ runner.os }}-samples-${{ steps.samples_head.outputs.sha }} |
| restore-keys: | |
| ${{ runner.os }}-samples- |
| |
| - name: Clone dubbo-go-pixiu-samples if not cached |
| if: steps.cache_samples.outputs.cache-hit != 'true' |
| shell: bash |
| run: | |
| if [ -d "$SAMPLES_CLONE_DIR" ]; then |
| rm -rf "$SAMPLES_CLONE_DIR" |
| fi |
| git clone --depth 1 -b "$SAMPLES_BRANCH" "$SAMPLES_REPO_URL" "$SAMPLES_CLONE_DIR" |
| |
| - name: Wire samples to local pixiu |
| working-directory: ${{ env.SAMPLES_CLONE_DIR }} |
| run: | |
| go mod edit -replace=github.com/apache/dubbo-go-pixiu=${{ github.workspace }} |
| go mod tidy |
| |
| - name: Run Integration Tests |
| run: | |
| chmod +x start_integrate_test.sh |
| ./start_integrate_test.sh |