1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-16 03:52:12 +02:00
goreleaser/internal/skips/skips.go

127 lines
2.3 KiB
Go
Raw Normal View History

package skips
import (
"fmt"
"sort"
"strings"
"github.com/goreleaser/goreleaser/v2/pkg/context"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)
type Key string
const (
2023-09-17 18:59:34 +02: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-04 01:23:25 +02:00
Winget Key = "winget"
2023-11-04 01:24:04 +02:00
Snapcraft Key = "snapcraft"
2023-11-04 01:22:50 +02:00
Scoop Key = "scoop"
2023-11-04 01:31:37 +02:00
Homebrew Key = "homebrew"
2023-11-04 01:31:25 +02:00
Nix Key = "nix"
2023-11-04 01:30:48 +02:00
AUR Key = "aur"
2024-01-08 04:16:24 +02:00
NFPM Key = "nfpm"
2024-01-09 20:47:14 +02:00
Chocolatey Key = "chocolatey"
Notarize Key = "notarize"
)
func String(ctx *context.Context) string {
keys := maps.Keys(ctx.Skips)
sort.Strings(keys)
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 !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-04 01:23:25 +02:00
Winget,
2024-01-14 20:26:16 +02:00
Chocolatey,
2023-11-04 01:24:04 +02:00
Snapcraft,
2023-11-04 01:22:50 +02:00
Scoop,
2023-11-04 01:31:37 +02:00
Homebrew,
2023-11-04 01:31:25 +02:00
Nix,
2023-11-04 01:30:48 +02:00
AUR,
2024-01-08 04:16:24 +02:00
NFPM,
Before,
Notarize,
}
var Build = Keys{
2023-09-17 18:59:34 +02:00
PreBuildHooks,
PostBuildHooks,
Validate,
Before,
}