diff --git a/.gitignore b/.gitignore index b6ede629..22a0a10a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,7 @@ coverage.json coverage.txt coverage.xml -testresults.xml \ No newline at end of file +testresults.xml + +# .syso is generated by go-winres. Only needed for official builds +*.syso diff --git a/README.md b/README.md index 90dd7f0a..d3253df0 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,17 @@ pkg/sqlcmd is consumable by other hosts. Go docs for the package are forthcoming ## Building +To add version data to your build using `go-winres`, add `GOBIN` to your `PATH` then use `go generate` +The version on the binary will match the version tag of the branch. + +```sh + +go install https://github.com/tc-hib/go-winres +cd cmd/sqlcmd +go generate + +``` + Scripts to build the binaries and package them for release will be added in a build folder off the root. We will also add Azure Devops pipeline yml files there to initiate builds and releases. Until then just use `go build ./cmd/sqlcmd` to create a sqlcmd binary. ## Testing diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index 1330d720..c1aed34e 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -12,6 +12,23 @@ steps: - task: GoTool@0 inputs: version: '1.16.5' + goBin: $(Build.SourcesDirectory) + +- task: Go@0 + displayName: 'Go install go-winres' + inputs: + command: 'custom' + customCommand: 'install' + arguments: 'github.com/tc-hib/go-winres@latest' + workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' + 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' - task: Go@0 displayName: 'Go: get dependencies' @@ -22,7 +39,8 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - + GOBIN: $(Build.SourcesDirectory) + - task: Go@0 displayName: 'Go: build sqlcmd' inputs: @@ -32,6 +50,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} + GOBIN: $(Build.SourcesDirectory) - task: CopyFiles@2 inputs: diff --git a/cmd/sqlcmd/main.go b/cmd/sqlcmd/main.go index c1573b04..9d2ce7be 100644 --- a/cmd/sqlcmd/main.go +++ b/cmd/sqlcmd/main.go @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - +//go:generate go-winres make --file-version=git-tag --product-version=git-tag package main import ( diff --git a/cmd/sqlcmd/winres/winres.json b/cmd/sqlcmd/winres/winres.json new file mode 100644 index 00000000..7626ed75 --- /dev/null +++ b/cmd/sqlcmd/winres/winres.json @@ -0,0 +1,28 @@ +{ + "RT_VERSION": { + "#1": { + "0000": { + "fixed": { + "file_version": "0.0.0.0", + "product_version": "0.0.0.0" + }, + "info": { + "0409": { + "Comments": "SQL", + "CompanyName": "Microsoft Corporation", + "FileDescription": "T-SQL execution command line utility", + "FileVersion": "", + "InternalName": "go-sqlcmd", + "LegalCopyright": "Microsoft Corporation", + "LegalTrademarks": "Microsoft SQL Server is a registered trademark of Microsoft Corporation", + "OriginalFilename": "sqlcmd.exe", + "PrivateBuild": "", + "ProductName": "Microsoft SQL Server", + "ProductVersion": "", + "SpecialBuild": "" + } + } + } + } + } +} \ No newline at end of file