From c781baec2f1078931c77418de9da777518dfa3ec Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Mon, 2 Oct 2023 12:24:48 +0200 Subject: [PATCH] chore: bump schema version too when needed. Signed-off-by: Federico Di Pierro --- go.mod | 7 +++++-- go.sum | 2 ++ main.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 49d0786..2058320 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,13 @@ module github.com/falcosecurity/SyscallsBumper go 1.19 -require github.com/sirupsen/logrus v1.9.0 +require ( + github.com/blang/semver v3.5.1+incompatible + github.com/olekukonko/tablewriter v0.0.5 + github.com/sirupsen/logrus v1.9.0 +) require ( github.com/mattn/go-runewidth v0.0.9 // indirect - github.com/olekukonko/tablewriter v0.0.5 // indirect golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect ) diff --git a/go.sum b/go.sum index 390fb34..a442d84 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= +github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/main.go b/main.go index f6e6280..2b22d37 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bufio" "flag" + "github.com/blang/semver" "github.com/olekukonko/tablewriter" log "github.com/sirupsen/logrus" "io" @@ -136,9 +137,12 @@ func main() { log.Debugln("Finding union map for all supported archs") unionMap := UnionMaps(linuxMap) + needSchemaBump := false + log.Debugln("Diff unionMap->libs syscall maps") diffMap := unionMap.Diff(libsMap) if len(diffMap) > 0 { + needSchemaBump = true if !*dryRun { log.Infoln("Updating libs syscall table") updateLibsSyscallTable(diffMap) @@ -152,6 +156,7 @@ func main() { log.Debugln("Diff unionMap->ppm sc maps") diffMap = unionMap.Diff(ppmScMap) if len(diffMap) > 0 { + needSchemaBump = true if !*dryRun { log.Infoln("Updating libs PPM_SC enum") updateLibsPPMSc(diffMap) @@ -172,6 +177,18 @@ func main() { log.Infoln("Would have bumped compat tables", linuxMap) } + // Bump patch schema version + if !*dryRun { + if needSchemaBump { + log.Infoln("Bumping SCHEMA_VERSION patch") + bumpPatchSchemaVersion() + } else { + log.Infoln("SCHEMA_VERSION patch bump not needed") + } + } else { + log.Infoln("Would have bumped SCHEMA_VERSION patch") + } + // Generate xml report generateReport(unionMap) } @@ -481,6 +498,19 @@ func bumpCompats(systemMap map[string]SyscallMap) { } } +func bumpPatchSchemaVersion() { + updateLibsMap(*libsRepoRoot+"/driver/SCHEMA_VERSION", + func(lines *[]string, line string) bool { + v, err := semver.Parse(line) + if err != nil { + log.Fatal(err.Error()) + } + v.Patch++ + *lines = append(*lines, v.String()) + return true // Filter out this line + }) +} + func checkOverwriteRepoFile(fW *os.File, fp string) { if *overwrite { // Step 3: no error -> move temp file to real file