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
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ These environment variables can be set to configure some aspects of AAD auth and

#### sqlcmd executable

Build [sqlcmd](cmd/sqlcmd)
Build [sqlcmd](cmd/modern)

```sh

go build ./cmd/sqlcmd

./build/build.sh
```
or
```
.\build\build.cmd
```

#### sqlcmd package
Expand All @@ -109,7 +111,7 @@ The version on the binary will match the version tag of the branch.
```sh

go install github.com/tc-hib/go-winres@latest
cd cmd/sqlcmd
cd cmd/modern
go generate

```
Expand Down
12 changes: 7 additions & 5 deletions build/azure-pipelines/build-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ parameters:
- name: VersionTag
type: string
default: $(Build.BuildNumber)
- name: BinaryName
type: string

steps:
- task: GoTool@0
Expand All @@ -23,22 +25,22 @@ steps:
command: 'custom'
customCommand: 'install'
arguments: 'github.com/tc-hib/go-winres@latest'
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'
env:
GOBIN: $(Build.SourcesDirectory)

- task: CmdLine@2
displayName: 'generate version resource'
inputs:
script: $(Build.SourcesDirectory)/go-winres make --file-version git-tag --product-version git-tag
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'

- task: Go@0
displayName: 'Go: get dependencies'
inputs:
command: 'get'
arguments: '-d'
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'
env:
GOOS: ${{ parameters.OS }}
GOARCH: ${{ parameters.Arch }}
Expand All @@ -48,8 +50,8 @@ steps:
displayName: 'Go: build sqlcmd'
inputs:
command: 'build'
arguments: '-o $(Build.BinariesDirectory) -ldflags="-X main.version=${{ parameters.VersionTag }}"'
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
arguments: '-o $(Build.BinariesDirectory)/${{ parameters.BinaryName }} -ldflags="-X main.version=${{ parameters.VersionTag }}"'
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'
env:
GOOS: ${{ parameters.OS }}
GOARCH: ${{ parameters.Arch }}
Expand Down
11 changes: 11 additions & 0 deletions build/azure-pipelines/build-product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,37 @@ stages:
artifact: LinuxAmd64
os:
arch:
binaryName: 'sqlcmd'
mac:
imageName: 'macOS-latest'
artifact: DarwinAmd64
os:
arch:
binaryName: 'sqlcmd'
windows:
imageName: 'windows-latest'
artifact: WindowsAmd64
os:
arch:
binaryName: 'sqlcmd.exe'
linuxArm:
imageName: 'ubuntu-latest'
artifact: LinuxArm64
os:
arch: arm64
binaryName: 'sqlcmd'
windowsArm:
imageName: 'windows-latest'
artifact: WindowsArm
os:
arch: arm
binaryName: 'sqlcmd.exe'
linuxs390x:
imageName: 'ubuntu-latest'
artifact: LinuxS390x
os:
arch: s390x
binaryName: 'sqlcmd'
pool:
vmImage: $(imageName)
steps:
Expand All @@ -60,6 +66,7 @@ stages:
Arch: $(arch)
ArtifactName: $(artifact)
VersionTag: $(getVersion.VERSION_TAG)
BinaryName: $(binaryName)

- stage: CreatePackages
displayName: Create packages to publish
Expand All @@ -73,6 +80,10 @@ stages:
inputs:
buildType: 'current'
targetPath: '$(Pipeline.Workspace)'
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '2.1.x'
- task: EsrpCodeSigning@1
displayName: Sign Windows binary
inputs:
Expand Down
5 changes: 5 additions & 0 deletions build/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
REM Get Version Tag
for /f %%i in ('"git describe --tags --abbrev=0"') do set sqlcmdVersion=%%i

REM Generates sqlcmd.exe in the root dir of the repo
go build -o %~dp0..\sqlcmd.exe -ldflags="-X main.version=%sqlcmdVersion%" %~dp0..\cmd\modern
4 changes: 4 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
scriptdir=`dirname $0`
versionTag=`git describe --tags --abbrev=0`
go build -o $scriptdir/../sqlcmd -ldflags="-X main.version=$versionTag" $scriptdir/../cmd/modern
1 change: 0 additions & 1 deletion cmd/modern/build.cmd

This file was deleted.

1 change: 0 additions & 1 deletion cmd/modern/build.sh

This file was deleted.

6 changes: 5 additions & 1 deletion cmd/modern/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// command-line interface (CLI) should be used based on if the first argument provided
// by the user is a valid sub-command for the new CLI, if so it executes the
// new cobra CLI; otherwise, it falls back to the old kong-based CLI.

//go:generate go-winres make --file-version=git-tag --product-version=git-tag

package main

import (
Expand All @@ -25,6 +28,7 @@ import (

var rootCmd *Root
var outputter *output.Output
var version = "local-build" // overridden in pipeline builds with: -ldflags="-X main.version=$(VersionTag)"

// main is the entry point for the sqlcmd command line interface.
// It parses command line options and initializes the command parser.
Expand All @@ -42,7 +46,7 @@ func main() {
cmdparser.Initialize(initializeCallback)
rootCmd.Execute()
} else {
legacyCmd.Execute()
legacyCmd.Execute(version)
}
}

Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions cmd/sqlcmd/sqlcmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
//go:generate go-winres make --file-version=git-tag --product-version=git-tag

package sqlcmd

import (
Expand All @@ -15,8 +15,6 @@ import (
"github.com/microsoft/go-sqlcmd/pkg/sqlcmd"
)

var version = "Local-build" // overridden in pipeline builds with: -ldflags="-X main.version=$(VersionTag)"

// SQLCmdArguments defines the command line arguments for sqlcmd
// The exhaustive list is at https://docs.microsoft.com/sql/tools/sqlcmd-utility?view=sql-server-ver15
type SQLCmdArguments struct {
Expand Down Expand Up @@ -118,7 +116,7 @@ func (a SQLCmdArguments) authenticationMethod(hasPassword bool) string {
return a.AuthenticationMethod
}

func Execute() {
func Execute(version string) {
ctx := kong.Parse(&args, kong.NoDefaultHelp())
if args.Version {
ctx.Printf("%v", version)
Expand Down