Skip to content

Add version resource to Windows binaries #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 24, 2022
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
coverage.json
coverage.txt
coverage.xml
testresults.xml
testresults.xml

# .syso is generated by go-winres. Only needed for official builds
*.syso
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion build/azure-pipelines/build-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -22,7 +39,8 @@ steps:
env:
GOOS: ${{ parameters.OS }}
GOARCH: ${{ parameters.Arch }}

GOBIN: $(Build.SourcesDirectory)

- task: Go@0
displayName: 'Go: build sqlcmd'
inputs:
Expand All @@ -32,6 +50,7 @@ steps:
env:
GOOS: ${{ parameters.OS }}
GOARCH: ${{ parameters.Arch }}
GOBIN: $(Build.SourcesDirectory)

- task: CopyFiles@2
inputs:
Expand Down
2 changes: 1 addition & 1 deletion cmd/sqlcmd/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
28 changes: 28 additions & 0 deletions cmd/sqlcmd/winres/winres.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
}
}
}
}
}