Skip to content

Commit

Permalink
disable cgo in goreleaser and add version info as build flags
Browse files Browse the repository at this point in the history
  • Loading branch information
agaurav committed Mar 27, 2023
1 parent a520a94 commit a833fbf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
16 changes: 12 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ before:
- go generate ./...
builds:
- env:
- CGO_ENABLED=1
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- "386"
- amd64
- arm
- arm64
- ppc64
goarm:
- "7"
ignore:
- goos: linux
goarch: arm64
- goos: linux
- goos: windows
goarch: arm
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
archives:
- replacements:
darwin: Darwin
Expand Down
36 changes: 35 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,10 +16,44 @@ limitations under the License.
package main

import (
"fmt"
"github.com/OpenSLO/slogen/cmd"
"runtime"
"runtime/debug"
)

// nolint: gochecknoglobals
var (
version = "dev"
commit = ""
date = ""
builtBy = ""
)

func main() {

fmt.Printf("\nrunning version: %s\n\n-------------------\n\n",
buildVersion(version, commit, date, builtBy),
)

cmd.Execute()
}

func buildVersion(version, commit, date, builtBy string) string {
result := version
if commit != "" {
result = fmt.Sprintf("%s\ncommit: %s", result, commit)
}
if date != "" {
result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
}
if builtBy != "" {
result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
}
result = fmt.Sprintf("%s\ngoos: %s\ngoarch: %s", result, runtime.GOOS, runtime.GOARCH)
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
result = fmt.Sprintf("%s\nmodule version: %s, checksum: %s", result, info.Main.Version, info.Main.Sum)
}

return result
}

0 comments on commit a833fbf

Please sign in to comment.