1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-22 04:08:49 +02:00

131 lines
2.4 KiB
Go
Raw Normal View History

package skips
import (
"fmt"
"maps"
"slices"
"sort"
"strings"
"github.com/goreleaser/goreleaser/v2/pkg/context"
)
type Key string
const (
2023-09-17 16:59:34 +00:00
PreBuildHooks Key = "pre-hooks"
PostBuildHooks Key = "post-hooks"
Publish Key = "publish"
Announce Key = "announce"
Sign Key = "sign"
Validate Key = "validate"
SBOM Key = "sbom"
Ko Key = "ko"
Docker Key = "docker"
Before Key = "before"
2023-11-03 23:23:25 +00:00
Winget Key = "winget"
2023-11-03 23:24:04 +00:00
Snapcraft Key = "snapcraft"
2023-11-03 23:22:50 +00:00
Scoop Key = "scoop"
2023-11-03 23:31:37 +00:00
Homebrew Key = "homebrew"
2023-11-03 23:31:25 +00:00
Nix Key = "nix"
2023-11-03 23:30:48 +00:00
AUR Key = "aur"
2024-01-07 23:16:24 -03:00
NFPM Key = "nfpm"
2024-01-09 19:47:14 +01:00
Chocolatey Key = "chocolatey"
Notarize Key = "notarize"
Archive Key = "archive"
)
func String(ctx *context.Context) string {
keys := slices.Sorted(maps.Keys(ctx.Skips))
str := strings.Join(keys, ", ")
if idx := strings.LastIndex(str, ","); idx > -1 {
str = str[:idx] + " and" + str[idx+1:]
}
return str
}
func Any(ctx *context.Context, keys ...Key) bool {
for _, key := range keys {
if ctx.Skips[string(key)] {
return true
}
}
return false
}
func Set(ctx *context.Context, keys ...Key) {
for _, key := range keys {
ctx.Skips[string(key)] = true
}
}
var (
SetRelease = set(Release)
SetBuild = set(Build)
)
func set(allowed Keys) func(ctx *context.Context, keys ...string) error {
return func(ctx *context.Context, keys ...string) error {
for _, key := range keys {
if key == "" {
continue
}
if !slices.Contains(allowed, Key(key)) {
return fmt.Errorf("--skip=%s is not allowed. Valid options for skip are [%s]", key, allowed)
}
ctx.Skips[key] = true
}
return nil
}
}
type Keys []Key
func (keys Keys) String() string {
ss := make([]string, len(keys))
for i, key := range keys {
ss[i] = string(key)
}
slices.Sort(ss)
return strings.Join(ss, ", ")
}
func (keys Keys) Complete(prefix string) []string {
var result []string
for _, k := range keys {
if strings.HasPrefix(string(k), strings.ToLower(prefix)) {
result = append(result, string(k))
}
}
sort.Strings(result)
return result
}
var Release = Keys{
Publish,
Announce,
Sign,
Validate,
SBOM,
Ko,
Docker,
2023-11-03 23:23:25 +00:00
Winget,
2024-01-14 15:26:16 -03:00
Chocolatey,
2023-11-03 23:24:04 +00:00
Snapcraft,
2023-11-03 23:22:50 +00:00
Scoop,
2023-11-03 23:31:37 +00:00
Homebrew,
2023-11-03 23:31:25 +00:00
Nix,
2023-11-03 23:30:48 +00:00
AUR,
2024-01-07 23:16:24 -03:00
NFPM,
Before,
Notarize,
Archive,
}
var Build = Keys{
2023-09-17 16:59:34 +00:00
PreBuildHooks,
PostBuildHooks,
Validate,
Before,
}