-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add magefile for running development commands (#315)
* Add magefile for running development commands * Add doc command * No package
- Loading branch information
Showing
7 changed files
with
140 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.o | ||
*.dylib | ||
.DS_Store | ||
.idea | ||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
test/crs | ||
/main | ||
vendor/ | ||
coraza-waf | ||
__debug_bin | ||
seclang/crs_test.go | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.o | ||
*.dylib | ||
.DS_Store | ||
.idea | ||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
test/crs | ||
/main | ||
vendor/ | ||
coraza-waf | ||
__debug_bin | ||
seclang/crs_test.go | ||
|
||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,8 @@ linters: | |
- goimports | ||
- gofmt | ||
- gocritic | ||
issues: | ||
exclude-rules: | ||
- path: magefile\.go | ||
linters: | ||
- deadcode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//go:build mage | ||
// +build mage | ||
|
||
// Copyright 2022 Juan Pablo Tosso | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/magefile/mage/mg" | ||
"github.com/magefile/mage/sh" | ||
) | ||
|
||
var golangCILintVer = "v1.48.0" // https://github.com/golangci/golangci-lint/releases | ||
var gosImportsVer = "v0.1.5" // https://github.com/rinchsan/gosimports/releases/tag/v0.1.5 | ||
|
||
var errCommitFormatting = errors.New("files not formatted, please commit formatting changes") | ||
|
||
// Format formats code in this repository. | ||
func Format() error { | ||
if err := sh.RunV("go", "mod", "tidy"); err != nil { | ||
return err | ||
} | ||
return sh.RunV("go", "run", fmt.Sprintf("github.com/rinchsan/gosimports/cmd/gosimports@%s", gosImportsVer), "-w", ".") | ||
} | ||
|
||
// Lint verifies code quality. | ||
func Lint() error { | ||
mg.SerialDeps(Format) | ||
|
||
if sh.Run("git", "diff", "--exit-code") != nil { | ||
return errCommitFormatting | ||
} | ||
|
||
return sh.RunV("go", "run", fmt.Sprintf("github.com/golangci/golangci-lint/cmd/golangci-lint@%s", golangCILintVer), "run") | ||
} | ||
|
||
// Test runs all tests. | ||
func Test() error { | ||
return sh.RunV("go", "test", "./...") | ||
} | ||
|
||
// 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", "-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") | ||
} | ||
|
||
// Check runs tests and lint. | ||
func Check() { | ||
mg.SerialDeps(Test, Lint) | ||
} |