When releasing, allow certain replacements.

This commit is contained in:
monopole
2021-04-30 17:08:16 -07:00
parent 7716b1bd3d
commit b6fba0ad5c
4 changed files with 54 additions and 6 deletions

View File

@@ -37,6 +37,10 @@ var (
"releasing",
"site",
}
// TODO: make this a PATH-like flag
allowedReplacements = []string {
"gopkg.in/yaml.v3",
}
)
type Command int
@@ -64,6 +68,14 @@ func (a *Args) GetCommand() Command {
return a.cmd
}
func (a *Args) AllowedReplacements() (result []string) {
// Make sure the list has no repeats.
for k := range utils.SliceToSet(allowedReplacements) {
result = append(result, k)
}
return
}
func (a *Args) Bump() semver.SvBump {
return a.bump
}

View File

@@ -8,6 +8,7 @@ import (
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/git"
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/misc"
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/semver"
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/utils"
)
// Manager manages a git repo.
@@ -116,14 +117,18 @@ func (mgr *Manager) Debug(_ misc.LaModule, doIt bool) error {
//
// * All development happens in the branch named "master".
// * Each minor release gets its own branch.
// *
//
func (mgr *Manager) Release(
target misc.LaModule, bump semver.SvBump, doIt bool) error {
target misc.LaModule, bump semver.SvBump,
allowedReplacements []string, doIt bool) error {
if reps := target.GetReplacements(); len(reps) > 0 {
return fmt.Errorf(
"to release %q, first pin these replacements: %v",
target.ShortName(), reps)
badReps := findDisallowedReplacements(reps, allowedReplacements)
if len(badReps) > 0 {
return fmt.Errorf(
"to release %q, first pin these replacements: %v",
target.ShortName(), badReps)
}
}
newVersion := target.VersionLocal().Bump(bump)
@@ -182,6 +187,18 @@ func (mgr *Manager) Release(
return nil
}
func findDisallowedReplacements(
reps []string, allowedReplacements []string) []string {
var badReps []string
for _, r := range reps {
km := utils.ExtractModule(r)
if !utils.SliceContains(allowedReplacements, km) {
badReps = append(badReps, r)
}
}
return badReps
}
func (mgr *Manager) UnRelease(target misc.LaModule, doIt bool) error {
fmt.Printf(
"Unreleasing %s/%s\n",

View File

@@ -3,6 +3,7 @@ package utils
import (
"log"
"os"
"strings"
)
func DirExists(name string) bool {
@@ -24,3 +25,20 @@ func SliceToSet(slice []string) map[string]bool {
}
return result
}
func ExtractModule(m string) string {
k := strings.Index(m, " => ")
if k < 0 {
return m
}
return m[:k]
}
func SliceContains(slice []string, target string) bool {
for _, x := range slice {
if x == target {
return true
}
}
return false
}

View File

@@ -71,7 +71,8 @@ func actualMain() error {
case arguments.UnPin:
return mgr.UnPin(args.DoIt(), targetModule, conditionalModule)
case arguments.Release:
return mgr.Release(targetModule, args.Bump(), args.DoIt())
return mgr.Release(
targetModule, args.Bump(), args.AllowedReplacements(), args.DoIt())
case arguments.UnRelease:
return mgr.UnRelease(targetModule, args.DoIt())
case arguments.Debug: