1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-05 13:15:26 +02:00

chore: format and lint fixes

This commit is contained in:
Carlos Alexandro Becker 2018-07-09 00:01:06 -07:00
parent 8d444233d0
commit 495126ffd9
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 55 additions and 55 deletions

View File

@ -60,19 +60,19 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
cmd = append(cmd, build.Flags...)
asmflags, err := processFlags(ctx, build.Asmflags, "asmflags", "-asmflags=")
asmflags, err := processFlags(ctx, build.Asmflags, "-asmflags=")
if err != nil {
return err
}
cmd = append(cmd, asmflags...)
gcflags, err := processFlags(ctx, build.Gcflags, "gcflags", "-gcflags=")
gcflags, err := processFlags(ctx, build.Gcflags, "-gcflags=")
if err != nil {
return err
}
cmd = append(cmd, gcflags...)
ldflags, err := processFlags(ctx, build.Ldflags, "ldflags", "-ldflags=")
ldflags, err := processFlags(ctx, build.Ldflags, "-ldflags=")
if err != nil {
return err
}
@ -103,7 +103,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
return nil
}
func processFlags(ctx *context.Context, flags []string, flagName string, flagPrefix string) ([]string, error) {
func processFlags(ctx *context.Context, flags []string, flagPrefix string) ([]string, error) {
processed := make([]string, 0, len(flags))
for _, rawFlag := range flags {
flag, err := tmpl.New(ctx).Apply(rawFlag)

View File

@ -21,49 +21,49 @@ type fields map[string]interface{}
const (
// general keys
kProjectName = "ProjectName"
kVersion = "Version"
kTag = "Tag"
kCommit = "Commit"
kMajor = "Major"
kMinor = "Minor"
kPatch = "Patch"
kEnv = "Env"
kDate = "Date"
kTimestamp = "Timestamp"
projectName = "ProjectName"
version = "Version"
tag = "Tag"
commit = "Commit"
major = "Major"
minor = "Minor"
patch = "Patch"
env = "Env"
date = "Date"
timestamp = "Timestamp"
// artifact-only keys
kOs = "Os"
kArch = "Arch"
kArm = "Arm"
kBinary = "Binary"
os = "Os"
arch = "Arch"
arm = "Arm"
binary = "Binary"
)
// New Template
func New(ctx *context.Context) *Template {
return &Template{
fields: fields{
kProjectName: ctx.Config.ProjectName,
kVersion: ctx.Version,
kTag: ctx.Git.CurrentTag,
kCommit: ctx.Git.Commit,
kEnv: ctx.Env,
kDate: time.Now().UTC().Format(time.RFC3339),
kTimestamp: time.Now().UTC().Unix(),
projectName: ctx.Config.ProjectName,
version: ctx.Version,
tag: ctx.Git.CurrentTag,
commit: ctx.Git.Commit,
env: ctx.Env,
date: time.Now().UTC().Format(time.RFC3339),
timestamp: time.Now().UTC().Unix(),
},
}
}
// WithArtifacts populate fields from the artifact and replacements
func (t *Template) WithArtifact(a artifact.Artifact, replacements map[string]string) *Template {
var binary = a.Extra[kBinary]
var binary = a.Extra[binary]
if binary == "" {
binary = t.fields[kProjectName].(string)
binary = t.fields[projectName].(string)
}
t.fields[kOs] = replace(replacements, a.Goos)
t.fields[kArch] = replace(replacements, a.Goarch)
t.fields[kArm] = replace(replacements, a.Goarm)
t.fields[kBinary] = binary
t.fields[os] = replace(replacements, a.Goos)
t.fields[arch] = replace(replacements, a.Goarch)
t.fields[arm] = replace(replacements, a.Goarm)
t.fields[binary] = binary
return t
}
@ -82,13 +82,13 @@ func (t *Template) Apply(s string) (string, error) {
return "", err
}
sv, err := semver.NewVersion(t.fields[kTag].(string))
sv, err := semver.NewVersion(t.fields[tag].(string))
if err != nil {
return "", errors.Wrap(err, "tmpl")
}
t.fields[kMajor] = sv.Major()
t.fields[kMinor] = sv.Minor()
t.fields[kPatch] = sv.Patch()
t.fields[major] = sv.Major()
t.fields[minor] = sv.Minor()
t.fields[patch] = sv.Patch()
err = tmpl.Execute(&out, t.fields)
return out.String(), err

View File

@ -14,7 +14,7 @@ templating is available.
On fields that support templating, this fields are always available:
| Key | Description |
|:-:|:-:|
| :------------: | :----------------------------------------------: |
| `.ProjectName` | the project name |
| `.Version` | the version being released (`v` prefix stripped) |
| `.Tag` | the current git tag |
@ -30,7 +30,7 @@ On fields that are related to a single artifact (e.g., the binary name), you
may have some extra fields:
| Key | Description |
|:-:|:-:|
| :-------: | :-----------------------------------: |
| `.Os` | `GOOS` (usually allow replacements) |
| `.Arch` | `GOARCH` (usually allow replacements) |
| `.Arm` | `GOARM` (usually allow replacements) |
@ -39,7 +39,7 @@ may have some extra fields:
On all fields, you have these available functions:
| Usage | Description |
|:-:|:-:|
| :-----------------: | :--------------------------------------: |
| `time "01/02/2006"` | current UTC time in the specified format |
With all those fields, you may be able to compose the name of your artifacts