From 527e92f812025f391abc20f0b390622c13bc94b6 Mon Sep 17 00:00:00 2001 From: Dezhi Wu Date: Thu, 24 Sep 2026 06:53:14 +0800 Subject: [PATCH] ci: Move the Go tests from Prow to GitHub Actions The Test workflow replaces the Prow jobs pull-appkit-go-test and post-appkit-go-test. It runs go test ./... for a pull request and for a push to master. Like the Prow jobs, it runs only when a Go file or go.mod changes. It also runs when go.sum or the workflow file changes. setup-go reads the Go version from go.mod, so the workflow does not need a change for a Go upgrade. TestLogError removed only the $GOPATH/src/ prefix from the stack traces. The test passed only in a checkout under $GOPATH/src/github.com/theplant/appkit, which is the Prow clone path. GitHub Actions checks out to a different directory, and a local checkout is usually not under GOPATH either. The test now removes the module directory, which it finds from its own source file path. GitHub Actions does not send the failures on master to team-dev in Slack, as the Prow reporter did. Jira: SRE-6511 --- .github/workflows/test.yaml | 35 +++++++++++++++++++++++++++++++++++ log/log_test.go | 12 ++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..69fa345 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,35 @@ +name: Test + +# Replaces the Prow jobs pull-appkit-go-test and post-appkit-go-test. +on: + pull_request: + paths: + - '**.go' + - 'go.mod' + - 'go.sum' + - '.github/workflows/test.yaml' + push: + branches: + - master + paths: + - '**.go' + - 'go.mod' + - 'go.sum' + - '.github/workflows/test.yaml' + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + + - run: go test ./... diff --git a/log/log_test.go b/log/log_test.go index b72ebe4..3a72c84 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -4,8 +4,9 @@ import ( "context" "errors" "fmt" - "go/build" "io" + "path/filepath" + "runtime" "strings" "testing" "time" @@ -77,8 +78,15 @@ func TestLogError(t *testing.T) { } } +// moduleRoot is the directory of the appkit module. The stack traces +// have absolute file paths, and the expected values do not. +var moduleRoot = func() string { + _, file, _, _ := runtime.Caller(0) + return filepath.Dir(filepath.Dir(file)) +}() + func cleanStacktrace(stacktrace string) (cleantrace string) { - cleantrace = strings.Replace(stacktrace, build.Default.GOPATH+"/src/", "", -1) + cleantrace = strings.Replace(stacktrace, moduleRoot+"/", "github.com/theplant/appkit/", -1) lines := strings.Split(cleantrace, "\n") if len(lines) >= 4 { lines = lines[0:5]