Skip to content

Commit

Permalink
build: use plugin event source as alternative commit scope for change…
Browse files Browse the repository at this point in the history
…log generation

Signed-off-by: Sverre Boschman <[email protected]>
  • Loading branch information
sboschman authored and poiana committed May 21, 2024
1 parent 4686bf8 commit a492a54
Show file tree
Hide file tree
Showing 3 changed files with 587 additions and 8 deletions.
28 changes: 22 additions & 6 deletions build/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"regexp"
"strings"

"github.com/falcosecurity/plugins/build/registry/pkg/registry"
"github.com/spf13/pflag"
)

Expand Down Expand Up @@ -83,6 +84,21 @@ func gitListCommits(from, to string) ([]string, error) {
return logs, nil
}

func pluginSource(pname string) string {
reg, err := registry.LoadRegistryFromFile("registry.yaml")
if err != nil {
fail(fmt.Errorf("an error occurred while loading registry entries from file %q: %v", "registry.yaml", err))
}

for _, plugin := range reg.Plugins {
if plugin.Name == pname && plugin.Capabilities.Sourcing.Supported {
return plugin.Capabilities.Sourcing.Source
}
}

return ""
}

func fail(err error) {
fmt.Printf("error: %s\n", err)
os.Exit(1)
Expand Down Expand Up @@ -130,16 +146,16 @@ func main() {
fail(err)
}

var rgx, rgxAlt, rgxDeps *regexp.Regexp
var rgx, rgxSource, rgxDeps *regexp.Regexp
if len(plugin) > 0 {
// craft a regex to filter all plugin-related commits that follow
// the conventional commit format
rgx, _ = regexp.Compile("^[a-f0-9]+ [a-zA-Z]+\\(([a-zA-Z\\/]+\\/)?" + plugin + "(\\/[a-zA-Z\\/]+)?\\):.*")

// alternative plugin name used as scope
if plugin == "k8saudit" {
pluginAlt := "k8s_audit"
rgxAlt, _ = regexp.Compile("^[a-f0-9]+ [a-zA-Z]+\\(([a-zA-Z\\/]+\\/)?" + pluginAlt + "(\\/[a-zA-Z\\/]+)?\\):.*")
// use source name of the plugin as well, if it has sourcing capabilities
pluginSource := pluginSource(plugin)
if pluginSource != "" {
rgxSource, _ = regexp.Compile("^[a-f0-9]+ [a-zA-Z]+\\(([a-zA-Z\\/]+\\/)?" + pluginSource + "(\\/[a-zA-Z\\/]+)?\\):.*")
}

// craft a regex to filter all plugin-related dependabot commits
Expand All @@ -148,7 +164,7 @@ func main() {

for _, c := range commits {
if len(c) > 0 && (rgx == nil || rgx.MatchString(c) ||
(rgxAlt != nil && rgxAlt.MatchString(c)) ||
(rgxSource != nil && rgxSource.MatchString(c)) ||
rgxDeps.MatchString(c)) {
fmt.Println(formatCommitLine(c) + "\n")
}
Expand Down
42 changes: 40 additions & 2 deletions build/changelog/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
module github.com/falcosecurity/plugins/build/changelog

go 1.17
go 1.21

require github.com/spf13/pflag v1.0.5
toolchain go1.22.2

require (
github.com/falcosecurity/plugins/build/registry v0.0.0-20240514080945-0e7ef7698747
github.com/spf13/pflag v1.0.5
)

require (
github.com/docker/cli v24.0.5+incompatible // indirect
github.com/docker/docker v24.0.9+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.0 // indirect
github.com/falcosecurity/falcoctl v0.6.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
oras.land/oras-go/v2 v2.2.1 // indirect
)
Loading

0 comments on commit a492a54

Please sign in to comment.