-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add CLI option to override package version (#10)
* feat: Allow providing version overrides to check action (#6) * feat: Add version override option to CLI (#6) * docs: Document --override CLI option in README (#6)
- Loading branch information
Showing
13 changed files
with
213 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package bumper | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"go.uber.org/config" | ||
) | ||
|
||
const overrideSeparator = "=" | ||
|
||
var ErrInvalidOverride = errors.New("invalid version override") | ||
|
||
func configFromVersionOverrides(versionOverrides []string) (config.YAMLOption, error) { | ||
overridesMap, err := parseVersionOverrides(versionOverrides) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var overrideValue interface{} | ||
if len(overridesMap) != 0 { | ||
overrideValue = overridesMap | ||
} else { | ||
overrideValue = nil | ||
} | ||
|
||
checkConfig := map[string]map[string]interface{}{ | ||
"check": {"versionOverrides": overrideValue}, | ||
} | ||
return config.Static(checkConfig), nil | ||
} | ||
|
||
func parseVersionOverrides(versionOverrides []string) (map[string]string, error) { | ||
overridesMap := map[string]string{} | ||
|
||
for _, overrideString := range versionOverrides { | ||
pkgname, override, separatorFound := strings.Cut(overrideString, overrideSeparator) | ||
if !separatorFound { | ||
return nil, fmt.Errorf("%w: '%s'", ErrInvalidOverride, overrideString) | ||
} | ||
overridesMap[pkgname] = override | ||
} | ||
|
||
return overridesMap, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package bumper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/config" | ||
) | ||
|
||
func TestConfigFromVersionOverrides_Success(t *testing.T) { | ||
overrideString := []string{"foopkg=1.2.3", "barpkg=6.6.6"} | ||
|
||
source, err := configFromVersionOverrides(overrideString) | ||
assert.Nil(t, err) | ||
|
||
actualConfig, err := config.NewYAML(source) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "1.2.3", actualConfig.Get("check.versionOverrides.foopkg").String()) | ||
assert.Equal(t, "6.6.6", actualConfig.Get("check.versionOverrides.barpkg").String()) | ||
} | ||
|
||
func TestConfigFromVersionOverrides_Fail(t *testing.T) { | ||
overrideString := []string{"invalidstring"} | ||
|
||
_, err := configFromVersionOverrides(overrideString) | ||
assert.ErrorIs(t, err, ErrInvalidOverride) | ||
assert.ErrorContains(t, err, "'invalidstring'") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.