Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Determine Version
run: |
VERSION=$(git describe --tags)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
Expand All @@ -31,7 +35,7 @@ jobs:
run: |
cd web
bun install
DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(git describe --tags) bun run build
DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$VERSION bun run build
cd ..
- name: Set up Go
uses: actions/setup-go@v3
Expand All @@ -40,13 +44,11 @@ jobs:
- name: Build Backend (amd64)
run: |
go mod download
VERSION=$(git describe --tags)
go build -ldflags "-s -w -X 'new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-$VERSION
- name: Build Backend (arm64)
run: |
sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y gcc-aarch64-linux-gnu
VERSION=$(git describe --tags)
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X 'new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-arm64-$VERSION
- name: Release
uses: softprops/action-gh-release@v2
Expand All @@ -65,6 +67,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Determine Version
run: |
VERSION=$(git describe --tags)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
Expand All @@ -75,7 +81,7 @@ jobs:
run: |
cd web
bun install
DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(git describe --tags) bun run build
DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$VERSION bun run build
cd ..
- name: Set up Go
uses: actions/setup-go@v3
Expand All @@ -84,7 +90,6 @@ jobs:
- name: Build Backend
run: |
go mod download
VERSION=$(git describe --tags)
go build -ldflags "-X 'new-api/common.Version=$VERSION'" -o new-api-macos-$VERSION
- name: Release
uses: softprops/action-gh-release@v2
Expand All @@ -105,6 +110,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Determine Version
run: |
VERSION=$(git describe --tags)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
Expand All @@ -114,7 +123,7 @@ jobs:
run: |
cd web
bun install
DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(git describe --tags) bun run build
DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$VERSION bun run build
cd ..
- name: Set up Go
uses: actions/setup-go@v3
Expand All @@ -123,7 +132,6 @@ jobs:
- name: Build Backend
run: |
go mod download
VERSION=$(git describe --tags)
go build -ldflags "-s -w -X 'new-api/common.Version=$VERSION'" -o new-api-$VERSION.exe
- name: Release
uses: softprops/action-gh-release@v2
Expand All @@ -132,5 +140,3 @@ jobs:
files: new-api-*.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


5 changes: 5 additions & 0 deletions common/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func printHelp() {
func InitEnv() {
flag.Parse()

envVersion := os.Getenv("VERSION")
if envVersion != "" {
Version = envVersion
}
Comment on lines +33 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Question: Is the runtime VERSION environment variable override necessary?

The workflow changes set the version at build time using go build -ldflags "-X 'new-api/common.Version=$VERSION'", which should embed the version string directly into the binary. This runtime environment variable check appears redundant if the ldflags approach is working correctly.

Consider:

  • If ldflags is working, this runtime override is unnecessary and could cause confusion (users might think they can override the version by setting a VERSION env var at runtime)
  • If ldflags isn't working, the root cause should be fixed rather than adding a runtime workaround
  • Mixing build-time and runtime version setting mechanisms adds complexity

Please verify:

  1. That the ldflags approach correctly embeds the version (check the module path new-api/common.Version matches your go.mod module declaration - see next comment)
  2. Whether this runtime override serves a specific purpose beyond the reported issue

🏁 Script executed:

#!/bin/bash
# Verify the module path in go.mod to ensure ldflags target is correct
cat go.mod | head -n 5

Length of output: 77


The runtime VERSION override is necessary because the workflow's ldflags command uses an incorrect module path.

The workflow sets the version using -X 'new-api/common.Version=$VERSION', but your go.mod declares the module as github.com/QuantumNous/new-api. The ldflags command must use the full module path, so it should be:

-X 'github.com/QuantumNous/new-api/common.Version=$VERSION'

Without this correction, the build-time flag substitution fails silently, and the version remains at the default "v0.0.0". The runtime environment variable override in common/init.go is a valid workaround—but the root cause should be fixed in your workflow configuration.

Fix the workflow first, then reassess whether the runtime override is still needed.

🤖 Prompt for AI Agents
In common/init.go around lines 33 to 36, the current code applies a runtime
VERSION override which masks an incorrect ldflags module path used at build
time; update your CI/workflow build step to set the -X ldflag to the full module
path (e.g. -X 'github.com/QuantumNous/new-api/common.Version=$VERSION') so Go's
linker can substitute the build-time Version variable correctly, then remove or
reevaluate the need for the environment-based override in common/init.go after
confirming the build-time substitution works.


if *PrintVersion {
fmt.Println(Version)
os.Exit(0)
Expand Down