diff --git a/.github/workflows/go-build.yaml b/.github/workflows/go-build.yaml new file mode 100644 index 0000000..3ecc0cb --- /dev/null +++ b/.github/workflows/go-build.yaml @@ -0,0 +1,41 @@ +name: "Go: Build" +on: + workflow_call: {} + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + cache: false + go-version-file: go.mod + + + - id: go-cache-paths + run: | + echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT + echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + + mkdir -p "$(go env GOMODCACHE)" + mkdir -p "$(go env GOCACHE)" + + - name: Go Build Cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-gobuild-build-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-gobuild-build + + - name: Go Mod Cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-gomod-build-${{ hashFiles('**/go.sum') }} + + - run: | + go build -v . diff --git a/.github/workflows/go-lint.yaml b/.github/workflows/go-lint.yaml new file mode 100644 index 0000000..156acfd --- /dev/null +++ b/.github/workflows/go-lint.yaml @@ -0,0 +1,20 @@ +name: "Go: Lint" +on: + workflow_call: {} + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + cache: false + go-version-file: go.mod + + + - name: Run golangci-lint + id: golangci-lint + uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/go-test.yaml b/.github/workflows/go-test.yaml new file mode 100644 index 0000000..dde1697 --- /dev/null +++ b/.github/workflows/go-test.yaml @@ -0,0 +1,51 @@ +name: "Go: Test" +on: + workflow_call: {} + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + cache: false + go-version-file: go.mod + + + - name: Determine Go Cache Paths + id: go-cache-paths + run: | + echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT + echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + + mkdir -p "$(go env GOMODCACHE)" + mkdir -p "$(go env GOCACHE)" + + - name: Go Build Cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-gobuild-test-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-gobuild-test + + - name: Go Mod Cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-gomod-test-${{ hashFiles('**/go.sum') }} + + - run: | + go test -v \ + -coverprofile=coverage.txt \ + -covermode=atomic \ + -coverpkg=./... \ + ./... + + - name: Collect Code Coverage + uses: codecov/codecov-action@v2 + with: + file: ./coverage.txt diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml new file mode 100644 index 0000000..397376f --- /dev/null +++ b/.github/workflows/go.yaml @@ -0,0 +1,20 @@ +name: Go +on: + push: + branches: [main] + pull_request: + +jobs: + lint: + name: "Go: Lint" + uses: ./.github/workflows/go-lint.yaml + + build: + name: "Go: Build" + uses: ./.github/workflows/go-build.yaml + + test: + name: "Go: Test" + uses: ./.github/workflows/go-test.yaml + + secrets: inherit diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 4670b35..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,139 +0,0 @@ -name: Go -on: - push: - branches: [main] - pull_request: - -jobs: - - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - uses: actions/checkout@v2 - - - id: go-cache-paths - run: | - echo "::set-output name=go-build::$(go env GOCACHE)" - echo "::set-output name=go-mod::$(go env GOMODCACHE)" - - - name: Go Build Cache - uses: actions/cache@v2 - with: - path: ${{ steps.go-cache-paths.outputs.go-build }} - key: ${{ runner.os }}-go-build-lint-${{ hashFiles('.github/workflows/go.yml') }} - - - name: Go Mod Cache - uses: actions/cache@v2 - with: - path: ${{ steps.go-cache-paths.outputs.go-mod }} - key: ${{ runner.os }}-go-mod-lint-${{ hashFiles('.github/workflows/go.yml') }} - - - name: formatting - if: ${{ always() }} - run: | - go run golang.org/x/tools/cmd/goimports@v0.1.7 -w . - go run mvdan.cc/gofumpt@v0.2.1 -w . - [[ -z $(git status -s) ]] || (echo "::error::Formatting"; exit 1) - - - name: revive (run) - id: revive_lint - if: ${{ always() }} - shell: bash {0} # don't fail fast - run: | - FINDINGS=$(go run github.com/mgechev/revive@v1.1.2 -config ci/revive.toml --formatter json ./...) - code=$? - echo "::set-output name=findings::${FINDINGS}" - exit $code - - name: revive (report) - if: ${{ always() && fromJSON(steps.revive_lint.outputs.findings)[0] != null }} - run: | - echo "::group::Failures" - while read -r line; do - eval "$(echo ${line} | jq -r '@sh "severity=\(.Severity) failure=\(.Failure) file=\(.Position.Start.Filename) l=\(.Position.Start.Line) col=\(.Position.Start.Column)"')" - echo "::${severity} file=$file,line=$l,col=$col::${failure}" - done < <( - jq -c '.[]' <<-EOF - ${{ steps.revive_lint.outputs.findings }} - EOF - ) - echo "::endgroup::" - - - name: markdownlint - if: ${{ always() }} - uses: nosborn/github-action-markdown-cli@v2 - with: - files: . - - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - uses: actions/checkout@v2 - - - id: go-cache-paths - run: | - echo "::set-output name=go-build::$(go env GOCACHE)" - echo "::set-output name=go-mod::$(go env GOMODCACHE)" - - - name: Go Build Cache - uses: actions/cache@v2 - with: - path: ${{ steps.go-cache-paths.outputs.go-build }} - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - - - name: Go Mod Cache - uses: actions/cache@v2 - with: - path: ${{ steps.go-cache-paths.outputs.go-mod }} - key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} - - - run: | - go build -v . - - test: - name: Test - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - uses: actions/checkout@v2 - - - id: go-cache-paths - run: | - echo "::set-output name=go-build::$(go env GOCACHE)" - echo "::set-output name=go-mod::$(go env GOMODCACHE)" - - - name: Go Build Cache - uses: actions/cache@v2 - with: - path: ${{ steps.go-cache-paths.outputs.go-build }} - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - - - name: Go Mod Cache - uses: actions/cache@v2 - with: - path: ${{ steps.go-cache-paths.outputs.go-mod }} - key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} - - - run: | - go test -v \ - -coverprofile=coverage.txt \ - -covermode=atomic \ - -coverpkg=./... \ - ./... - - - name: collect code coverage - uses: codecov/codecov-action@v2 - with: - file: ./coverage.txt diff --git a/.github/workflows/markdown-lint.yaml b/.github/workflows/markdown-lint.yaml new file mode 100644 index 0000000..4dc6f8b --- /dev/null +++ b/.github/workflows/markdown-lint.yaml @@ -0,0 +1,14 @@ +name: "Markdown: Lint" +on: + workflow_call: {} + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: markdownlint + uses: nosborn/github-action-markdown-cli@v2 + with: + files: . diff --git a/.github/workflows/markdown.yaml b/.github/workflows/markdown.yaml new file mode 100644 index 0000000..8d9a87e --- /dev/null +++ b/.github/workflows/markdown.yaml @@ -0,0 +1,10 @@ +name: Markdown +on: + push: + branches: [main] + pull_request: + +jobs: + lint: + name: "Markdown: Lint" + uses: ./.github/workflows/markdown-lint.yaml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..fb91925 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,54 @@ +linters: + # Disable all default linters and enable only revive and formatters before + # new findings by default linters are addressed. + disable-all: true + enable: + - gofumpt + - goimports + - revive + +issues: + exclude-use-default: false + +linters-settings: + revive: + confidence: 0.8 + ignore-generated-header: false + severity: error + + rules: + - name: blank-imports + - name: confusing-naming + - name: confusing-results + - name: context-as-argument + - name: context-keys-type + - name: deep-exit + - name: dot-imports + - name: empty-block + - name: empty-lines + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + - name: get-return + - name: if-return + - name: import-shadowing + - name: increment-decrement + - name: indent-error-flow + - name: modifies-parameter + - name: modifies-value-receiver + - name: package-comments + - name: range + - name: receiver-naming + - name: redefines-builtin-id + - name: struct-tag + - name: superfluous-else + - name: time-naming + - name: unexported-return + - name: unnecessary-stmt + - name: unreachable-code + - name: unused-parameter + - name: unused-receiver + - name: var-declaration + - name: var-naming