Skip to content

Commit

Permalink
chore: bump schema version too when needed.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed Oct 2, 2023
1 parent 7460e66 commit c781bae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
30 changes: 30 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"flag"
"github.com/blang/semver"
"github.com/olekukonko/tablewriter"
log "github.com/sirupsen/logrus"
"io"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c781bae

Please sign in to comment.