forked from goreleaser/goreleaser
/
config.go
353 lines (311 loc) · 10.8 KB
/
config.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// Package config contains the model and loader of the goreleaser configuration
// file.
package config
import (
"io"
"io/ioutil"
"os"
"strings"
"github.com/apex/log"
"gopkg.in/yaml.v2"
)
// GitHubURLs holds the URLs to be used when using github enterprise
type GitHubURLs struct {
API string `yaml:"api,omitempty"`
Upload string `yaml:"upload,omitempty"`
Download string `yaml:"download,omitempty"`
}
// Repo represents any kind of repo (github, gitlab, etc)
type Repo struct {
Owner string `yaml:",omitempty"`
Name string `yaml:",omitempty"`
}
// String of the repo, e.g. owner/name
func (r Repo) String() string {
if r.Owner == "" && r.Name == "" {
return ""
}
return r.Owner + "/" + r.Name
}
// Homebrew contains the brew section
type Homebrew struct {
Name string `yaml:",omitempty"`
GitHub Repo `yaml:",omitempty"`
CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"`
Folder string `yaml:",omitempty"`
Caveats string `yaml:",omitempty"`
Plist string `yaml:",omitempty"`
Install string `yaml:",omitempty"`
Dependencies []string `yaml:",omitempty"`
Test string `yaml:",omitempty"`
Conflicts []string `yaml:",omitempty"`
Description string `yaml:",omitempty"`
Homepage string `yaml:",omitempty"`
SkipUpload bool `yaml:"skip_upload,omitempty"`
DownloadStrategy string `yaml:"download_strategy,omitempty"`
SourceTarball string `yaml:"-"`
URLTemplate string `yaml:"url_template,omitempty"`
}
// Scoop contains the scoop.sh section
type Scoop struct {
Name string `yaml:",omitempty"`
Bucket Repo `yaml:",omitempty"`
CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"`
Homepage string `yaml:",omitempty"`
Description string `yaml:",omitempty"`
License string `yaml:",omitempty"`
URLTemplate string `yaml:"url_template,omitempty"`
Persist []string `yaml:"persist,omitempty"`
}
// CommitAuthor is the author of a Git commit
type CommitAuthor struct {
Name string `yaml:",omitempty"`
Email string `yaml:",omitempty"`
}
// Hooks define actions to run before and/or after something
type Hooks struct {
Pre string `yaml:",omitempty"`
Post string `yaml:",omitempty"`
}
// IgnoredBuild represents a build ignored by the user
type IgnoredBuild struct {
Goos, Goarch, Goarm string
}
// StringArray is a wrapper for an array of strings
type StringArray []string
// UnmarshalYAML is a custom unmarshaler that wraps strings in arrays
func (a *StringArray) UnmarshalYAML(unmarshal func(interface{}) error) error {
var strings []string
if err := unmarshal(&strings); err != nil {
var str string
if err := unmarshal(&str); err != nil {
return err
}
*a = []string{str}
} else {
*a = strings
}
return nil
}
// FlagArray is a wrapper for an array of strings
type FlagArray []string
// UnmarshalYAML is a custom unmarshaler that wraps strings in arrays
func (a *FlagArray) UnmarshalYAML(unmarshal func(interface{}) error) error {
var flags []string
if err := unmarshal(&flags); err != nil {
var flagstr string
if err := unmarshal(&flagstr); err != nil {
return err
}
*a = strings.Fields(flagstr)
} else {
*a = flags
}
return nil
}
// Build contains the build configuration section
type Build struct {
Goos []string `yaml:",omitempty"`
Goarch []string `yaml:",omitempty"`
Goarm []string `yaml:",omitempty"`
Targets []string `yaml:",omitempty"`
Ignore []IgnoredBuild `yaml:",omitempty"`
Main string `yaml:",omitempty"`
Ldflags StringArray `yaml:",omitempty"`
Flags FlagArray `yaml:",omitempty"`
Binary string `yaml:",omitempty"`
Hooks Hooks `yaml:",omitempty"`
Env []string `yaml:",omitempty"`
Lang string `yaml:",omitempty"`
Asmflags StringArray `yaml:",omitempty"`
Gcflags StringArray `yaml:",omitempty"`
}
// FormatOverride is used to specify a custom format for a specific GOOS.
type FormatOverride struct {
Goos string `yaml:",omitempty"`
Format string `yaml:",omitempty"`
}
// Archive config used for the archive
type Archive struct {
NameTemplate string `yaml:"name_template,omitempty"`
Replacements map[string]string `yaml:",omitempty"`
Format string `yaml:",omitempty"`
FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"`
WrapInDirectory bool `yaml:"wrap_in_directory,omitempty"`
Files []string `yaml:",omitempty"`
}
// Release config used for the GitHub release
type Release struct {
GitHub Repo `yaml:",omitempty"`
Draft bool `yaml:",omitempty"`
Prerelease bool `yaml:",omitempty"`
Disable bool `yaml:",omitempty"`
NameTemplate string `yaml:"name_template,omitempty"`
}
// NFPM config
type NFPM struct {
NFPMOverridables `yaml:",inline"`
Overrides map[string]NFPMOverridables `yaml:"overrides,omitempty"`
Formats []string `yaml:",omitempty"`
Vendor string `yaml:",omitempty"`
Homepage string `yaml:",omitempty"`
Maintainer string `yaml:",omitempty"`
Description string `yaml:",omitempty"`
License string `yaml:",omitempty"`
Bindir string `yaml:",omitempty"`
}
// NFPMScripts is used to specify maintainer scripts
type NFPMScripts struct {
PreInstall string `yaml:"preinstall,omitempty"`
PostInstall string `yaml:"postinstall,omitempty"`
PreRemove string `yaml:"preremove,omitempty"`
PostRemove string `yaml:"postremove,omitempty"`
}
// NFPMOverridables is used to specify per package format settings
type NFPMOverridables struct {
NameTemplate string `yaml:"name_template,omitempty"`
Replacements map[string]string `yaml:",omitempty"`
Dependencies []string `yaml:",omitempty"`
Recommends []string `yaml:",omitempty"`
Suggests []string `yaml:",omitempty"`
Conflicts []string `yaml:",omitempty"`
EmptyFolders []string `yaml:"empty_folders,omitempty"`
Files map[string]string `yaml:",omitempty"`
ConfigFiles map[string]string `yaml:"config_files,omitempty"`
Scripts NFPMScripts `yaml:"scripts,omitempty"`
}
// Sign config
type Sign struct {
Cmd string `yaml:"cmd,omitempty"`
Args []string `yaml:"args,omitempty"`
Signature string `yaml:"signature,omitempty"`
Artifacts string `yaml:"artifacts,omitempty"`
}
// SnapcraftAppMetadata for the binaries that will be in the snap package
type SnapcraftAppMetadata struct {
Plugs []string
Daemon string
Args string
}
// Snapcraft config
type Snapcraft struct {
NameTemplate string `yaml:"name_template,omitempty"`
Replacements map[string]string `yaml:",omitempty"`
Publish bool `yaml:",omitempty"`
Name string `yaml:",omitempty"`
Summary string `yaml:",omitempty"`
Description string `yaml:",omitempty"`
Grade string `yaml:",omitempty"`
Confinement string `yaml:",omitempty"`
Apps map[string]SnapcraftAppMetadata `yaml:",omitempty"`
}
// Snapshot config
type Snapshot struct {
NameTemplate string `yaml:"name_template,omitempty"`
}
// Checksum config
type Checksum struct {
NameTemplate string `yaml:"name_template,omitempty"`
}
// Docker image config
type Docker struct {
Binary string `yaml:",omitempty"`
Goos string `yaml:",omitempty"`
Goarch string `yaml:",omitempty"`
Goarm string `yaml:",omitempty"`
Image string `yaml:",omitempty"`
Dockerfile string `yaml:",omitempty"`
ImageTemplates []string `yaml:"image_templates,omitempty"`
SkipPush bool `yaml:"skip_push,omitempty"`
TagTemplates []string `yaml:"tag_templates,omitempty"`
Files []string `yaml:"extra_files,omitempty"`
BuildFlagTemplates []string `yaml:"build_flag_templates,omitempty"`
}
// Filters config
type Filters struct {
Exclude []string `yaml:",omitempty"`
}
// Changelog Config
type Changelog struct {
Filters Filters `yaml:",omitempty"`
Sort string `yaml:",omitempty"`
}
// EnvFiles holds paths to files that contains environment variables
// values like the github token for example
type EnvFiles struct {
GitHubToken string `yaml:"github_token,omitempty"`
}
// Git config
type Git struct {
ShortHash bool `yaml:"short_hash,omitempty"`
}
// Before config
type Before struct {
Hooks []string `yaml:",omitempty"`
}
// S3 contains s3 config
type S3 struct {
Region string
Bucket string
Folder string
Profile string
Endpoint string // used for minio for example
ACL string
}
// Put HTTP upload configuration
type Put struct {
Name string `yaml:",omitempty"`
Target string `yaml:",omitempty"`
Username string `yaml:",omitempty"`
Mode string `yaml:",omitempty"`
ChecksumHeader string `yaml:"checksum_header,omitempty"`
TrustedCerts string `yaml:"trusted_certificates,omitempty"`
Checksum bool `yaml:",omitempty"`
Signature bool `yaml:",omitempty"`
}
// Project includes all project configuration
type Project struct {
ProjectName string `yaml:"project_name,omitempty"`
Release Release `yaml:",omitempty"`
Brew Homebrew `yaml:",omitempty"`
Scoop Scoop `yaml:",omitempty"`
Builds []Build `yaml:",omitempty"`
Archive Archive `yaml:",omitempty"`
NFPM NFPM `yaml:",omitempty"`
Snapcraft Snapcraft `yaml:",omitempty"`
Snapshot Snapshot `yaml:",omitempty"`
Checksum Checksum `yaml:",omitempty"`
Dockers []Docker `yaml:",omitempty"`
Artifactories []Put `yaml:",omitempty"`
Puts []Put `yaml:",omitempty"`
S3 []S3 `yaml:"s3,omitempty"`
Changelog Changelog `yaml:",omitempty"`
Dist string `yaml:",omitempty"`
Sign Sign `yaml:",omitempty"`
EnvFiles EnvFiles `yaml:"env_files,omitempty"`
Git Git `yaml:",omitempty"`
Before Before `yaml:",omitempty"`
// this is a hack ¯\_(ツ)_/¯
SingleBuild Build `yaml:"build,omitempty"`
// should be set if using github enterprise
GitHubURLs GitHubURLs `yaml:"github_urls,omitempty"`
}
// Load config file
func Load(file string) (config Project, err error) {
f, err := os.Open(file) // #nosec
if err != nil {
return
}
log.WithField("file", file).Info("loading config file")
return LoadReader(f)
}
// LoadReader config via io.Reader
func LoadReader(fd io.Reader) (config Project, err error) {
data, err := ioutil.ReadAll(fd)
if err != nil {
return config, err
}
err = yaml.UnmarshalStrict(data, &config)
log.WithField("config", config).Debug("loaded config file")
return config, err
}