Skip to content

Commit

Permalink
feat: gomod verifiable builds (#319)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 authored Apr 15, 2021
1 parent 4107794 commit 1fb2691
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ env:
before:
hooks:
- go mod tidy
gomod:
proxy: true
builds:
- main: ./cmd/nfpm
env:
Expand Down
25 changes: 23 additions & 2 deletions cmd/nfpm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
"runtime/debug"

"github.com/alecthomas/kingpin"

Expand All @@ -19,7 +20,10 @@ import (

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

app = kingpin.New("nfpm", "not-fpm packages apps in some formats")
config = app.Flag("config", "config file").
Expand All @@ -40,7 +44,7 @@ var (
)

func main() {
app.Version(version)
app.Version(buildVersion(version, commit, date, builtBy))
app.VersionFlag.Short('v')
app.HelpFlag.Short('h')
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
Expand All @@ -56,6 +60,23 @@ func main() {
}
}

func buildVersion(version, commit, date, builtBy string) string {
result := "nfpm version " + 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)
}
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
}

func initFile(config string) error {
return ioutil.WriteFile(config, []byte(example), 0o600)
}
Expand Down

1 comment on commit 1fb2691

@vercel
Copy link

@vercel vercel bot commented on 1fb2691 Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.