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
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .

Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/vscode-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,34 @@ 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: |
sha256sum "vscode-extension/bin/${{ matrix.binary }}" | awk '{print $1}' > "vscode-extension/bin/${{ matrix.binary }}.sha256"

- 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
Expand Down
9 changes: 7 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=<version>
# (see .github/workflows/vscode-publish.yml, which builds the bundled binary).
builds:
- id: sql-validator
main: ./examples/sql-validator
Expand All @@ -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
Expand All @@ -34,7 +39,7 @@ builds:
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.version={{.Version}}
- -s -w

archives:
- id: gosqlx-tools
Expand Down
5 changes: 5 additions & 0 deletions cmd/gosqlx/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=<tag>".
// 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)")
Expand Down
29 changes: 29 additions & 0 deletions cmd/gosqlx/cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -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=<tag>.
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)
}
}
3 changes: 2 additions & 1 deletion pkg/lsp/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pkg/lsp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/lsp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"sync"
"testing"
"time"

"github.com/ajitpratap0/GoSQLX/pkg/gosqlx"
)

// mockReadWriter provides a mock for testing the LSP server
Expand Down Expand Up @@ -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")
}
Expand Down
Loading