diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a7d1d770..17d2c31a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -130,7 +130,12 @@ jobs: test -s "$dir/main.go" cd "$dir" go mod init readme_quickstart - go get github.com/ajitpratap0/GoSQLX@latest + # Resolve the latest tagged release explicitly, then pin it in go.mod + # (module checksums are verified against sum.golang.org by go mod tidy). + tag="$(go list -m -f '{{.Version}}' github.com/ajitpratap0/GoSQLX@latest)" + echo "Latest tagged GoSQLX release: ${tag}" + go mod edit -require="github.com/ajitpratap0/GoSQLX@${tag}" + go mod tidy go build -o /dev/null . go run . diff --git a/.github/workflows/vscode-publish.yml b/.github/workflows/vscode-publish.yml index b6feef3f..f4c553bb 100644 --- a/.github/workflows/vscode-publish.yml +++ b/.github/workflows/vscode-publish.yml @@ -84,9 +84,17 @@ jobs: env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} + RELEASE_TAG: ${{ inputs.tag || github.ref_name }} run: | + VERSION="${RELEASE_TAG#v}" + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Tag '$RELEASE_TAG' does not produce a valid semver: '$VERSION'" + exit 1 + fi mkdir -p vscode-extension/bin - go build -ldflags="-s -w" -o "vscode-extension/bin/${{ matrix.binary }}" ./cmd/gosqlx + # Stamp the tag version so `gosqlx --version` matches the release. + go build -ldflags="-s -w -X github.com/ajitpratap0/GoSQLX/cmd/gosqlx/cmd.Version=${VERSION}" \ + -o "vscode-extension/bin/${{ matrix.binary }}" ./cmd/gosqlx - name: Generate binary checksum run: | @@ -94,9 +102,16 @@ jobs: - name: Smoke test binary if: matrix.target == 'linux-x64' + env: + RELEASE_TAG: ${{ inputs.tag || github.ref_name }} run: | chmod +x vscode-extension/bin/${{ matrix.binary }} - ./vscode-extension/bin/${{ matrix.binary }} --version + out="$(./vscode-extension/bin/${{ matrix.binary }} --version)" + echo "$out" + if [ "$out" != "gosqlx version ${RELEASE_TAG#v}" ]; then + echo "::error::bundled binary reports '$out', expected version ${RELEASE_TAG#v}" + exit 1 + fi - name: Setup Node uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 diff --git a/.goreleaser.yml b/.goreleaser.yml index be3b6c44..6d5a83ce 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -5,6 +5,11 @@ before: - go mod tidy - go test -race ./... +# The release archives ship the example tools only. Neither example defines a +# version variable, so a "-X main.version=..." ldflag would be a silent no-op +# and is intentionally omitted. The gosqlx CLI reports the tag version via +# -X github.com/ajitpratap0/GoSQLX/cmd/gosqlx/cmd.Version= +# (see .github/workflows/vscode-publish.yml, which builds the bundled binary). builds: - id: sql-validator main: ./examples/sql-validator @@ -19,7 +24,7 @@ builds: env: - CGO_ENABLED=0 ldflags: - - -s -w -X main.version={{.Version}} + - -s -w - id: sql-formatter main: ./examples/sql-formatter @@ -34,7 +39,7 @@ builds: env: - CGO_ENABLED=0 ldflags: - - -s -w -X main.version={{.Version}} + - -s -w archives: - id: gosqlx-tools diff --git a/cmd/gosqlx/cmd/root.go b/cmd/gosqlx/cmd/root.go index 33d317db..4161081b 100644 --- a/cmd/gosqlx/cmd/root.go +++ b/cmd/gosqlx/cmd/root.go @@ -175,6 +175,11 @@ func Execute() error { // Persistent flags are available to the command and all its children, // enabling consistent behavior across all subcommands. func init() { + // Report the Version variable from --version so release builds can set it + // with -ldflags "-X github.com/ajitpratap0/GoSQLX/cmd/gosqlx/cmd.Version=". + // A plain `go build` keeps the hard-coded default. + rootCmd.Version = Version + // Global flags available to all subcommands rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose output") rootCmd.PersistentFlags().StringVarP(&outputFile, "output", "o", "", "output file (default: stdout)") diff --git a/cmd/gosqlx/cmd/version_test.go b/cmd/gosqlx/cmd/version_test.go new file mode 100644 index 00000000..cb4b27f9 --- /dev/null +++ b/cmd/gosqlx/cmd/version_test.go @@ -0,0 +1,29 @@ +// Copyright 2026 GoSQLX Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import "testing" + +// TestRootCmdVersionUsesVersionVar guards the release ldflags contract: +// --version must print the Version variable, which release builds override +// with -X github.com/ajitpratap0/GoSQLX/cmd/gosqlx/cmd.Version=. +func TestRootCmdVersionUsesVersionVar(t *testing.T) { + if Version == "" { + t.Fatal("Version must have a non-empty default for dev builds") + } + if rootCmd.Version != Version { + t.Errorf("rootCmd.Version = %q, want Version %q", rootCmd.Version, Version) + } +} diff --git a/pkg/lsp/doc.go b/pkg/lsp/doc.go index 429441f8..cd47f3de 100644 --- a/pkg/lsp/doc.go +++ b/pkg/lsp/doc.go @@ -25,7 +25,8 @@ The GoSQLX LSP server transforms any LSP-compatible editor into a powerful SQL d environment. It leverages the GoSQLX SQL parser to provide accurate, real-time feedback on SQL syntax and offers intelligent code assistance through the Language Server Protocol. -Version: 1.0.0 (GoSQLX v1.6.0+) +The server reports the GoSQLX library version (gosqlx.Version) in serverInfo.version. +Available since GoSQLX v1.6.0. # Features diff --git a/pkg/lsp/handler.go b/pkg/lsp/handler.go index 6a9efea7..161dac43 100644 --- a/pkg/lsp/handler.go +++ b/pkg/lsp/handler.go @@ -253,7 +253,7 @@ func (h *Handler) handleInitialize(params json.RawMessage) (*InitializeResult, e }, ServerInfo: &ServerInfo{ Name: "gosqlx-lsp", - Version: "1.0.0", + Version: gosqlx.Version, }, }, nil } diff --git a/pkg/lsp/server_test.go b/pkg/lsp/server_test.go index 4436bfbc..4cc11ff5 100644 --- a/pkg/lsp/server_test.go +++ b/pkg/lsp/server_test.go @@ -25,6 +25,8 @@ import ( "sync" "testing" "time" + + "github.com/ajitpratap0/GoSQLX/pkg/gosqlx" ) // mockReadWriter provides a mock for testing the LSP server @@ -156,6 +158,10 @@ func TestHandler_Initialize(t *testing.T) { t.Errorf("expected server name 'gosqlx-lsp', got %q", initResult.ServerInfo.Name) } + if initResult.ServerInfo.Version != gosqlx.Version { + t.Errorf("expected server version %q (gosqlx.Version), got %q", gosqlx.Version, initResult.ServerInfo.Version) + } + if !initResult.Capabilities.HoverProvider { t.Error("expected hover provider to be enabled") }