diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ba77d75..6f50b84 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,7 @@ jobs: if [ "$platform" = "darwin" ]; then platform="mac"; fi suffix="${platform}_${{ matrix.goarch }}${extension}" cd backend - BUILD_FLAGS="-s -w -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.Version=${{ env.VERSION }}' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GoVersion=$(go version)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GitHash=$(git show -s --format=%H)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)'" + BUILD_FLAGS="-s -w -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.Version=${{ env.VERSION }}' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GoVersion=$(go env GOVERSION)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GitHash=$(git show -s --format=%H)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)'" go build -tags bundled -trimpath -ldflags "$BUILD_FLAGS" -o ../out/backend/smail_$suffix ./cmd/smail go build -trimpath -ldflags "$BUILD_FLAGS" -o ../out/backend/smail-admin_$suffix ./cmd/smail-admin go build -trimpath -ldflags "$BUILD_FLAGS" -o ../out/backend/smail-config_$suffix ./cmd/smail-config diff --git a/Makefile b/Makefile index da08bb1..50cdfdf 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SMAIL_VERSION ?= $(shell git describe --tags --always --dirty) GIT_HASH ?= $(shell git show -s --format=%H) BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) -GO_VERSION ?= $(shell cd backend && go version) +GO_VERSION ?= $(shell cd backend && go env GOVERSION) BUILD_LDFLAGS = -s -w -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.Version=$(SMAIL_VERSION)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GitHash=$(GIT_HASH)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.BuildTime=$(BUILD_TIME)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GoVersion=$(GO_VERSION)' .PHONY: build clean clean_codex_test_artifacts build_fe build_server wechat_push spam_block telegram_push plugin package test test_mysql test_postgres diff --git a/deploy/build.ps1 b/deploy/build.ps1 index ec30c22..aa3f09d 100644 --- a/deploy/build.ps1 +++ b/deploy/build.ps1 @@ -51,7 +51,7 @@ try { $gitHash = (& git rev-parse HEAD).Trim() if ($LASTEXITCODE -ne 0) { throw '无法读取构建提交信息' } $buildTime = [DateTime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ssZ') - $goVersion = (& go version).Trim() + $goVersion = (& go env GOVERSION).Trim() $flags = "-s -w -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.Version=dev-$($fingerprint.Substring(0, 12))' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GitHash=$gitHash' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.BuildTime=$buildTime' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GoVersion=$goVersion'" & go build -tags bundled -trimpath -ldflags $flags -o (Join-Path $output 'smail.exe') ./cmd/smail if ($LASTEXITCODE -ne 0) { throw '开发后端构建失败' } diff --git a/test/frontend/output-paths.test.mjs b/test/frontend/output-paths.test.mjs index c0ad570..9f0ae9f 100644 --- a/test/frontend/output-paths.test.mjs +++ b/test/frontend/output-paths.test.mjs @@ -11,7 +11,7 @@ const read = relative => readFile(path.join(root, relative), 'utf8') test('跨平台构建输出不得越过项目 out 目录', async () => { const content = await read('Makefile') - assert.match(content, /GO_VERSION \?= \$\(shell cd backend && go version\)/) + assert.match(content, /GO_VERSION \?= \$\(shell cd backend && go env GOVERSION\)/) const commands = [...content.matchAll(/cd ([^\s]+) && [^\n]*go build [^\n]* -o ([^\s]+) /g)] assert.equal(commands.length, 18) for (const [, directory, output] of commands) {