Skip to content

Commit 3f7c4ad

Browse files
Build cmd/modern dir as per current dir structure (#186)
This commit addresses #185 and updates the pipeline yamls as per the new directory structure for sqlcmd. Additionally, winres files have also been moved appropriately and modified build scripts so that they can be executed from anywhere and has version info.
1 parent 1d4adeb commit 3f7c4ad

File tree

10 files changed

+41
-17
lines changed

10 files changed

+41
-17
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ These environment variables can be set to configure some aspects of AAD auth and
8989

9090
#### sqlcmd executable
9191

92-
Build [sqlcmd](cmd/sqlcmd)
92+
Build [sqlcmd](cmd/modern)
9393

9494
```sh
95-
96-
go build ./cmd/sqlcmd
97-
95+
./build/build.sh
96+
```
97+
or
98+
```
99+
.\build\build.cmd
98100
```
99101

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

111113
go install github.com/tc-hib/go-winres@latest
112-
cd cmd/sqlcmd
114+
cd cmd/modern
113115
go generate
114116

115117
```

build/azure-pipelines/build-common.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ parameters:
1010
- name: VersionTag
1111
type: string
1212
default: $(Build.BuildNumber)
13+
- name: BinaryName
14+
type: string
1315

1416
steps:
1517
- task: GoTool@0
@@ -23,22 +25,22 @@ steps:
2325
command: 'custom'
2426
customCommand: 'install'
2527
arguments: 'github.com/tc-hib/go-winres@latest'
26-
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
28+
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'
2729
env:
2830
GOBIN: $(Build.SourcesDirectory)
2931

3032
- task: CmdLine@2
3133
displayName: 'generate version resource'
3234
inputs:
3335
script: $(Build.SourcesDirectory)/go-winres make --file-version git-tag --product-version git-tag
34-
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
36+
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'
3537

3638
- task: Go@0
3739
displayName: 'Go: get dependencies'
3840
inputs:
3941
command: 'get'
4042
arguments: '-d'
41-
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
43+
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'
4244
env:
4345
GOOS: ${{ parameters.OS }}
4446
GOARCH: ${{ parameters.Arch }}
@@ -48,8 +50,8 @@ steps:
4850
displayName: 'Go: build sqlcmd'
4951
inputs:
5052
command: 'build'
51-
arguments: '-o $(Build.BinariesDirectory) -ldflags="-X main.version=${{ parameters.VersionTag }}"'
52-
workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd'
53+
arguments: '-o $(Build.BinariesDirectory)/${{ parameters.BinaryName }} -ldflags="-X main.version=${{ parameters.VersionTag }}"'
54+
workingDirectory: '$(Build.SourcesDirectory)/cmd/modern'
5355
env:
5456
GOOS: ${{ parameters.OS }}
5557
GOARCH: ${{ parameters.Arch }}

build/azure-pipelines/build-product.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,37 @@ stages:
2323
artifact: LinuxAmd64
2424
os:
2525
arch:
26+
binaryName: 'sqlcmd'
2627
mac:
2728
imageName: 'macOS-latest'
2829
artifact: DarwinAmd64
2930
os:
3031
arch:
32+
binaryName: 'sqlcmd'
3133
windows:
3234
imageName: 'windows-latest'
3335
artifact: WindowsAmd64
3436
os:
3537
arch:
38+
binaryName: 'sqlcmd.exe'
3639
linuxArm:
3740
imageName: 'ubuntu-latest'
3841
artifact: LinuxArm64
3942
os:
4043
arch: arm64
44+
binaryName: 'sqlcmd'
4145
windowsArm:
4246
imageName: 'windows-latest'
4347
artifact: WindowsArm
4448
os:
4549
arch: arm
50+
binaryName: 'sqlcmd.exe'
4651
linuxs390x:
4752
imageName: 'ubuntu-latest'
4853
artifact: LinuxS390x
4954
os:
5055
arch: s390x
56+
binaryName: 'sqlcmd'
5157
pool:
5258
vmImage: $(imageName)
5359
steps:
@@ -60,6 +66,7 @@ stages:
6066
Arch: $(arch)
6167
ArtifactName: $(artifact)
6268
VersionTag: $(getVersion.VERSION_TAG)
69+
BinaryName: $(binaryName)
6370

6471
- stage: CreatePackages
6572
displayName: Create packages to publish
@@ -73,6 +80,10 @@ stages:
7380
inputs:
7481
buildType: 'current'
7582
targetPath: '$(Pipeline.Workspace)'
83+
- task: UseDotNet@2
84+
inputs:
85+
packageType: 'sdk'
86+
version: '2.1.x'
7687
- task: EsrpCodeSigning@1
7788
displayName: Sign Windows binary
7889
inputs:

build/build.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
REM Get Version Tag
2+
for /f %%i in ('"git describe --tags --abbrev=0"') do set sqlcmdVersion=%%i
3+
4+
REM Generates sqlcmd.exe in the root dir of the repo
5+
go build -o %~dp0..\sqlcmd.exe -ldflags="-X main.version=%sqlcmdVersion%" %~dp0..\cmd\modern

build/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
scriptdir=`dirname $0`
3+
versionTag=`git describe --tags --abbrev=0`
4+
go build -o $scriptdir/../sqlcmd -ldflags="-X main.version=$versionTag" $scriptdir/../cmd/modern

cmd/modern/build.cmd

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/modern/build.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/modern/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// command-line interface (CLI) should be used based on if the first argument provided
77
// by the user is a valid sub-command for the new CLI, if so it executes the
88
// new cobra CLI; otherwise, it falls back to the old kong-based CLI.
9+
10+
//go:generate go-winres make --file-version=git-tag --product-version=git-tag
11+
912
package main
1013

1114
import (
@@ -25,6 +28,7 @@ import (
2528

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

2933
// main is the entry point for the sqlcmd command line interface.
3034
// It parses command line options and initializes the command parser.
@@ -42,7 +46,7 @@ func main() {
4246
cmdparser.Initialize(initializeCallback)
4347
rootCmd.Execute()
4448
} else {
45-
legacyCmd.Execute()
49+
legacyCmd.Execute(version)
4650
}
4751
}
4852

cmd/sqlcmd/sqlcmd.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
//
4-
//go:generate go-winres make --file-version=git-tag --product-version=git-tag
4+
55
package sqlcmd
66

77
import (
@@ -15,8 +15,6 @@ import (
1515
"github.com/microsoft/go-sqlcmd/pkg/sqlcmd"
1616
)
1717

18-
var version = "Local-build" // overridden in pipeline builds with: -ldflags="-X main.version=$(VersionTag)"
19-
2018
// SQLCmdArguments defines the command line arguments for sqlcmd
2119
// The exhaustive list is at https://docs.microsoft.com/sql/tools/sqlcmd-utility?view=sql-server-ver15
2220
type SQLCmdArguments struct {
@@ -118,7 +116,7 @@ func (a SQLCmdArguments) authenticationMethod(hasPassword bool) string {
118116
return a.AuthenticationMethod
119117
}
120118

121-
func Execute() {
119+
func Execute(version string) {
122120
ctx := kong.Parse(&args, kong.NoDefaultHelp())
123121
if args.Version {
124122
ctx.Printf("%v", version)

0 commit comments

Comments
 (0)