-
Notifications
You must be signed in to change notification settings - Fork 0
ci: add golangci-lint and coverage gate #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,25 +2,72 @@ name: CI | |
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| branches: [main] | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ci-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| COVER_MIN: "65" | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Go lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: true | ||
|
|
||
| - name: golangci-lint | ||
| uses: golangci/golangci-lint-action@v8 | ||
| with: | ||
| version: latest | ||
| only-new-issues: true | ||
| args: --timeout=5m | ||
|
|
||
| test: | ||
| name: Go tests + coverage | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.26' | ||
| go-version-file: go.mod | ||
| cache: true | ||
|
|
||
| - name: Run tests with coverage | ||
| env: | ||
| GOWORK: off | ||
| run: go test $(go list ./pkg/pluginsdk/... | grep -v '/runtimedefault$') -count=1 -covermode=atomic -coverprofile=coverage.out | ||
|
Comment on lines
+54
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== ci.yml relevant section ==\n'
nl -ba .github/workflows/ci.yml | sed -n '1,140p'
printf '\n== search for coverage/protobuf filtering ==\n'
rg -n --hidden -S "coverage\.raw|coverage\.out|pb\.go|runtimedefault|coverprofile|go test .*cover" .github/workflows . || trueRepository: Prairie-Server/prairie-plugin-sdk Length of output: 242 🌐 Web query:
💡 Result: In GitHub Actions, the shell used for run steps depends on whether you explicitly specify a shell and whether the runner is on a Linux/macOS or Windows platform [1]. The default behavior on Linux and macOS is as follows: 1. Unspecified shell: If no shell is specified for a run step on a Linux or macOS runner, GitHub Actions uses a default command equivalent to Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== ci.yml section ==\n'
sed -n '45,70p' .github/workflows/ci.yml
printf '\n== search for coverage/protobuf filtering ==\n'
grep -RIn --exclude-dir=.git -E 'coverage\.raw|coverage\.out|pb\.go|runtimedefault|coverprofile|go test .*cover' .github/workflows .Repository: Prairie-Server/prairie-plugin-sdk Length of output: 3461 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== ci.yml section ==\n'
sed -n '45,70p' .github/workflows/ci.yml
printf '\n== coverage/protobuf references under repository ==\n'
grep -RIn --exclude-dir=.git -E 'coverage\.raw|coverage\.out|pb\.go|runtimedefault|coverprofile|go test .*cover' .Repository: Prairie-Server/prairie-plugin-sdk Length of output: 3166 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== scripts/check-coverage.sh ==\n'
sed -n '1,160p' scripts/check-coverage.sh
printf '\n== coverage/raw post-processing references ==\n'
grep -RIn --exclude-dir=.git -E 'coverage\.raw|awk .*pb\.go|sed .*pb\.go|filter.*pb\.go' scripts .github/workflows || trueRepository: Prairie-Server/prairie-plugin-sdk Length of output: 919 Keep coverage generation fail-closed and drop generated protobufs. The current step still writes 🤖 Prompt for AI Agents |
||
|
|
||
| - name: Run tests | ||
| run: go test ./... | ||
| - name: Enforce coverage floor | ||
| run: ./scripts/check-coverage.sh coverage.out | ||
|
|
||
| - name: Build example plugin | ||
| run: go build ./examples/hello-scheduled-task | ||
| - name: Build examples | ||
| run: | | ||
| go build ./examples/hello-scheduled-task | ||
| go build ./examples/hello-runtime-host | ||
|
|
||
| - name: Build hello-runtime-host example | ||
| run: go build ./examples/hello-runtime-host | ||
| - name: Upload coverage profile | ||
| if: always() | ||
| uses: actions/upload-artifact@v5 | ||
| with: | ||
| name: coverage-out | ||
| path: coverage.out | ||
| if-no-files-found: ignore | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| version: "2" | ||
|
|
||
| run: | ||
| timeout: 5m | ||
|
|
||
| formatters: | ||
| enable: | ||
| - gofmt | ||
| - goimports | ||
|
|
||
| settings: | ||
| goimports: | ||
| local-prefixes: | ||
| - github.com/prairie-server/prairie-plugin-sdk | ||
|
|
||
| linters: | ||
| enable: | ||
| - errcheck | ||
| - govet | ||
| - ineffassign | ||
| - misspell | ||
| - staticcheck | ||
| - unused | ||
|
|
||
| exclusions: | ||
| rules: | ||
| - path: _test\.go | ||
| linters: | ||
| - errcheck |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||
| # Fail if total statement coverage is below COVER_MIN (percent). | ||||||||||||||
| set -euo pipefail | ||||||||||||||
| COVER_MIN="${COVER_MIN:-70}" | ||||||||||||||
|
Comment on lines
+2
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Align the fallback with the documented 65% floor. CI sets Proposed fix-COVER_MIN="${COVER_MIN:-70}"
+COVER_MIN="${COVER_MIN:-65}"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| PROFILE="${1:-coverage.out}" | ||||||||||||||
| if [[ ! -f "$PROFILE" ]]; then | ||||||||||||||
| echo "coverage profile missing: $PROFILE" >&2 | ||||||||||||||
| exit 1 | ||||||||||||||
| fi | ||||||||||||||
| total="$(go tool cover -func="$PROFILE" | awk '/^total:/{gsub(/%/,"",$3); print $3}')" | ||||||||||||||
| if [[ -z "$total" ]]; then | ||||||||||||||
| echo "could not parse total coverage from $PROFILE" >&2 | ||||||||||||||
| exit 1 | ||||||||||||||
| fi | ||||||||||||||
| awk -v total="$total" -v min="$COVER_MIN" 'BEGIN { | ||||||||||||||
| if (total+0 < min+0) { | ||||||||||||||
| printf "coverage %.1f%% is below required %.1f%%\n", total, min > "/dev/stderr" | ||||||||||||||
| exit 1 | ||||||||||||||
| } | ||||||||||||||
| printf "coverage %.1f%% (min %.1f%%)\n", total, min | ||||||||||||||
|
Comment on lines
+15
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
awk -v min='abc' 'BEGIN { print min+0 < 65+0 ? "fail" : "pass" }'Repository: Prairie-Server/prairie-plugin-sdk Length of output: 176 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
wc -l scripts/check-coverage.sh
cat -n scripts/check-coverage.sh | sed -n '1,80p'Repository: Prairie-Server/prairie-plugin-sdk Length of output: 1015 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
wc -l scripts/check-coverage.sh
cat -n scripts/check-coverage.sh | sed -n '1,120p'Repository: Prairie-Server/prairie-plugin-sdk Length of output: 1015 🏁 Script executed: python3 - <<'PY'
import subprocess, textwrap
cases = [
("80", "abc"),
("80", "-5"),
("80", "70"),
("50", "70"),
]
for total, minv in cases:
script = textwrap.dedent(f"""\
awk -v total='{total}' -v min='{minv}' 'BEGIN {{
if (total+0 < min+0) {{
print "reject"
}} else {{
print "accept"
}}
}}'
""")
out = subprocess.check_output(["bash", "-lc", script], text=True).strip()
print(total, minv, "=>", out)
PYRepository: Prairie-Server/prairie-plugin-sdk Length of output: 236 Reject malformed 🤖 Prompt for AI Agents |
||||||||||||||
| }' | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Prairie-Server/prairie-plugin-sdk
Length of output: 262
🏁 Script executed:
Repository: Prairie-Server/prairie-plugin-sdk
Length of output: 261
🌐 Web query:
golangci-lint-action only-new-issues pull-requests permission GitHub Actions💡 Result:
When using the only-new-issues option in the golangci-lint-action, you should grant read access to pull requests in your GitHub Actions workflow permissions [1][2]. Specifically, the action requires the pull-requests: read permission to fetch the necessary diff information from the GitHub API [1][3]. The recommended configuration in your workflow file is as follows [1][2]: permissions: contents: read # Optional: allow read access to pull requests. Use with only-new-issues option. pull-requests: read The action uses this permission to retrieve the diff of the pull request content (or push content) via the GitHub API, which it then processes using the --new-from-patch option to report only newly introduced issues [1][2]. If you do not provide this permission, the action may fail to correctly identify or filter for only the new issues [1].
Citations:
🏁 Script executed:
Repository: Prairie-Server/prairie-plugin-sdk
Length of output: 2656
Add
pull-requests: readforonly-new-issues.contents: readleaves PR access atnone, and this mode needs the pull request API on PR runs or linting can fail before it starts.Proposed fix
permissions: contents: read + pull-requests: read📝 Committable suggestion
🤖 Prompt for AI Agents