Skip to content

fix: release workflow show version - #2278

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/release-version
Nov 23, 2025
Merged

fix: release workflow show version#2278
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/release-version

Conversation

@seefs001

@seefs001 seefs001 commented Nov 22, 2025

Copy link
Copy Markdown
Collaborator

fix #2242

Summary by CodeRabbit

  • Chores
    • Improved build and release infrastructure by centralizing version determination across all release workflows (Linux, macOS, Windows) for more consistent version handling during the release process.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Nov 22, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes centralize version determination in the CI/CD release workflow by adding a "Determine Version" step that computes version via git describe --tags and exports it as an environment variable. The Go initialization code is updated to read this VERSION environment variable and assign it before version printing logic, ensuring compiled binaries display the correct version number.

Changes

Cohort / File(s) Summary
GitHub Actions Release Workflow
\.github/workflows/release\.yml
Added centralized "Determine Version" step computing VERSION via git describe --tags and exporting to GITHUB_ENV; replaced inline git describe calls with $VERSION variable reference in frontend and backend build commands across Linux, macOS, and Windows job blocks
Go Initialization
common/init\.go
Modified InitEnv to read VERSION environment variable and assign it to the Version global before version flag output logic, enabling environment-based version override

Sequence Diagram

sequenceDiagram
    actor Release as Release Trigger
    participant GHA as GitHub Actions
    participant Build as Build Step
    participant Env as Environment
    participant Binary as Compiled Binary
    participant Init as InitEnv()

    Release->>GHA: Trigger release workflow
    GHA->>GHA: Determine Version (git describe --tags)
    GHA->>Env: Export VERSION to GITHUB_ENV
    GHA->>Build: Build with $VERSION available
    Build->>Build: Frontend/Backend build (reference $VERSION)
    Build->>Binary: Embed version info
    Binary->>Init: Binary execution
    Init->>Env: Read VERSION variable
    Env-->>Init: Return VERSION value
    Init->>Init: Assign to Version global
    Init-->>Binary: Version now available for display
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • .github/workflows/release.yml: Verify the "Determine Version" step is correctly positioned before build steps across all platforms (Linux, macOS, Windows) and that the $VERSION variable substitution is properly applied in all build commands
  • common/init.go: Confirm the VERSION environment variable read and assignment logic is placed correctly in InitEnv before version flag handling, and validate the logic for empty/non-empty cases

Poem

🐰 A version once hidden in the binary's heart,
Now flows from workflows, playing its part!
Environment variables dance and align,
The compiled binary displays with divine design,
No more v0.0.0—the real version will shine! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: release workflow show version' clearly describes the main change: fixing the release workflow to properly display the version number in compiled binaries.
Linked Issues check ✅ Passed The PR addresses issue #2242 by centralizing version extraction in the release workflow and ensuring the VERSION environment variable is used in the binary build and propagated to runtime display via common/init.go.
Out of Scope Changes check ✅ Passed All changes directly address the linked issue: workflow modifications ensure proper version injection, and init.go reads the VERSION environment variable to display the correct version at startup.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/release.yml (1)

47-47: Update ldflags to use the full module path on lines 47, 52, 93, and 135.

The go.mod declares module github.com/QuantumNous/new-api, but all four build commands use the shortened path -X 'new-api/common.Version=$VERSION'. In Go, the -X flag requires the exact full module path as declared in go.mod. When the path doesn't match, the flag silently fails and the version is not set in the binary.

Correct all four instances to:

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

This directly resolves the issue where the binary version was not being set at build time.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efb8f1f and f47d473.

📒 Files selected for processing (2)
  • .github/workflows/release.yml (6 hunks)
  • common/init.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
common/init.go (1)
common/constants.go (1)
  • Version (13-13)
🔇 Additional comments (2)
.github/workflows/release.yml (2)

25-28: LGTM! Centralized version determination is a good approach.

The "Determine Version" step correctly computes the version using git describe --tags and exports it to GITHUB_ENV, making it available for subsequent steps. This eliminates redundant version computation and ensures consistency between frontend and backend builds.

Also applies to: 70-73, 113-116


38-38: LGTM! Frontend version alignment is good.

The frontend builds now use the centralized $VERSION variable via VITE_REACT_APP_VERSION=$VERSION, ensuring consistent version display between frontend and backend.

Also applies to: 84-84, 126-126

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

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.

@Calcium-Ion
Calcium-Ion merged commit 3f19f18 into QuantumNous:main Nov 23, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Release工作流没有正确写入版本号导致直接运行二进制不显示版本

2 participants