-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnfpm.go
86 lines (72 loc) · 1.59 KB
/
nfpm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2020, Sylabs, Inc. All rights reserved.
// +build mage
package main
import (
"fmt"
"os"
"github.com/goreleaser/nfpm"
_ "github.com/goreleaser/nfpm/deb"
_ "github.com/goreleaser/nfpm/rpm"
)
// getPackageInfo returns the target based on suffix and c.
func getPackageInfo(c nfpm.Config, format string) (*nfpm.Info, error) {
d, err := describeHead()
if err != nil {
return nil, err
}
v, err := getVersion(d)
if err != nil {
return nil, err
}
c.Version = v.String()
info, err := c.Get(format)
if err != nil {
return nil, err
}
info = nfpm.WithDefaults(info)
switch format {
case "deb":
// Ref: https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-pkgname
info.Target = fmt.Sprintf("%v_%v-%v_%v.%v",
info.Name,
info.Version,
info.Release,
info.Arch,
format)
case "rpm":
// Ref: http://ftp.rpm.org/max-rpm/ch-rpm-file-format.html
info.Target = fmt.Sprintf("%v-%v-%v.%v.%v",
info.Name,
info.Version,
info.Release,
info.Arch,
format)
default:
return nil, fmt.Errorf("unknown package format: %v", format)
}
if err = nfpm.Validate(info); err != nil {
return nil, err
}
return info, nil
}
// makePackage creates a package based on the supplied format.
func makePackage(format string) error {
config, err := nfpm.ParseFile("nfpm.yaml")
if err != nil {
return err
}
info, err := getPackageInfo(config, format)
if err != nil {
return err
}
p, err := nfpm.Get(format)
if err != nil {
return err
}
f, err := os.Create(info.Target)
if err != nil {
return err
}
defer f.Close()
return p.Package(info, f)
}