-
Notifications
You must be signed in to change notification settings - Fork 8
/
goreleaser.mage.go
117 lines (104 loc) · 3.29 KB
/
goreleaser.mage.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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/magefile/mage/sh"
"github.com/pterm/pterm"
"github.com/sheldonhull/magetools/pkg/magetoolsutils"
"github.com/sheldonhull/magetools/pkg/req"
)
func checkEnvVar(envVar string, required bool) (string, error) {
envVarValue := os.Getenv(envVar)
if envVarValue == "" && required {
pterm.Error.Printfln(
"%s is required and unable to proceed without this being provided. terminating task.",
envVar,
)
return "", fmt.Errorf("%s is required", envVar)
}
if envVarValue == "" {
pterm.Debug.Printfln(
"checkEnvVar() found no value for: %q, however this is marked as optional, so not exiting task",
envVar,
)
}
pterm.Debug.Printfln("checkEnvVar() found value: %q=%q", envVar, envVarValue)
return envVarValue, nil
}
// 🔨 Build builds the project for the current platform.
func Build() error {
magetoolsutils.CheckPtermDebug()
binary, err := req.ResolveBinaryByInstall("goreleaser", "github.com/goreleaser/goreleaser@latest")
if err != nil {
return err
}
releaserArgs := []string{
"build",
"--rm-dist",
"--snapshot",
"--single-target",
}
pterm.Debug.Printfln("goreleaser: %+v", releaserArgs)
return sh.RunV(binary, releaserArgs...) // "--skip-announce",.
}
// 🔨 BuildAll builds all the binaries defined in the project, for all platforms. This includes Docker image generation but skips publish.
// If there is no additional platforms configured in the task, then basically this will just be the same as `mage build`.
func BuildAll() error {
magetoolsutils.CheckPtermDebug()
binary, err := req.ResolveBinaryByInstall("goreleaser", "github.com/goreleaser/goreleaser@latest")
if err != nil {
return err
}
releaserArgs := []string{
"release",
"--snapshot",
"--rm-dist",
"--skip-publish",
}
pterm.Debug.Printfln("goreleaser: %+v", releaserArgs)
return sh.RunV(binary, releaserArgs...)
// To pass in explicit version mapping, you can do this. I'm not using at this time.
// Return sh.RunWithV(map[string]string{
// "GORELEASER_CURRENT_TAG": "latest",
// }, binary, releaserArgs...)
}
// 🔨 Release generates a release for the current platform.
func Release() error {
magetoolsutils.CheckPtermDebug()
binary, err := req.ResolveBinaryByInstall("goreleaser", "github.com/goreleaser/goreleaser@latest")
if err != nil {
return err
}
if _, err = checkEnvVar("DOCKER_ORG", true); err != nil {
return err
}
changieBinary, err := req.ResolveBinaryByInstall("changie", "github.com/miniscruff/changie@latest")
if err != nil {
pterm.Error.Println("unable to install changelog binary")
return err
}
releaseVersion, err := sh.Output(changieBinary, "latest")
if err != nil {
pterm.Warning.Printfln("changie pulling latest release note version failure: %v", err)
}
cleanVersion := strings.TrimSpace(releaseVersion)
cleanpath := filepath.Join(".changes", cleanVersion+".md")
if os.Getenv("GITHUB_WORKSPACE") != "" {
cleanpath = filepath.Join(os.Getenv("GITHUB_WORKSPACE"), ".changes", cleanVersion+".md")
}
releaserArgs := []string{
"release",
"--rm-dist",
"--skip-validate",
fmt.Sprintf("--release-notes=%s", cleanpath),
}
pterm.Debug.Printfln("goreleaser: %+v", releaserArgs)
return sh.RunWithV(map[string]string{
"GORELEASER_CURRENT_TAG": cleanVersion,
},
binary,
releaserArgs...,
)
}