Skip to content

Commit

Permalink
feat: add FileVersion and icon to Win exe (influxdata#10487)
Browse files Browse the repository at this point in the history
  • Loading branch information
sspaink authored Jan 26, 2022
1 parent 4394f0b commit deda716
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ commands:
- check-changed-files-or-halt
- attach_workspace:
at: '/go'
- when:
condition:
equal: [ windows, << parameters.type >> ]
steps:
- run: make versioninfo
- when:
condition: << parameters.nightly >>
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ process.yml
/.vscode
/*.toml
/*.conf
resource.syso
versioninfo.json
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ help:
deps:
go mod download -x

.PHONY: version
version:
@echo $(version)-$(commit)

.PHONY: versioninfo
versioninfo:
go install github.com/josephspurrier/goversioninfo/cmd/[email protected]; \
go run scripts/generate_versioninfo/main.go; \
go generate cmd/telegraf/telegraf_windows.go; \

.PHONY: telegraf
telegraf:
go build -ldflags "$(LDFLAGS)" ./cmd/telegraf
Expand Down Expand Up @@ -235,6 +245,7 @@ install: $(buildbin)
# the bin between deb/rpm/tar packages over building directly into the package
# directory.
$(buildbin):
echo $(GOOS)
@mkdir -pv $(dir $@)
go build -o $(dir $@) -ldflags "$(LDFLAGS)" ./cmd/telegraf

Expand Down
Binary file added assets/tiger.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions cmd/telegraf/telegraf_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:build windows
// +build windows

//go:generate goversioninfo -icon=../../assets/tiger.ico

package main

import (
Expand Down
46 changes: 46 additions & 0 deletions scripts/generate_versioninfo/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit deda716

Please sign in to comment.