From 773802807cbdc90912ca02ca2d7302b6159d9b74 Mon Sep 17 00:00:00 2001 From: Dov Benyomin Sohacheski Date: Wed, 1 Jul 2026 22:41:00 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Retire=20ws-cli's=20own=20versio?= =?UTF-8?q?n=20scheme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Report the go-module version via debug.ReadBuildInfo() instead of a hardcoded 0.0.x literal, and drop the auto-tag workflow. Workspace now consumes ws-cli by commit (git-refs), so the semver + tag ritual is dead weight — the pseudo-version the binary is installed at is the identity. --- .github/workflows/tag.yaml | 37 ------------------------------------- cmd/info/info.go | 6 +++--- cmd/info/version.go | 18 +++++++++++++++++- cmd/info/version_test.go | 36 ++++++++++++++++++++++++++++++++++++ cmd/root.go | 4 ++-- 5 files changed, 58 insertions(+), 43 deletions(-) delete mode 100644 .github/workflows/tag.yaml create mode 100644 cmd/info/version_test.go diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml deleted file mode 100644 index 13f5894..0000000 --- a/.github/workflows/tag.yaml +++ /dev/null @@ -1,37 +0,0 @@ ---- -name: 🔖 Publish New Tag - -on: - push: - branches: - - main - paths: - - cmd/info/version.go - -permissions: - contents: write - -jobs: - tag: - runs-on: ubuntu-latest - steps: - - name: 📥 Checkout repository - uses: actions/checkout@v6 - with: - token: ${{ secrets.KLOUD_BOT_ORG_PAT }} - - - name: 🔢 Extract version from version.go - id: extract_version - run: | - VERSION=$(grep -oP 'Version = "\K[^"]+' cmd/info/version.go) - echo "VERSION=$VERSION" >> "$GITHUB_ENV" - - - name: 🔖 Tag if new - run: | - if git ls-remote --exit-code --tags origin "refs/tags/v$VERSION" >/dev/null 2>&1; then - echo "Tag v$VERSION already exists on origin — skipping." - exit 0 - fi - - git tag "v$VERSION" - git push origin "v$VERSION" diff --git a/cmd/info/info.go b/cmd/info/info.go index 0f569a8..fe462bf 100644 --- a/cmd/info/info.go +++ b/cmd/info/info.go @@ -16,7 +16,7 @@ func showVersion(writer io.Writer) { styles.PrintWarning(writer, fmt.Sprintf("Could not read workspace version: %v", err)) fmt.Fprintf(writer, "%s\n", styles.Title().Render("Versions")) t := styles.Table().Rows( - []string{"ws-cli", Version}, + []string{"ws-cli", Version()}, ) fmt.Fprintln(writer, t.Render()) return @@ -26,7 +26,7 @@ func showVersion(writer io.Writer) { t := styles.Table().Rows( []string{"workspace", manifest.Version}, - []string{"ws-cli", Version}, + []string{"ws-cli", Version()}, []string{"VSCode", manifest.VSCode.Version}, ) @@ -47,7 +47,7 @@ var showVersionCmd = &cobra.Command{ if all, _ := cmd.Flags().GetBool("all"); all { showVersion(cmd.OutOrStdout()) } else { - fmt.Fprintln(cmd.OutOrStdout(), Version) + fmt.Fprintln(cmd.OutOrStdout(), Version()) } }, } diff --git a/cmd/info/version.go b/cmd/info/version.go index 99f3bf4..a57223d 100644 --- a/cmd/info/version.go +++ b/cmd/info/version.go @@ -1,3 +1,19 @@ package info -var Version = "0.0.69" +import "runtime/debug" + +func Version() string { + if build, ok := debug.ReadBuildInfo(); ok { + return resolveVersion(build.Main.Version) + } + + return resolveVersion("") +} + +func resolveVersion(v string) string { + if v == "" || v == "(devel)" { + return "(devel)" + } + + return v +} diff --git a/cmd/info/version_test.go b/cmd/info/version_test.go new file mode 100644 index 0000000..4b402ce --- /dev/null +++ b/cmd/info/version_test.go @@ -0,0 +1,36 @@ +package info + +import ( + "bytes" + "testing" + + "gotest.tools/v3/assert" +) + +func TestResolveVersion(t *testing.T) { + tests := []struct { + name string + in string + want string + }{ + {"empty", "", "(devel)"}, + {"devel", "(devel)", "(devel)"}, + {"semver", "v1.2.3", "v1.2.3"}, + {"pseudo", "v0.0.0-20260101000000-abcdef123456", "v0.0.0-20260101000000-abcdef123456"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, resolveVersion(tt.in), tt.want) + }) + } +} + +func TestShowVersionRendersResolvedVersionVerbatim(t *testing.T) { + buf := &bytes.Buffer{} + showVersionCmd.SetOut(buf) + + showVersionCmd.Run(showVersionCmd, []string{}) + + assert.Equal(t, buf.String(), Version()+"\n") +} diff --git a/cmd/root.go b/cmd/root.go index ee663af..f06c625 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -25,7 +25,7 @@ var rootCmd = &cobra.Command{ Use: "ws-cli", Short: "⚡ CLI companion to charge the workspace batteries", Long: "The workspace command-line companion. Groups helpers for inspecting the running workspace, managing settings and secrets, driving the editor, and serving local assets — most are called by the startup scripts, all are yours in the terminal.", - Version: "v" + info.Version, + Version: info.Version(), Aliases: []string{"ws"}, SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { @@ -42,7 +42,7 @@ func Execute() { fangOptions := []fang.Option{ fang.WithColorSchemeFunc(styles.FrappeColorScheme), - fang.WithVersion(info.Version), + fang.WithVersion(info.Version()), fang.WithoutManpage(), }