From e63043dfe0fd1c88b4d7ae40dbccf67c97daa148 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sat, 19 Mar 2022 23:45:35 -0400 Subject: [PATCH 1/9] Add file version for Windows binary --- .gitignore | 5 ++++- README.md | 11 ++++++++++ build/azure-pipelines/build-common.yml | 15 ++++++++++++++ cmd/sqlcmd/main.go | 2 +- cmd/sqlcmd/winres/winres.json | 28 ++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 cmd/sqlcmd/winres/winres.json 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..899df1ee 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 `GOPATH` 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..0b8f1a99 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -13,6 +13,21 @@ steps: inputs: version: '1.16.5' +- 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' + +- task: Go@0 + displayName: 'Go generate' + inputs: + command: 'custom' + customCommand: 'generate' + workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' + - task: Go@0 displayName: 'Go: get dependencies' 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 From a3d7fc629663bc33f8497595dc1131736ff5fba8 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 00:06:57 -0400 Subject: [PATCH 2/9] fix gopath --- build/azure-pipelines/build-common.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index 0b8f1a99..e52ce442 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -8,10 +8,16 @@ parameters: - name: ArtifactName type: string +variables: + GOPATH: $(Build.SourcesDirectory)\bin + steps: - task: GoTool@0 inputs: version: '1.16.5' + goPath: $(GOPATH) + +- script: echo '##vso[task.prependpath]$(GOPATH)' - task: Go@0 displayName: 'Go install go-winres' @@ -20,6 +26,8 @@ steps: customCommand: 'install' arguments: 'github.com/tc-hib/go-winres@latest' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' + env: + GOPATH: $(GOPATH) - task: Go@0 displayName: 'Go generate' @@ -27,6 +35,8 @@ steps: command: 'custom' customCommand: 'generate' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' + env: + GOPATH: $(GOPATH) - task: Go@0 displayName: 'Go: get dependencies' @@ -37,7 +47,8 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - + GOPATH: $(GOPATH) + - task: Go@0 displayName: 'Go: build sqlcmd' inputs: @@ -47,6 +58,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} + GOPATH: $(GOPATH) - task: CopyFiles@2 inputs: From b96e278642609d7516d6921d07516b127e0d2266 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 00:12:31 -0400 Subject: [PATCH 3/9] use gobin instead of gopath --- build/azure-pipelines/build-common.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index e52ce442..ebc0e48f 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -9,15 +9,15 @@ parameters: type: string variables: - GOPATH: $(Build.SourcesDirectory)\bin + GOBIN: $(Build.SourcesDirectory)\bin steps: - task: GoTool@0 inputs: version: '1.16.5' - goPath: $(GOPATH) + GOBIN: $(GOBIN) -- script: echo '##vso[task.prependpath]$(GOPATH)' +- script: echo '##vso[task.prependpath]$(GOBIN)' - task: Go@0 displayName: 'Go install go-winres' @@ -27,7 +27,7 @@ steps: arguments: 'github.com/tc-hib/go-winres@latest' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' env: - GOPATH: $(GOPATH) + GOBIN: $(GOBIN) - task: Go@0 displayName: 'Go generate' @@ -36,7 +36,7 @@ steps: customCommand: 'generate' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' env: - GOPATH: $(GOPATH) + GOBIN: $(GOBIN) - task: Go@0 displayName: 'Go: get dependencies' @@ -47,7 +47,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOPATH: $(GOPATH) + GOBIN: $(GOBIN) - task: Go@0 displayName: 'Go: build sqlcmd' @@ -58,7 +58,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOPATH: $(GOPATH) + GOBIN: $(GOBIN) - task: CopyFiles@2 inputs: From 1599eb2b71891264de673e5ceea75bb13d1ded87 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 00:16:08 -0400 Subject: [PATCH 4/9] update readme --- README.md | 2 +- build/azure-pipelines/build-common.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 899df1ee..d3253df0 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ 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 `GOPATH` to your `PATH` then use `go generate` +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 diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index ebc0e48f..239a321b 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -8,6 +8,7 @@ parameters: - name: ArtifactName type: string + variables: GOBIN: $(Build.SourcesDirectory)\bin From d1006a2b2f2fc6bb0367e8cc31454d909f53e0ac Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 00:19:35 -0400 Subject: [PATCH 5/9] templates cannot use variables --- build/azure-pipelines/build-common.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index 239a321b..6504f28e 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -7,18 +7,17 @@ parameters: default: - name: ArtifactName type: string - - -variables: - GOBIN: $(Build.SourcesDirectory)\bin +- name: GOBIN + type: string + default: $(Build.SourcesDirectory)\bin steps: - task: GoTool@0 inputs: version: '1.16.5' - GOBIN: $(GOBIN) + GOBIN: ${{ parameters.GOBIN }} -- script: echo '##vso[task.prependpath]$(GOBIN)' +- script: echo '##vso[task.prependpath]${{ parameters.GOBIN }}' - task: Go@0 displayName: 'Go install go-winres' @@ -28,7 +27,7 @@ steps: arguments: 'github.com/tc-hib/go-winres@latest' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' env: - GOBIN: $(GOBIN) + GOBIN: ${{ parameters.GOBIN }} - task: Go@0 displayName: 'Go generate' @@ -37,7 +36,7 @@ steps: customCommand: 'generate' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' env: - GOBIN: $(GOBIN) + GOBIN: ${{ parameters.GOBIN }} - task: Go@0 displayName: 'Go: get dependencies' @@ -48,7 +47,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOBIN: $(GOBIN) + GOBIN: ${{ parameters.GOBIN }} - task: Go@0 displayName: 'Go: build sqlcmd' @@ -59,7 +58,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOBIN: $(GOBIN) + GOBIN: ${{ parameters.GOBIN }} - task: CopyFiles@2 inputs: From 718ad63c85c3127ea565ecf404c35add7e6ec621 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 00:41:39 -0400 Subject: [PATCH 6/9] trying to debug path issue --- build/azure-pipelines/build-common.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index 6504f28e..b47a8b9b 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -7,6 +7,7 @@ parameters: default: - name: ArtifactName type: string +# Currently GOBIN is only relevant for Windows to find winres - name: GOBIN type: string default: $(Build.SourcesDirectory)\bin @@ -19,6 +20,8 @@ steps: - script: echo '##vso[task.prependpath]${{ parameters.GOBIN }}' +- script: echo 'path is %path% or $(PATH)' + - task: Go@0 displayName: 'Go install go-winres' inputs: From f7798fa8c5fb8d882271361e492ec8fc5eb549e6 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 00:51:02 -0400 Subject: [PATCH 7/9] still debugging path --- build/azure-pipelines/build-common.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index b47a8b9b..59cbb2a5 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -18,9 +18,9 @@ steps: version: '1.16.5' GOBIN: ${{ parameters.GOBIN }} -- script: echo '##vso[task.prependpath]${{ parameters.GOBIN }}' +- script: echo ##vso[task.prependpath]${{ parameters.GOBIN }} -- script: echo 'path is %path% or $(PATH)' +- script: echo path is %path% or $(PATH) > $(Build.ArtifactStagingDirectory)/path.txt - task: Go@0 displayName: 'Go install go-winres' From e1e5db98c62cd4ef4d280942348be954fd276f60 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 08:38:45 -0400 Subject: [PATCH 8/9] use binariesdir for gobin --- build/azure-pipelines/build-common.yml | 27 ++++++++------------------ 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index 59cbb2a5..d2a47cff 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -7,20 +7,12 @@ parameters: default: - name: ArtifactName type: string -# Currently GOBIN is only relevant for Windows to find winres -- name: GOBIN - type: string - default: $(Build.SourcesDirectory)\bin steps: - task: GoTool@0 inputs: version: '1.16.5' - GOBIN: ${{ parameters.GOBIN }} - -- script: echo ##vso[task.prependpath]${{ parameters.GOBIN }} - -- script: echo path is %path% or $(PATH) > $(Build.ArtifactStagingDirectory)/path.txt + goBin: $(Build.BinariesDirectory) - task: Go@0 displayName: 'Go install go-winres' @@ -30,16 +22,13 @@ steps: arguments: 'github.com/tc-hib/go-winres@latest' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' env: - GOBIN: ${{ parameters.GOBIN }} + GOBIN: $(Build.BinariesDirectory) -- task: Go@0 - displayName: 'Go generate' +- task: CmdLine@2 + displayName: 'generate version resource' inputs: - command: 'custom' - customCommand: 'generate' + script: $(Build.BinariesDirectory)/go-winres make --file-version git-tag --product-version git-tag workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' - env: - GOBIN: ${{ parameters.GOBIN }} - task: Go@0 displayName: 'Go: get dependencies' @@ -50,7 +39,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOBIN: ${{ parameters.GOBIN }} + GOBIN: $(Build.BinariesDirectory) - task: Go@0 displayName: 'Go: build sqlcmd' @@ -61,8 +50,8 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOBIN: ${{ parameters.GOBIN }} - + GOBIN: $(Build.BinariesDirectory) + - task: CopyFiles@2 inputs: TargetFolder: '$(Build.ArtifactStagingDirectory)' From 69a87b013371aaa9b3edcd6d65678a242c51b654 Mon Sep 17 00:00:00 2001 From: David Shiflet Date: Sun, 20 Mar 2022 08:50:51 -0400 Subject: [PATCH 9/9] put go-winres in sources dir --- build/azure-pipelines/build-common.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build/azure-pipelines/build-common.yml b/build/azure-pipelines/build-common.yml index d2a47cff..c1aed34e 100644 --- a/build/azure-pipelines/build-common.yml +++ b/build/azure-pipelines/build-common.yml @@ -12,7 +12,7 @@ steps: - task: GoTool@0 inputs: version: '1.16.5' - goBin: $(Build.BinariesDirectory) + goBin: $(Build.SourcesDirectory) - task: Go@0 displayName: 'Go install go-winres' @@ -22,12 +22,12 @@ steps: arguments: 'github.com/tc-hib/go-winres@latest' workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' env: - GOBIN: $(Build.BinariesDirectory) + GOBIN: $(Build.SourcesDirectory) - task: CmdLine@2 displayName: 'generate version resource' inputs: - script: $(Build.BinariesDirectory)/go-winres make --file-version git-tag --product-version git-tag + script: $(Build.SourcesDirectory)/go-winres make --file-version git-tag --product-version git-tag workingDirectory: '$(Build.SourcesDirectory)/cmd/sqlcmd' - task: Go@0 @@ -39,7 +39,7 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOBIN: $(Build.BinariesDirectory) + GOBIN: $(Build.SourcesDirectory) - task: Go@0 displayName: 'Go: build sqlcmd' @@ -50,8 +50,8 @@ steps: env: GOOS: ${{ parameters.OS }} GOARCH: ${{ parameters.Arch }} - GOBIN: $(Build.BinariesDirectory) - + GOBIN: $(Build.SourcesDirectory) + - task: CopyFiles@2 inputs: TargetFolder: '$(Build.ArtifactStagingDirectory)'