mirror of
https://github.com/goreleaser/nfpm.git
synced 2026-06-19 08:05:04 +00:00
fix: use goversion lib (#685)
* feat: use goversion lib Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: trailing empty line Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
90d33177a3
commit
f8c8ab0057
+1
-1
@@ -27,7 +27,7 @@ builds:
|
||||
flags:
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- -s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
|
||||
- -s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser -X main.treeState={{ .IsGitDirty }}
|
||||
|
||||
dockers:
|
||||
- image_templates:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<p align="center">
|
||||
<img alt="GoReleaser Logo" src="https://avatars2.githubusercontent.com/u/24697112?v=3&s=200" height="140" />
|
||||
<h3 align="center">nFPM</h3>
|
||||
<p align="center">nFPM is a simple, 0-dependencies, deb, rpm and apk packager.</p>
|
||||
<p align="center">nFPM is a simple and 0-dependencies deb, rpm, apk and arch linux packager written in Go</p>
|
||||
<p align="center">
|
||||
<a href="https://github.com/goreleaser/nfpm/releases/latest"><img alt="Release" src="https://img.shields.io/github/release/goreleaser/nfpm.svg?style=for-the-badge"></a>
|
||||
<a href="/LICENSE.md"><img alt="Software License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=for-the-badge"></a>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
_____ ____ __ __
|
||||
_ __ | ___| _ \| \/ |
|
||||
| '_ \| |_ | |_) | |\/| |
|
||||
| | | | _| | __/| | | |
|
||||
|_| |_|_| |_| |_| |_|
|
||||
+36
-22
@@ -1,42 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
|
||||
_ "embed"
|
||||
|
||||
goversion "github.com/caarlos0/go-version"
|
||||
"github.com/goreleaser/nfpm/v2/internal/cmd"
|
||||
)
|
||||
|
||||
// nolint: gochecknoglobals
|
||||
var (
|
||||
version = "dev"
|
||||
commit = ""
|
||||
date = ""
|
||||
builtBy = ""
|
||||
version = "dev"
|
||||
treeState = ""
|
||||
commit = ""
|
||||
date = ""
|
||||
builtBy = ""
|
||||
)
|
||||
|
||||
const website = "https://nfpm.goreleaser.com"
|
||||
|
||||
//go:embed art.txt
|
||||
var asciiArt string
|
||||
|
||||
func main() {
|
||||
cmd.Execute(
|
||||
buildVersion(version, commit, date, builtBy),
|
||||
buildVersion(version, commit, date, builtBy, treeState),
|
||||
os.Exit,
|
||||
os.Args[1:],
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
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 buildVersion(version, commit, date, builtBy, treeState string) goversion.Info {
|
||||
return goversion.GetVersionInfo(
|
||||
goversion.WithAppDetails("nfpm", "a simple and 0-dependencies deb, rpm, apk and arch linux packager written in Go", website),
|
||||
goversion.WithASCIIName(asciiArt),
|
||||
func(i *goversion.Info) {
|
||||
if commit != "" {
|
||||
i.GitCommit = commit
|
||||
}
|
||||
if treeState != "" {
|
||||
i.GitTreeState = treeState
|
||||
}
|
||||
if date != "" {
|
||||
i.BuildDate = date
|
||||
}
|
||||
if version != "" {
|
||||
i.GitVersion = version
|
||||
}
|
||||
if builtBy != "" {
|
||||
i.BuiltBy = builtBy
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ require (
|
||||
github.com/ProtonMail/gopenpgp/v2 v2.7.1
|
||||
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb
|
||||
github.com/caarlos0/go-rpmutils v0.2.1-0.20211112020245-2cd62ff89b11
|
||||
github.com/caarlos0/go-version v0.1.1
|
||||
github.com/cavaliergopher/cpio v1.0.1
|
||||
github.com/google/go-cmp v0.5.9
|
||||
github.com/goreleaser/chglog v0.5.0
|
||||
|
||||
@@ -29,6 +29,8 @@ github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7N
|
||||
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/caarlos0/go-rpmutils v0.2.1-0.20211112020245-2cd62ff89b11 h1:IRrDwVlWQr6kS1U8/EtyA1+EHcc4yl8pndcqXWrEamg=
|
||||
github.com/caarlos0/go-rpmutils v0.2.1-0.20211112020245-2cd62ff89b11/go.mod h1:je2KZ+LxaCNvCoKg32jtOIULcFogJKcL1ZWUaIBjKj0=
|
||||
github.com/caarlos0/go-version v0.1.1 h1:1bikKHkGGVIIxqCmufhSSs3hpBScgHGacrvsi8FuIfc=
|
||||
github.com/caarlos0/go-version v0.1.1/go.mod h1:Ze5Qx4TsBBi5FyrSKVg1Ibc44KGV/llAaKGp86oTwZ0=
|
||||
github.com/caarlos0/testfs v0.4.4 h1:3PHvzHi5Lt+g332CiShwS8ogTgS3HjrmzZxCm6JCDr8=
|
||||
github.com/caarlos0/testfs v0.4.4/go.mod h1:bRN55zgG4XCUVVHZCeU+/Tz1Q6AxEJOEJTliBy+1DMk=
|
||||
github.com/cavaliergopher/cpio v1.0.1 h1:KQFSeKmZhv0cr+kawA3a0xTQCU4QxXF1vhU7P7av2KM=
|
||||
|
||||
@@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
goversion "github.com/caarlos0/go-version"
|
||||
_ "github.com/goreleaser/nfpm/v2/apk" // apk packager
|
||||
_ "github.com/goreleaser/nfpm/v2/arch" // archlinux packager
|
||||
_ "github.com/goreleaser/nfpm/v2/deb" // deb packager
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func Execute(version string, exit func(int), args []string) {
|
||||
func Execute(version goversion.Info, exit func(int), args []string) {
|
||||
newRootCmd(version, exit).Execute(args)
|
||||
}
|
||||
|
||||
@@ -28,20 +29,21 @@ func (cmd *rootCmd) Execute(args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func newRootCmd(version string, exit func(int)) *rootCmd {
|
||||
func newRootCmd(version goversion.Info, exit func(int)) *rootCmd {
|
||||
root := &rootCmd{
|
||||
exit: exit,
|
||||
}
|
||||
cmd := &cobra.Command{
|
||||
Use: "nfpm",
|
||||
Short: "Packages apps on RPM, Deb and APK formats based on a YAML configuration file",
|
||||
Long: `nFPM is a simple, 0-dependencies, deb, rpm and apk packager.`,
|
||||
Version: version,
|
||||
Short: "Packages apps on RPM, Deb, APK and Arch Linux formats based on a YAML configuration file",
|
||||
Long: `nFPM is a simple and 0-dependencies deb, rpm, apk and arch linux packager written in Go.`,
|
||||
Version: version.String(),
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
}
|
||||
cmd.SetVersionTemplate("{{.Version}}")
|
||||
|
||||
cmd.AddCommand(
|
||||
newInitCmd().cmd,
|
||||
|
||||
Reference in New Issue
Block a user