From 9407132b13812b4dd944545b8b18c47b9ddb5bc3 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Thu, 12 Dec 2024 09:43:02 -0300 Subject: [PATCH 1/2] chore: remove magefile Signed-off-by: Felipe Zipitria --- go.mod | 2 +- mage.go | 19 -------- magefile.go | 132 ---------------------------------------------------- 3 files changed, 1 insertion(+), 152 deletions(-) delete mode 100644 mage.go delete mode 100644 magefile.go diff --git a/go.mod b/go.mod index 8605c92..63c3df6 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( github.com/knadh/koanf/providers/rawbytes v0.1.0 github.com/knadh/koanf/v2 v2.1.2 github.com/kyokomi/emoji/v2 v2.2.13 - github.com/magefile/mage v1.15.1-0.20241126214340-bdc92f694516 github.com/rs/zerolog v1.33.0 github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.10.0 @@ -33,6 +32,7 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-multierror v1.1.0 // indirect + github.com/magefile/mage v1.15.1-0.20231118170541-2385abb49a1f // indirect github.com/valllabh/ocsf-schema-golang v1.0.3 // indirect google.golang.org/protobuf v1.34.2 // indirect ) diff --git a/mage.go b/mage.go deleted file mode 100644 index bbf0c4e..0000000 --- a/mage.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 OWASP Core Rule Set Project -// SPDX-License-Identifier: Apache-2.0 - -//go:build ignore -// +build ignore - -// Entrypoint to mage for running without needing to install the command. -// https://magefile.org/zeroinstall/ -package main - -import ( - "os" - - "github.com/magefile/mage/mage" -) - -func main() { - os.Exit(mage.Main()) -} diff --git a/magefile.go b/magefile.go deleted file mode 100644 index e6cd804..0000000 --- a/magefile.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2023 OWASP Core Rule Set Project -// SPDX-License-Identifier: Apache-2.0 - -//go:build mage -// +build mage - -package main - -import ( - "errors" - "fmt" - "io" - "os" - "path/filepath" - - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" -) - -var addLicenseVersion = "v1.1.1" // https://github.com/google/addlicense -var golangCILintVer = "v1.53.1" // https://github.com/golangci/golangci-lint/releases -var gosImportsVer = "v0.3.8" // https://github.com/rinchsan/gosimports/releases/tag/v0.1.5 -var goGciVer = "v0.10.1" // https://github.com/daixiang0/gci/releases/tag/v0.8.2 -var goCycloVer = "v0.6.0" // https://github.com/fzipp/gocyclo/releases/tag/v0.6.0 - -var errCommitFormatting = errors.New("files not formatted, please commit formatting changes") -var errNoGitDir = errors.New("no .git directory found") - -// Format formats code in this repository. -func Format() error { - if err := sh.RunV("go", "mod", "tidy"); err != nil { - return err - } - // addlicense strangely logs skipped files to stderr despite not being erroneous, so use the long sh.Exec form to - // discard stderr too. - if _, err := sh.Exec(map[string]string{}, io.Discard, io.Discard, "go", "run", fmt.Sprintf("github.com/google/addlicense@%s", addLicenseVersion), - "-c", "OWASP CRS Project", - "-s=only", - "-ignore", "**/*.yml", - "-ignore", "**/*.yaml", - "-ignore", "examples/**", "."); err != nil { - return err - } - if err := sh.RunV("go", "run", fmt.Sprintf("github.com/rinchsan/gosimports/cmd/gosimports@%s", gosImportsVer), - "-w", - "-local", - "github.com/coreruleset/go-ftw", - "."); err != nil { - return err - } - - return sh.RunV("go", "run", fmt.Sprintf("github.com/daixiang0/gci@%s", goGciVer), - "write", - "--section", - "standard", - "--section", - "default", - "--section", - "blank", - "--section", - "prefix(github.com/coreruleset/go-ftw)", - "--custom-order", - "--skip-generated", - ".") -} - -// Lint verifies code quality. -func Lint() error { - if err := sh.RunV("go", "run", fmt.Sprintf("github.com/golangci/golangci-lint/cmd/golangci-lint@%s", golangCILintVer), "run"); err != nil { - return err - } - - if err := sh.RunV("go", "run", fmt.Sprintf("github.com/fzipp/gocyclo/cmd/gocyclo@%s", goCycloVer), "-over", "15", "."); err != nil { - return err - } - - sh.Run("git", "stash", "-k", "-u") // stash unstagged changes so they don't interfere with git diff below - defer sh.Run("git", "stash", "pop") - - mg.SerialDeps(Format) - - if sh.Run("git", "diff", "--exit-code") != nil { - return errCommitFormatting - } - - return nil -} - -// Test runs all tests. -func Test() error { - if err := sh.RunV("go", "test", "-v", "./...", "-race"); err != nil { - return err - } - - return nil -} - -// Coverage runs tests with coverage and race detector enabled. -func Coverage() error { - if err := os.MkdirAll("build", 0755); err != nil { - return err - } - if err := sh.RunV("go", "test", "-v", "-race", "-coverprofile=build/coverage.txt", "-covermode=atomic", "-coverpkg=./...", "./..."); err != nil { - return err - } - - return sh.RunV("go", "tool", "cover", "-html=build/coverage.txt", "-o", "build/coverage.html") -} - -// Doc runs godoc, access at http://localhost:6060 -func Doc() error { - return sh.RunV("go", "run", "golang.org/x/tools/cmd/godoc@latest", "-http=:6060") -} - -// Precommit installs a git hook to run check when committing -func Precommit() error { - if _, err := os.Stat(filepath.Join(".git", "hooks")); os.IsNotExist(err) { - return errNoGitDir - } - - f, err := os.ReadFile(".pre-commit.hook") - if err != nil { - return err - } - - return os.WriteFile(filepath.Join(".git", "hooks", "pre-commit"), f, 0755) -} - -// Check runs lint and tests. -func Check() { - mg.SerialDeps(Lint, Test) -} From 8cd4dd655264905f01daa408d5774e4a4474ee97 Mon Sep 17 00:00:00 2001 From: Max Leske <250711+theseion@users.noreply.github.com> Date: Sat, 14 Dec 2024 10:00:15 +0100 Subject: [PATCH 2/2] chore: go mod tidy --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index a2f4bdf..0396c5d 100644 --- a/go.sum +++ b/go.sum @@ -106,8 +106,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kyokomi/emoji/v2 v2.2.13 h1:GhTfQa67venUUvmleTNFnb+bi7S3aocF7ZCXU9fSO7U= github.com/kyokomi/emoji/v2 v2.2.13/go.mod h1:JUcn42DTdsXJo1SWanHh4HKDEyPaR5CqkmoirZZP9qE= -github.com/magefile/mage v1.15.1-0.20241126214340-bdc92f694516 h1:aAO0L0ulox6m/CLRYvJff+jWXYYCKGpEm3os7dM/Z+M= -github.com/magefile/mage v1.15.1-0.20241126214340-bdc92f694516/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/magefile/mage v1.15.1-0.20231118170541-2385abb49a1f h1:iiLWLoibjCL0XND6inF7bs2nc20lU/FYkiR//VIOLUc= +github.com/magefile/mage v1.15.1-0.20231118170541-2385abb49a1f/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=