Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .custom-gcl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v2.5.0
name: custom-golangci-lint
plugins:
# partitiontest plugin from local source
- module: 'github.com/algorand/go-algorand/cmd/partitiontest_linter'
path: ./cmd/partitiontest_linter
96 changes: 24 additions & 72 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "ReviewDog workflow"
env:
GOLANGCI_LINT_VERSION: "v1.64.8"
GOLANGCI_LINT_VERSION: "v2.5.0"
on:
push:
branches:
Expand All @@ -23,52 +23,17 @@ jobs:
# move go out of the way temporarily to avoid "go list ./..." from installing modules
- name: Make libsodium.a
run: sudo mv /usr/bin/go /usr/bin/go.bak && make libsodium && sudo mv /usr/bin/go.bak /usr/bin/go
- name: Add bin to PATH
run: |
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" >> $GITHUB_PATH
- name: Set up Go
uses: ./.github/actions/setup-go
- name: Create folders for golangci-lint
run: mkdir -p cicdtmp/golangci-lint
- name: Check if custom golangci-lint is already built
id: cache-golangci-lint
uses: actions/cache@v4
- name: reviewdog-golangci-lint
uses: reviewdog/action-golangci-lint@v2.8.0
with:
path: cicdtmp/golangci-lint/golangci-lint-cgo
key: cicd-golangci-lint-cgo-v0.0.3-${{ env.GO_VERSION }}-${{ env.GOLANGCI_LINT_VERSION }}

- name: Build custom golangci-lint with CGO_ENABLED
if: steps.cache-golangci-lint.outputs.cache-hit != 'true'
run: |
cd cicdtmp/golangci-lint
git clone https://github.com/golangci/golangci-lint.git .
git checkout tags/${GOLANGCI_LINT_VERSION}
CGO_ENABLED=true go build -trimpath -o golangci-lint-cgo ./cmd/golangci-lint
./golangci-lint-cgo --version
cd ../../
- name: Install reviewdog
run: |
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/v0.20.3/install.sh | sh -s -- v0.20.3
reviewdog --version
- name: Run golangci-lint with reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e

./cicdtmp/golangci-lint/golangci-lint-cgo run \
--out-format line-number \
-c .golangci.yml \
--allow-parallel-runners > temp_golangci-lint-errors.txt

cat temp_golangci-lint-errors.txt | reviewdog \
-f=golangci-lint \
-name="Lint Errors" \
-reporter=github-pr-check \
-filter-mode=nofilter \
-fail-level=any \
-level=error
go_version_file: go.mod
golangci_lint_version: ${{ env.GOLANGCI_LINT_VERSION }}
golangci_lint_flags: "-c .golangci.yml --allow-parallel-runners"
reporter: "github-pr-check"
tool_name: "Lint Errors"
level: "error"
fail_level: any
filter_mode: "nofilter"
# Non-Blocking Warnings Section
reviewdog-warnings:
runs-on: ubuntu-latest
Expand All @@ -91,47 +56,34 @@ jobs:
echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" >> $GITHUB_PATH
- name: Set up Go
uses: ./.github/actions/setup-go
- name: Create folders for golangci-lint
run: mkdir -p cicdtmp/golangci-lint
- name: Check if custom golangci-lint is already built
id: cache-golangci-lint
- name: Check if custom golangci-lint with partitiontest plugin is already built
id: cache-custom-golangci-lint
uses: actions/cache@v4
with:
path: cicdtmp/golangci-lint/golangci-lint-cgo
key: cicd-golangci-lint-cgo-v0.0.3-${{ env.GO_VERSION }}-${{ env.GOLANGCI_LINT_VERSION }}

- name: Build custom golangci-lint with CGO_ENABLED
if: steps.cache-golangci-lint.outputs.cache-hit != 'true'
path: custom-golangci-lint
key: custom-golangci-lint-${{ env.GO_VERSION }}-${{ env.GOLANGCI_LINT_VERSION }}-${{ hashFiles('cmd/partitiontest_linter/**', '.custom-gcl.yml') }}
- name: Build custom golangci-lint with partitiontest plugin
if: steps.cache-custom-golangci-lint.outputs.cache-hit != 'true'
run: |
cd cicdtmp/golangci-lint
git clone https://github.com/golangci/golangci-lint.git .
git checkout tags/${GOLANGCI_LINT_VERSION}
CGO_ENABLED=true go build -trimpath -o golangci-lint-cgo ./cmd/golangci-lint
./golangci-lint-cgo --version
cd ../../
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${{ env.GOLANGCI_LINT_VERSION }} custom -v
./custom-golangci-lint --version
- name: Install reviewdog
run: |
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/v0.20.3/install.sh | sh -s -- v0.20.3
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/v0.21.0/install.sh | sh -s -- v0.21.0
reviewdog --version
- name: Build custom linters
run: |
cd cmd/partitiontest_linter/
CGO_ENABLED=true go build -buildmode=plugin -trimpath plugin/plugin.go
cd ../../
ls -la cmd/partitiontest_linter/
- name: Run golangci-lint with reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e

./cicdtmp/golangci-lint/golangci-lint-cgo run \
--out-format line-number \
./custom-golangci-lint run \
--output.text.path stdout \
-c .golangci-warnings.yml \
--issues-exit-code 0 \
--allow-parallel-runners > temp_golangci-lint-cgo.txt
--allow-parallel-runners > temp_golangci-lint-warnings.txt

cat temp_golangci-lint-cgo.txt | reviewdog \
cat temp_golangci-lint-warnings.txt | reviewdog \
-f=golangci-lint \
-name="Lint Warnings" \
-reporter=github-pr-check \
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ cmd/algod/algod
cmd/goal/goal
cmd/updater/updater

# custom golangci-lint binary with plugins
custom-golangci-lint

# Exclude our local temp directory
tmp/

Expand Down
79 changes: 24 additions & 55 deletions .golangci-warnings.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,35 @@
version: "2"
run:
timeout: 5m
tests: true

linters:
disable-all: true
default: none
enable:
- gosec
- partitiontest

linters-settings:
gosec: # Go 1.22 makes G601 irrelevant
excludes: [G101, G103, G104, G107, G115, G202, G301, G302, G303, G304, G306, G307, G404, G601]
custom:
partitiontest:
path: cmd/partitiontest_linter/plugin.so
description: This custom linter checks files that end in '_test.go', specifically functions that start with 'Test' and have testing argument, for a line 'partitiontest.ParitionTest(<testing arg>)'
original-url: github.com/algorand/go-algorand/cmd/partitiontest_linter

severity:
default-severity: warning

settings:
gosec:
excludes: [G101, G103, G104, G107, G112, G114, G115, G202, G204, G301, G302, G303, G304, G306, G307, G404]
custom:
partitiontest:
type: "module"
description: This custom linter ensures test functions call 'partitiontest.PartitionTest(t)'
exclusions:
generated: lax
rules:
# be more lenient with test code
- linters:
- gosec
path: _test\.go
- linters:
- partitiontest
path: crypto/secp256k1/secp256_test\.go
issues:
# use these new lint checks on code since #2574
new-from-rev: eb019291beed556ec6ac1ceb4a15114ce4df0c57

# Disable default exclude rules listed in `golangci-lint run --help` (selectively re-enable some below)
exclude-use-default: false

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

exclude:
# ignore govet false positive fixed in https://github.com/golang/go/issues/45043
- "sigchanyzer: misuse of unbuffered os.Signal channel as argument to signal.Notify"
# ignore issues about the way we use _struct fields to define encoding settings
- "`_struct` is unused"

# Enable some golangci-lint default exception rules:
# "EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok"
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# "EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore"
- ineffective break statement. Did you mean to break out of the outer loop

exclude-rules:
# be more lenient with test code
- path: _test\.go
linters:
- deadcode
- gosec
- structcheck
- varcheck
- unused
# Add all linters here -- Comment this block out for testing linters
- path: test/linttest/lintissues\.go
linters:
- deadcode
- structcheck
- varcheck
- unused
- path: crypto/secp256k1/secp256_test\.go
linters:
- partitiontest
severity:
default: warning
formatters:
exclusions:
generated: lax
Loading
Loading