feat: add FileVersion and icon to Win exe (#10487)

This commit is contained in:
Sebastian Spaink 2022-01-26 15:08:22 -06:00 committed by GitHub
parent 4394f0baff
commit deda716a15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 0 deletions

View File

@ -129,6 +129,11 @@ commands:
- check-changed-files-or-halt - check-changed-files-or-halt
- attach_workspace: - attach_workspace:
at: '/go' at: '/go'
- when:
condition:
equal: [ windows, << parameters.type >> ]
steps:
- run: make versioninfo
- when: - when:
condition: << parameters.nightly >> condition: << parameters.nightly >>
steps: steps:

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ process.yml
/.vscode /.vscode
/*.toml /*.toml
/*.conf /*.conf
resource.syso
versioninfo.json

View File

@ -99,6 +99,16 @@ help:
deps: deps:
go mod download -x go mod download -x
.PHONY: version
version:
@echo $(version)-$(commit)
.PHONY: versioninfo
versioninfo:
go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@v1.4.0; \
go run scripts/generate_versioninfo/main.go; \
go generate cmd/telegraf/telegraf_windows.go; \
.PHONY: telegraf .PHONY: telegraf
telegraf: telegraf:
go build -ldflags "$(LDFLAGS)" ./cmd/telegraf go build -ldflags "$(LDFLAGS)" ./cmd/telegraf
@ -235,6 +245,7 @@ install: $(buildbin)
# the bin between deb/rpm/tar packages over building directly into the package # the bin between deb/rpm/tar packages over building directly into the package
# directory. # directory.
$(buildbin): $(buildbin):
echo $(GOOS)
@mkdir -pv $(dir $@) @mkdir -pv $(dir $@)
go build -o $(dir $@) -ldflags "$(LDFLAGS)" ./cmd/telegraf go build -o $(dir $@) -ldflags "$(LDFLAGS)" ./cmd/telegraf

BIN
assets/tiger.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,6 +1,8 @@
//go:build windows //go:build windows
// +build windows // +build windows
//go:generate goversioninfo -icon=../../assets/tiger.ico
package main package main
import ( import (

View File

@ -0,0 +1,46 @@
// Generate the versioninfo.json with the current build version from the makefile
// The file versioninfo.json is used by the goversioninfo package to add version info into a windows binary
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log" //nolint:revive
"os/exec"
"strings"
)
type VersionInfo struct {
StringFileInfo StringFileInfo
}
type StringFileInfo struct {
ProductName string
ProductVersion string
}
func main() {
e := exec.Command("make", "version")
var out bytes.Buffer
e.Stdout = &out
if err := e.Run(); err != nil {
log.Fatalf("Failed to get version from makefile: %v", err)
}
version := strings.TrimSuffix(out.String(), "\n")
v := VersionInfo{
StringFileInfo: StringFileInfo{
ProductName: "Telegraf",
ProductVersion: version,
},
}
file, err := json.MarshalIndent(v, "", " ")
if err != nil {
log.Fatalf("Failed to marshal json: %v", err)
}
if err := ioutil.WriteFile("cmd/telegraf/versioninfo.json", file, 0644); err != nil {
log.Fatalf("Failed to write versioninfo.json: %v", err)
}
}