From 604c75941c5266d136d6808fc71c83b773ea8f94 Mon Sep 17 00:00:00 2001 From: "jiangqi.rrt" Date: Wed, 9 Apr 2025 10:27:09 +0800 Subject: [PATCH 1/5] add ci --- .github/release-drafter.yml | 47 +++++++++++++++++ .github/workflows/ci.yml | 90 ++++++++++++++++++++++++++++++++ examples/trace/benchmark_test.go | 2 +- 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..ddb8622 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,47 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '🧰 Maintenance' + labels: + - 'chore' + - 'documentation' +autolabeler: + - label: 'chore' + files: + - '*.md' + branch: + - '/docs{0,1}\/.+/' + - label: 'bug' + branch: + - '/fix\/.+/' + title: + - '/fix/i' + - label: 'enhancement' + branch: + - '/feature\/.+/' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch +template: | + ## Changes + + $CHANGES diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..508a072 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,90 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ '1.18', '1.19', '1.20', '1.21', '1.22' , '1.23'] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Install dependencies + run: go mod download + + go install mvdan.cc/gofumpt@v0.5.0 + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --out-format=colored-line-number + + - name: Run go build + run: | + go build ./... + + - name: Run gofumpt + run: | + if ! test -z "$(gofumpt -d -e . | tee /dev/stderr)"; then + echo "❗️ gofumpt check failed" + exit 1 + fi + + - name: Run tests with coverage + run: | + go test -race -coverprofile=coverage.out $(go list ./... | grep -v /examples/) + go tool cover -func=coverage.out + + - name: Check coverage threshold + run: | + COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}') + THRESHOLD=70 + if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then + echo "Code coverage $COVERAGE% is below threshold of $THRESHOLD%" + exit 1 + fi + echo "Code coverage $COVERAGE% is above threshold of $THRESHOLD%" + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + test_success: + # this aggregates success state of all jobs listed in `needs` + # this is the only required check to pass CI + name: "Test success" + if: always() + runs-on: ubuntu-latest + needs: [ test ] + steps: + - name: "Success" + if: needs.test.result == 'success' + run: true + shell: bash + - name: "Failure" + if: needs.test.result != 'success' + run: false + shell: bash + + draft: + runs-on: ubuntu-latest + needs: test_success + if: github.ref == 'refs/heads/main' + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/examples/trace/benchmark_test.go b/examples/trace/benchmark_test.go index 32e78b4..758e172 100644 --- a/examples/trace/benchmark_test.go +++ b/examples/trace/benchmark_test.go @@ -58,7 +58,7 @@ func BenchmarkMyFunctionWithQPS(b *testing.B) { // run benchmark test b.ResetTimer() - time.Sleep(1000 * time.Second) // wait + time.Sleep(1 * time.Second) // run duration close(done) } From e545fc3ed82e1ebc057e49d0ef249a1cceb66141 Mon Sep 17 00:00:00 2001 From: "jiangqi.rrt" Date: Wed, 9 Apr 2025 11:29:13 +0800 Subject: [PATCH 2/5] ut --- internal/util/validate_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/util/validate_test.go b/internal/util/validate_test.go index f53d0ea..831f90c 100644 --- a/internal/util/validate_test.go +++ b/internal/util/validate_test.go @@ -8,7 +8,7 @@ import "testing" func TestIsValidMDNBase64(t *testing.T) { testStr := "data:image/png;base64,SGVsbG8sIFdvcmxkIQ==" t.Run("TestIsValidMDNBase64", func(t *testing.T) { - if got := ParseValidMDNBase64(testStr); !got { + if _, got := ParseValidMDNBase64(testStr); !got { t.Errorf("ParseValidMDNBase64() = %v", got) } }) From 0f678a3bf8a8bbc1e46f62a8d615165c982c6b56 Mon Sep 17 00:00:00 2001 From: "jiangqi.rrt" Date: Wed, 9 Apr 2025 11:34:25 +0800 Subject: [PATCH 3/5] update ci --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 508a072..e6a1440 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,11 +27,11 @@ jobs: go install mvdan.cc/gofumpt@v0.5.0 - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: latest - args: --out-format=colored-line-number +# - name: Run golangci-lint +# uses: golangci/golangci-lint-action@v3 +# with: +# version: latest +# args: --out-format=colored-line-number - name: Run go build run: | From ccb3bb0d2a9c6391027e0cdfe58ab93132312a21 Mon Sep 17 00:00:00 2001 From: "jiangqi.rrt" Date: Wed, 9 Apr 2025 11:59:02 +0800 Subject: [PATCH 4/5] update ci --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6a1440..2dd3de1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,12 +37,12 @@ jobs: run: | go build ./... - - name: Run gofumpt - run: | - if ! test -z "$(gofumpt -d -e . | tee /dev/stderr)"; then - echo "❗️ gofumpt check failed" - exit 1 - fi +# - name: Run gofumpt +# run: | +# if ! test -z "$(gofumpt -d -e . | tee /dev/stderr)"; then +# echo "❗️ gofumpt check failed" +# exit 1 +# fi - name: Run tests with coverage run: | From d230dae7f75d21b1abdd63c7d73673ed24c7d05d Mon Sep 17 00:00:00 2001 From: "jiangqi.rrt" Date: Wed, 9 Apr 2025 16:05:03 +0800 Subject: [PATCH 5/5] fix ut --- internal/trace/trace_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/trace/trace_test.go b/internal/trace/trace_test.go index f3e0db9..7bf3e21 100644 --- a/internal/trace/trace_test.go +++ b/internal/trace/trace_test.go @@ -44,7 +44,7 @@ func Test_GetSpanFromHeader(t *testing.T) { opts := StartSpanOptions{ StartTime: time.Now(), ParentSpanID: "1433434", - TraceID: "1111111111111", + TraceID: "12345678901234567890123456789012", Baggage: map[string]string{"key": "value"}, } PatchConvey("Test FromHeader failed", t, func() { @@ -65,14 +65,13 @@ func Test_GetSpanFromHeader(t *testing.T) { PatchConvey("Test FromHeader success", t, func() { t := &Provider{} - expectedSpan := &Span{ - SpanContext: SpanContext{ - TraceID: "1234567890", - SpanID: "0987654321", - }, + expectedSpan := &SpanContext{ + TraceID: "1234567890", + SpanID: "0987654321", } + Mock(FromHeader).Return(expectedSpan).Build() - actual := t.GetSpanFromHeader(nil, nil) - So(actual, ShouldEqual, expectedSpan) + x := t.GetSpanFromHeader(nil, nil) + So(x, ShouldEqual, expectedSpan) }) }