From 72f8fca15589b4cee51f663e981815e7b4ac70b5 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 17 Aug 2022 13:28:01 +1000 Subject: [PATCH] cleanup CI --- .github/workflows/lint.yml | 19 +++++++++++++++++++ .github/workflows/test.yml | 22 ++++++---------------- .golintci.yaml | 32 ++++++++++++++++++++++++++++++++ csp_collector.go | 8 ++++---- csp_collector_test.go | 2 +- 5 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .golintci.yaml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3a03574 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,19 @@ +name: Lint +on: + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review +jobs: + golangci-lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: "--config .golintci.yaml" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index add8c9e..b291078 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,29 +1,19 @@ -on: [push, pull_request] +on: [pull_request] name: Test -env: - GOPROXY: "https://proxy.golang.org" + jobs: test: strategy: matrix: - go-version: [1.18, 1.19] + go-version: [1.17, 1.18, 1.19] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - - name: Install Go + - name: setup go uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - - name: Checkout code + - name: checkout code uses: actions/checkout@v3 - - name: Format - run: gofmt -d . - - name: Lint - if: matrix.os != 'windows-latest' - run: | - go get -v -u golang.org/x/lint/golint - $(go env GOPATH)/bin/golint -set_exit_status . - - name: Vet - run: go vet $(go list ./... | grep -v /vendor/) - - name: Test + - name: test run: go test -v -race ./... diff --git a/.golintci.yaml b/.golintci.yaml new file mode 100644 index 0000000..7117bd4 --- /dev/null +++ b/.golintci.yaml @@ -0,0 +1,32 @@ +run: + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 1m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: true + + # default is true. Enables skipping of directories: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true + + modules-download-mode: readonly + +linters: + enable: + - bodyclose # ensure HTTP response bodies are successfully closed. + - contextcheck # check we are passing context an inherited context. + - gofmt # checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification. + - errname # checks that sentinel errors are prefixed with the `Err`` and error types are suffixed with the `Error``. + - errorlint # used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - godot # check if comments end in a period. + - misspell # finds commonly misspelled English words in comments. + - nilerr # checks that there is no simultaneous return of nil error and an invalid value. + - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes. + - unparam # reports unused function parameters. + - whitespace # detection of leading and trailing whitespace. + +output: + format: colored-line-number diff --git a/csp_collector.go b/csp_collector.go index 16d6844..a9f4a25 100644 --- a/csp_collector.go +++ b/csp_collector.go @@ -54,10 +54,10 @@ var ( log.FieldKeyMsg: "message", } - // Path to file which has blocked URI's per line + // Path to file which has blocked URI's per line. blockedURIfile string - // Default URI Filter list + // Default URI Filter list. ignoredBlockedURIs = []string{ "resource://", "chromenull://", @@ -85,7 +85,7 @@ var ( "bdvideo://error", } - // TCP Port to listen on + // TCP Port to listen on. listenPort int ) @@ -219,7 +219,7 @@ func handleViolationReport(w http.ResponseWriter, r *http.Request) { func validateViolation(r CSPReport) error { for _, value := range ignoredBlockedURIs { - if strings.HasPrefix(r.Body.BlockedURI, value) == true { + if strings.HasPrefix(r.Body.BlockedURI, value) { err := fmt.Errorf("blocked URI ('%s') is an invalid resource", value) return err } diff --git a/csp_collector_test.go b/csp_collector_test.go index 4a0ffb9..81a420c 100644 --- a/csp_collector_test.go +++ b/csp_collector_test.go @@ -183,7 +183,7 @@ func TestValidateNonHttpDocumentURI(t *testing.T) { DocumentURI: "about", }} validateErr := validateViolation(report) - if validateErr.Error() != fmt.Sprintf("document URI ('about') is invalid") { + if validateErr.Error() != "document URI ('about') is invalid" { t.Errorf("expected error to include correct message string but it didn't") } }