diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 847fde250..fc53eb31e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. diff --git a/.github/workflows/go-ftw.yml b/.github/workflows/go-ftw.yml index 7bdd796fa..dd3ffbab7 100644 --- a/.github/workflows/go-ftw.yml +++ b/.github/workflows/go-ftw.yml @@ -15,15 +15,13 @@ jobs: os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: + - name: Checkout code + uses: actions/checkout@v3 - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - with: - lfs: true - fetch-depth: 0 #for better blame info + cache: true - name: Start httpbin run: docker run -p 8080:80 -d kennethreitz/httpbin - name: Setup CRS diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index db84ab267..090120d4f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,23 +1,16 @@ -name: lint (pre-commit) +name: lint on: pull_request: push: jobs: - pre-commit: + lint: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: v1.18.x - - name: Install dependencies - run: | - cd /tmp && go install github.com/go-critic/go-critic/cmd/gocritic@latest - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2 - go install golang.org/x/lint/golint@latest - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.3 - with: - extra_args: --all-files + cache: true + - run: go run mage.go lint diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 19ffb9de2..0b77a919b 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -20,19 +20,15 @@ jobs: os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: + - name: Checkout code + uses: actions/checkout@v3 - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - with: - lfs: true - fetch-depth: 0 #for better blame info - - name: Download vendored dependencies - run: go mod vendor + cache: true - name: Tests and coverage - run: go test -v -coverpkg=./... -coverprofile=coverage-waf.out ./... + run: go run mage.go coverage - name: SonarCloud Scan if: ${{ matrix.go-version == '1.17.x' && github.event.pull_request.head.repo.full_name == github.repository }} uses: sonarsource/sonarcloud-github-action@master diff --git a/.github/workflows/tinygo.yml b/.github/workflows/tinygo.yml deleted file mode 100644 index ef4244aeb..000000000 --- a/.github/workflows/tinygo.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Tinygo tests - -on: - push: - pull_request: -jobs: - test: - strategy: - matrix: - go-version: [1.18.x, 1.19.x] - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - with: - lfs: true - fetch-depth: 0 #for better blame info - - name: Download vendored dependencies - run: go mod vendor - - name: Tests and coverage - run: go test -v --tags=tinygo ./... \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 1c6861355..0a8d33e15 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,11 +11,10 @@ linters: - govet - ineffassign - staticcheck - - structcheck - typecheck - unused - varcheck # Enabled by coraza - goimports - gofmt - - gocritic + - gocritic \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index cfca657a3..000000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -repos: - - repo: https://github.com/dnephin/pre-commit-golang - rev: v0.4.0 - hooks: - - id: golangci-lint - - id: go-unit-tests - - id: go-mod-tidy diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 660577665..5ee1a9ed7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ Did you write a patch that fixes a bug? * Open a new GitHub pull request which includes your changes. * Please include a description which clearly describes the change. Include the relevant issue number if applicable. -* We use the [pre-commit](https://pre-commit.com/) framework to perform quality tests before sending them for review. It is recommended you [install](https://pre-commit.com/#install) it and use it before sending any patches. +* You may consider installing a pre-commit hook to automatically run required checks with `go run mage.go precommit` ## Enhancements @@ -63,12 +63,14 @@ Do you have questions about the source code? Ask any question about how to use C Coraza uses Go's built-in test tool. Examples (run from the repository root): -- `go test -v` +- `go test -v` or `go run mage.go test` - `go test -v -race ` use to enable the built-in data race detector - `go test -run TestDefaultWriters -v ./loggers` run all tests loggers package with name substring `TestDefaultWriters` -- `pre-commit run --all-files` run tests using pre-commit -- `pre-commit install` install the pre-commit git hook +- `go run mage.go lint` run code style checks +- `go run mage.go check` run tests and code style checks + +- `go run mage.go precommit` install the pre-commit git hook _________________