Skip to content
Open
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
14 changes: 8 additions & 6 deletions cmd/itgray-helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import (
"github.com/spf13/cobra"
)

const (
// Version is overridden at build time via -ldflags "-X main.Version=...".
Version = "0.0.0-dev"
// PipeName is the canonical pipe path the user-side client connects to.
PipeName = `\\.\pipe\ITGRay.Helper.v1`
)
// Version is overridden at build time via -ldflags "-X main.Version=...".
// It must stay a var: the linker can only rewrite variables, so declaring it
// const compiles the placeholder in permanently and every build reports
// "0.0.0-dev" no matter what the build scripts pass.
var Version = "0.0.0-dev"

// PipeName is the canonical pipe path the user-side client connects to.
const PipeName = `\\.\pipe\ITGRay.Helper.v1`

// extraCommands holds platform-specific subcommands registered via init() in
// build-tagged files (e.g. install/uninstall on Linux). Empty on Windows.
Expand Down
41 changes: 41 additions & 0 deletions cmd/itgray-helper/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)

// Version carries the release tag into `itgray-helper --version`, and the
// build scripts set it with -ldflags "-X main.Version=...". That only works on
// a var: the linker cannot rewrite a constant, so declaring it const silently
// pinned every release to the placeholder.
func TestVersionIsOverridableByLdflags(t *testing.T) {
if _, err := exec.LookPath("go"); err != nil {
t.Skip("go toolchain not available")
}
// Windows needs the .exe suffix: with an explicit -o the toolchain writes
// exactly the name given, and exec then refuses to run an extension-less
// file.
name := "itgray-helper-test"
if runtime.GOOS == "windows" {
name += ".exe"
}
bin := filepath.Join(t.TempDir(), name)
const want = "v9.9.9-ldflags-probe"

build := exec.Command("go", "build", "-ldflags", "-X main.Version="+want, "-o", bin, ".")
if out, err := build.CombinedOutput(); err != nil {
t.Fatalf("go build: %v\n%s", err, out)
}

out, err := exec.Command(bin, "--version").CombinedOutput()
if err != nil {
t.Fatalf("run --version: %v\n%s", err, out)
}
if !strings.Contains(string(out), want) {
t.Fatalf("--version did not report the linker-supplied version.\ngot: %s\nwant it to contain: %s", out, want)
}
}
6 changes: 5 additions & 1 deletion scripts/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ ls -la "$OUT" | grep -vE '\.exe|\.dll' || true

# ----- Electron AppImage -----
echo ">> building itgray-bridge for Linux (Electron bundle)"
( cd "$ROOT/cmd/itgray-electron" && npm run build:bridge:linux )
# Pass VERSION through: without it build-bridge.mjs falls back to its own
# `git describe --dirty`, and a release build is dirty by construction — the
# workflow stamps package.json before building — so the bridge reported
# "<tag>+dirty" in the About panel.
( cd "$ROOT/cmd/itgray-electron" && APP_VERSION="$VERSION" npm run build:bridge:linux )

echo ">> building Electron bundle (main + preload + frontend)"
( cd "$ROOT/cmd/itgray-electron" && npm run build:main && npm run build:preload && npm run build:frontend )
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ ls -la "$OUT"

# ----- Electron NSIS installer -----
echo ">> cross-compiling itgray-bridge for Windows"
( cd "$ROOT/cmd/itgray-electron" && npm run build:bridge:win )
# Pass VERSION through — see the note in build-linux.sh: otherwise the bridge
# derives its own dirty describe string and ships "<tag>+dirty".
( cd "$ROOT/cmd/itgray-electron" && APP_VERSION="$VERSION" npm run build:bridge:win )

echo ">> building Electron bundle (main + preload + frontend)"
( cd "$ROOT/cmd/itgray-electron" && npm run build:main && npm run build:preload && npm run build:frontend )
Expand Down
Loading