Skip to content

Commit 47ef69f

Browse files
Merge branch 'main' into print-statistics
2 parents 60d2a1c + 2138fa7 commit 47ef69f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3556
-2775
lines changed

.github/copilot-instructions.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,57 @@ The project supports creating SQL Server instances using Docker or Podman:
155155
- Use the `internal/localizer` package for localized messages
156156
- Supported languages: Chinese (Simplified/Traditional), English, French, German, Italian, Japanese, Korean, Portuguese (Brazil), Russian, Spanish
157157

158+
### Adding Localizable Strings
159+
160+
When adding user-facing strings to the code, use the `localizer` package:
161+
162+
```go
163+
import "github.com/microsoft/go-sqlcmd/internal/localizer"
164+
165+
// Use localizer.Sprintf for formatted strings
166+
message := localizer.Sprintf("This is a localizable message with %s", value)
167+
168+
// Use localizer.Errorf for localized errors
169+
err := localizer.Errorf("Error: %s failed", operation)
170+
```
171+
172+
Constants that are not user-facing (like environment variable names, command names) should be placed in `internal/localizer/constants.go` and do not need localization.
173+
174+
### Generating Localization Files
175+
176+
After adding new localizable strings, you **must** regenerate the translation catalog files before committing. The build scripts handle this automatically.
177+
178+
#### On Windows
179+
180+
```cmd
181+
build\build.cmd
182+
```
183+
184+
This script:
185+
- Installs `gotext` if not already installed
186+
- Runs `go generate` which executes the gotext command defined in `internal/translations/translations.go`
187+
- Generates/updates the translation catalog in `internal/translations/catalog.go`
188+
- Reports any conflicting localizable strings that need to be fixed
189+
190+
#### On Linux/macOS
191+
192+
Run the following commands manually:
193+
194+
```bash
195+
# Install gotext if not already installed
196+
go install golang.org/x/text/cmd/gotext@latest
197+
198+
# Generate translation files
199+
go generate ./...
200+
```
201+
202+
### Important Notes
203+
204+
- Always run the build script after adding new user-facing strings
205+
- Check the build output for "conflicting localizable strings" warnings and resolve them
206+
- The `SQLCMD_LANG` environment variable controls the runtime language (e.g., `de-de`, `fr-fr`)
207+
- Test your changes with different language settings to ensure proper localization
208+
158209
## Azure Authentication
159210

160211
- Azure AD authentication is supported via the `azidentity` package

.github/dependabot.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT license.
3+
4+
# To get started with Dependabot version updates, you'll need to specify which
5+
# package ecosystems to update and where the package manifests are located.
6+
# Please see the documentation for all configuration options:
7+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
8+
9+
version: 2
10+
updates:
11+
# Enable version updates for Go modules
12+
- package-ecosystem: "gomod"
13+
directory: "/"
14+
schedule:
15+
interval: "weekly"
16+
day: "monday"
17+
open-pull-requests-limit: 10
18+
labels:
19+
- "dependencies"
20+
- "go"
21+
commit-message:
22+
prefix: "deps"
23+
include: "scope"
24+
25+
# Enable version updates for GitHub Actions
26+
- package-ecosystem: "github-actions"
27+
directory: "/"
28+
schedule:
29+
interval: "weekly"
30+
day: "monday"
31+
open-pull-requests-limit: 5
32+
labels:
33+
- "dependencies"
34+
- "github-actions"
35+
commit-message:
36+
prefix: "ci"

.github/workflows/golangci-lint.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ jobs:
99
name: lint-pr-changes
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/setup-go@v5
12+
# Pinned to commit SHA for supply chain security (CWE-829)
13+
# Verify: gh api repos/actions/setup-go/git/ref/tags/v6 --jq '.object.sha'
14+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
1315
with:
14-
go-version: stable
15-
- uses: actions/checkout@v4
16+
go-version: '1.24'
17+
- uses: actions/checkout@v6
1618
- name: golangci-lint
17-
uses: golangci/golangci-lint-action@v6
19+
# Pinned to commit SHA for supply chain security (CWE-829)
20+
# Verify: gh api repos/golangci/golangci-lint-action/git/ref/tags/v9 --jq '.object.sha'
21+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.0.0
1822
with:
1923
version: latest
2024
only-new-issues: true

.github/workflows/pr-validation.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v6
1313
- name: Setup go
14-
uses: actions/setup-go@v2
14+
uses: actions/setup-go@v6
1515
with:
16-
go-version: '1.22'
16+
go-version: '1.24'
1717
- name: Run tests against Linux SQL
1818
run: |
1919
go version
@@ -23,5 +23,20 @@ jobs:
2323
export SQLCMDPASSWORD=$(date +%s|sha256sum|base64|head -c 32)
2424
export SQLCMDUSER=sa
2525
docker run -m 2GB -e ACCEPT_EULA=1 -d --name sql2022 -p:1433:1433 -e SA_PASSWORD=$SQLCMDPASSWORD mcr.microsoft.com/mssql/server:2022-latest
26+
echo "Waiting for SQL Server to be ready..."
27+
READY=0
28+
for i in {1..60}; do
29+
if docker exec sql2022 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$SQLCMDPASSWORD" -C -Q "SELECT 1" &>/dev/null; then
30+
echo "SQL Server is ready!"
31+
READY=1
32+
break
33+
fi
34+
echo "Attempt $i: SQL Server not ready yet, waiting..."
35+
sleep 2
36+
done
37+
if [ $READY -eq 0 ]; then
38+
echo "ERROR: SQL Server failed to become ready within 2 minutes"
39+
exit 1
40+
fi
2641
cd ../..
2742
go test -v ./...

.github/workflows/security.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT license.
3+
4+
name: Security Scanning
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
branches:
12+
- main
13+
schedule:
14+
# Run weekly on Monday at 9:00 AM UTC
15+
- cron: '0 9 * * 1'
16+
workflow_dispatch:
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
govulncheck:
23+
name: Go Vulnerability Check
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v6
28+
29+
- name: Setup Go
30+
uses: actions/setup-go@v6
31+
with:
32+
go-version: '1.24.13'
33+
34+
- name: Install govulncheck
35+
run: go install golang.org/x/vuln/cmd/govulncheck@latest
36+
37+
- name: Run govulncheck
38+
run: govulncheck ./...

.pipelines/LocBuild.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ steps:
1919
packageSourceAuth: patAuth
2020
dependencyPackageSource: 'https://pkgs.dev.azure.com/msdata/_packaging/SQLDS_SSMS/nuget/v3/index.json'
2121
patVariable: $(System.AccessToken)
22-
22+
isAutoCompletePrSelected: false
23+
isShouldReusePrSelected: true
2324
- task: PublishPipelineArtifact@1
2425
inputs:
2526
targetPath: '$(Build.ArtifactStagingDirectory)'

.pipelines/include-install-go-tools.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
steps:
22
- task: GoTool@0
33
inputs:
4-
version: '1.22.10'
4+
version: '1.24.2'
55
- task: Go@0
66
displayName: 'Go: get dependencies'
77
inputs:

NOTICE.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ SOFTWARE.
587587
## github.com/docker/distribution
588588

589589
* Name: github.com/docker/distribution
590-
* Version: v2.8.2
591-
* License: [Apache-2.0](https://github.com/docker/distribution/blob/v2.8.2/LICENSE)
590+
* Version: v2.8.3
591+
* License: [Apache-2.0](https://github.com/docker/distribution/blob/v2.8.3/LICENSE)
592592

593593
```
594594
Apache License
@@ -5056,6 +5056,61 @@ SUBDIRECTORIES
50565056
50575057
```
50585058

5059+
## github.com/shopspring/decimal
5060+
5061+
* Name: github.com/shopspring/decimal
5062+
* Version: v1.4.0
5063+
* License: [MIT](https://github.com/shopspring/decimal/blob/v1.4.0/LICENSE)
5064+
5065+
```
5066+
The MIT License (MIT)
5067+
5068+
Copyright (c) 2015 Spring, Inc.
5069+
5070+
Permission is hereby granted, free of charge, to any person obtaining a copy
5071+
of this software and associated documentation files (the "Software"), to deal
5072+
in the Software without restriction, including without limitation the rights
5073+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5074+
copies of the Software, and to permit persons to whom the Software is
5075+
furnished to do so, subject to the following conditions:
5076+
5077+
The above copyright notice and this permission notice shall be included in
5078+
all copies or substantial portions of the Software.
5079+
5080+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5081+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5082+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5083+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5084+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5085+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
5086+
THE SOFTWARE.
5087+
5088+
- Based on https://github.com/oguzbilgic/fpd, which has the following license:
5089+
"""
5090+
The MIT License (MIT)
5091+
5092+
Copyright (c) 2013 Oguz Bilgic
5093+
5094+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5095+
this software and associated documentation files (the "Software"), to deal in
5096+
the Software without restriction, including without limitation the rights to
5097+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
5098+
the Software, and to permit persons to whom the Software is furnished to do so,
5099+
subject to the following conditions:
5100+
5101+
The above copyright notice and this permission notice shall be included in all
5102+
copies or substantial portions of the Software.
5103+
5104+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5105+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
5106+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
5107+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
5108+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
5109+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5110+
"""
5111+
5112+
```
5113+
50595114
## github.com/spf13/afero
50605115

50615116
* Name: github.com/spf13/afero

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ sqlcmd
112112

113113
If no current context exists, `sqlcmd` (with no connection parameters) reverts to the original ODBC `sqlcmd` behavior of creating an interactive session to the default local instance on port 1433 using trusted authentication, otherwise it will create an interactive session to the current context.
114114

115+
### Piping input to sqlcmd
116+
117+
You can pipe SQL commands directly to `sqlcmd` from the command line. This is useful for scripting and automation:
118+
119+
**PowerShell:**
120+
```powershell
121+
"SELECT @@version" | sqlcmd -S myserver -d mydb -G
122+
"SELECT name FROM sys.databases" | sqlcmd -S myserver.database.windows.net -d mydb -G
123+
```
124+
125+
**Bash:**
126+
```bash
127+
echo "SELECT @@version" | sqlcmd -S myserver -d mydb -G
128+
cat myscript.sql | sqlcmd -S myserver -d mydb -G
129+
```
130+
131+
Note: When piping input, `GO` batch terminators are optional—`sqlcmd` will automatically execute the batch when the input ends. However, you can still include `GO` statements if you want to execute multiple batches.
132+
115133
## Sqlcmd
116134

117135
The `sqlcmd` project aims to be a complete port of the original ODBC sqlcmd to the `Go` language, utilizing the [go-mssqldb][] driver. For full documentation of the tool and installation instructions, see [go-sqlcmd-utility][].

0 commit comments

Comments
 (0)