Skip to content

Commit

Permalink
chore(goreleaser): Enable reproducible builds
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 16, 2023
1 parent f0891fe commit 322e19b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project_name: castsponsorskip
before:
hooks:
- go run ./internal/generate/completions
- go run ./internal/generate/completions --date={{ .CommitDate }}
- go run ./internal/generate/manpages --version={{ .Version }} --date={{ .CommitDate }}
builds:
- env:
Expand All @@ -13,7 +13,7 @@ builds:
- -w
- -X main.version=v{{.Version}}
- -X main.commit={{.ShortCommit}}
- -X main.date={{.Date}}
- -X main.date={{.CommitDate}}
- -X main.builtBy=goreleaser
goarch:
- amd64
Expand All @@ -22,6 +22,7 @@ builds:
goarm:
- "6"
- "7"
mod_timestamp: "{{.CommitTimestamp}}"
archives:
- format: tar.gz
# use zip for windows archives
Expand Down
20 changes: 20 additions & 0 deletions internal/generate/completions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ import (
"io"
"os"
"path/filepath"
"time"

"github.com/gabe565/castsponsorskip/cmd"
flag "github.com/spf13/pflag"
)

var Shells = []string{"bash", "zsh", "fish"}

func main() {
flags := flag.NewFlagSet("", flag.ContinueOnError)

var dateParam string
flags.StringVar(&dateParam, "date", time.Now().Format(time.RFC3339), "Build date")

if err := flags.Parse(os.Args); err != nil {
panic(err)
}

date, err := time.Parse(time.RFC3339, dateParam)
if err != nil {
panic(err)
}

if err := os.RemoveAll("completions"); err != nil {
panic(err)
}
Expand Down Expand Up @@ -43,5 +59,9 @@ func main() {
if err := f.Close(); err != nil {
panic(err)
}

if err := os.Chtimes(f.Name(), date, date); err != nil {
panic(err)
}
}
}
4 changes: 4 additions & 0 deletions internal/generate/manpages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ func main() {
if err := f.Close(); err != nil {
panic(err)
}

if err := os.Chtimes(f.Name(), date, date); err != nil {
panic(err)
}
}

0 comments on commit 322e19b

Please sign in to comment.