github.com/windmeup/goreleaser@v1.21.95/main.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  
     6  	_ "embed"
     7  
     8  	goversion "github.com/caarlos0/go-version"
     9  	"github.com/caarlos0/log"
    10  	"github.com/charmbracelet/lipgloss"
    11  	"github.com/muesli/termenv"
    12  	"github.com/windmeup/goreleaser/cmd"
    13  	"go.uber.org/automaxprocs/maxprocs"
    14  )
    15  
    16  // nolint: gochecknoglobals
    17  var (
    18  	version   = ""
    19  	commit    = ""
    20  	treeState = ""
    21  	date      = ""
    22  	builtBy   = ""
    23  )
    24  
    25  func init() {
    26  	// enable colored output on github actions et al
    27  	if os.Getenv("CI") != "" {
    28  		lipgloss.SetColorProfile(termenv.TrueColor)
    29  	}
    30  	// automatically set GOMAXPROCS to match available CPUs.
    31  	// GOMAXPROCS will be used as the default value for the --parallelism flag.
    32  	if _, err := maxprocs.Set(); err != nil {
    33  		log.WithError(err).Warn("failed to set GOMAXPROCS")
    34  	}
    35  }
    36  
    37  func main() {
    38  	cmd.Execute(
    39  		buildVersion(version, commit, date, builtBy, treeState),
    40  		os.Exit,
    41  		os.Args[1:],
    42  	)
    43  }
    44  
    45  const website = "https://goreleaser.com"
    46  
    47  //go:embed art.txt
    48  var asciiArt string
    49  
    50  func buildVersion(version, commit, date, builtBy, treeState string) goversion.Info {
    51  	return goversion.GetVersionInfo(
    52  		goversion.WithAppDetails("goreleaser", "Deliver Go Binaries as fast and easily as possible", website),
    53  		goversion.WithASCIIName(asciiArt),
    54  		func(i *goversion.Info) {
    55  			if commit != "" {
    56  				i.GitCommit = commit
    57  			}
    58  			if treeState != "" {
    59  				i.GitTreeState = treeState
    60  			}
    61  			if date != "" {
    62  				i.BuildDate = date
    63  			}
    64  			if version != "" {
    65  				i.GitVersion = version
    66  			}
    67  			if builtBy != "" {
    68  				i.BuiltBy = builtBy
    69  			}
    70  		},
    71  	)
    72  }