feat: support cooldown for Golang module by olblak · Pull Request #8966 · updatecli/updatecli · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions pkg/plugins/autodiscovery/golang/dependency.go
55 changes: 28 additions & 27 deletions pkg/plugins/autodiscovery/golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/go-viper/mapstructure/v2"
"github.com/sirupsen/logrus"
"github.com/updatecli/updatecli/pkg/plugins/utils/age"
"github.com/updatecli/updatecli/pkg/plugins/utils/version"
)

Expand All @@ -20,35 +21,35 @@ type Spec struct {
OnlyGoModule *bool `yaml:",omitempty"`
// ignore allows to specify "rule" to ignore autodiscovery a specific go.mod rule
Ignore MatchingRules `yaml:",omitempty"`
/*
`only` allows to specify rule to "only" autodiscover manifest for a specific golang rule
*/
// `only` allows to specify rule to "only" autodiscover manifest for a specific golang rule
Only MatchingRules `yaml:",omitempty"`
/*
`versionfilter` provides parameters to specify the version pattern to use when generating manifest.

kind - semver
versionfilter of kind `semver` uses semantic versioning as version filtering
pattern accepts one of:
`patch` - patch only update patch version
`minor` - minor only update minor version
`major` - major only update major versions
`a version constraint` such as `>= 1.0.0`

kind - regex
versionfilter of kind `regex` uses regular expression as version filtering
pattern accepts a valid regular expression

example:
```
versionfilter:
kind: semver
pattern: minor
```

and its type like regex, semver, or just latest.
*/
// `versionfilter` provides parameters to specify the version pattern to use when generating manifest.
//
// kind - semver
// versionfilter of kind `semver` uses semantic versioning as version filtering
// pattern accepts one of:
// `patch` - patch only update patch version
// `minor` - minor only update minor version
// `major` - major only update major versions
// `a version constraint` such as `>= 1.0.0`
//
// kind - regex
// versionfilter of kind `regex` uses regular expression as version filtering
// pattern accepts a valid regular expression
//
// example:
// ```
// versionfilter:
// kind: semver
// pattern: minor
// ```
//
// and its type like regex, semver, or just latest.
//
VersionFilter version.Filter `yaml:",omitempty"`
// Age defines the minimum or maximum age of a release to be considered valid.
// It accepts a duration string (e.g., "24h", "7d", "1w").
Age age.Spec `yaml:",omitempty"`
}

// Golang holds all information needed to generate golang manifest.
Expand Down
102 changes: 101 additions & 1 deletion pkg/plugins/autodiscovery/golang/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,115 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/updatecli/updatecli/pkg/plugins/utils/age"
)

func TestDiscoverManifests(t *testing.T) {

testdata := []struct {
name string
rootDir string
spec Spec
expectedPipelines []string
}{
{
name: "Maximum one year old Golang Version",
rootDir: "testdata/noSumFile",
spec: Spec{
Age: age.Spec{
Maximum: "1y",
},
},
expectedPipelines: []string{`name: 'deps(go): bump module gopkg.in/yaml.v3'
sources:
module:
name: 'Get latest golang module gopkg.in/yaml.v3 version'
kind: 'golang/module'
spec:
age:
maximum: '1y'
module: 'gopkg.in/yaml.v3'
versionfilter:
kind: 'semver'
pattern: '>=3.0.1'
targets:
module:
name: 'deps(go): bump module gopkg.in/yaml.v3 to {{ source "module" }}'
kind: 'golang/gomod'
sourceid: 'module'
spec:
file: 'go.mod'
module: 'gopkg.in/yaml.v3'
`, `name: 'deps(golang): bump Go version'
sources:
go:
name: 'Get latest Go version'
kind: 'golang'
spec:
age:
maximum: '1y'
versionfilter:
kind: 'semver'
pattern: '>=1.20.0'
targets:
go:
name: 'deps(golang): bump Go version to {{ source "go" }}'
kind: 'golang/gomod'
sourceid: 'go'
spec:
file: 'go.mod'
`,
},
},
{
name: "Minimum one year old Golang Version",
rootDir: "testdata/noSumFile",
spec: Spec{
Age: age.Spec{
Minimum: "1y",
},
},
expectedPipelines: []string{`name: 'deps(go): bump module gopkg.in/yaml.v3'
sources:
module:
name: 'Get latest golang module gopkg.in/yaml.v3 version'
kind: 'golang/module'
spec:
age:
minimum: '1y'
module: 'gopkg.in/yaml.v3'
versionfilter:
kind: 'semver'
pattern: '>=3.0.1'
targets:
module:
name: 'deps(go): bump module gopkg.in/yaml.v3 to {{ source "module" }}'
kind: 'golang/gomod'
sourceid: 'module'
spec:
file: 'go.mod'
module: 'gopkg.in/yaml.v3'
`, `name: 'deps(golang): bump Go version'
sources:
go:
name: 'Get latest Go version'
kind: 'golang'
spec:
age:
minimum: '1y'
versionfilter:
kind: 'semver'
pattern: '>=1.20.0'
targets:
go:
name: 'deps(golang): bump Go version to {{ source "go" }}'
kind: 'golang/gomod'
sourceid: 'go'
spec:
file: 'go.mod'
`,
},
},
{
name: "Test with pseudo version",
rootDir: "testdata/pseudoVersion",
Expand Down Expand Up @@ -278,7 +378,7 @@ targets:
for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) {
resource, err := New(
Spec{}, tt.rootDir, "", "")
tt.spec, tt.rootDir, "", "")
require.NoError(t, err)

var pipelines []string
Expand Down
27 changes: 27 additions & 0 deletions pkg/plugins/autodiscovery/golang/manifestTemplate.go
Loading
Loading