Skip to content

Commit

Permalink
Base 0 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
raghu0891 committed Nov 26, 2024
0 parents commit 5404290
Show file tree
Hide file tree
Showing 250 changed files with 33,230 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e
set -o pipefail
set -u

# This script should be saved in a git repo as a hook file, e.g. .git/hooks/pre-push.
# It looks for scripts in the .git/hooks/pre-push.d directory and executes them in order,
# passing along stdin. If any script exits with a non-zero status, this script exits.

script_dir=$(dirname "$0")
hook_name=$(basename "$0")

hooks_dir="$script_dir/$hook_name.d"

if [ -d "$hooks_dir" ]; then
stdin=$(cat /dev/stdin)

for hook in "$hooks_dir"/*; do
# echo "Running hook $hook_name/$hook"
printf '%s' "$stdin" | $hook "$@"

exit_code=$?

if [ $exit_code != 0 ]; then
exit $exit_code
fi
done
fi

exit 0
3 changes: 3 additions & 0 deletions .githooks/pre-push.d/100-test-coverage.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

make coverage
175 changes: 175 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: Go Build and Test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main", "develop" ]

jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"

- name: golangci-lint
uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5.1.0
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.58.1
# only-new-issues is only applicable to PRs, otherwise it is always set to false
only-new-issues: true
args: --out-format colored-line-number,checkstyle:golangci-lint-report.xml

- name: Print golangci lint report
if: always()
run: test -f golangci-lint-report.xml && cat golangci-lint-report.xml || true

- name: Upload golangci lint report artifact
if: always()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: golangci-lint-report
path: golangci-lint-report.xml

unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"

- name: Run Unit Tests
run: go test ./... -coverpkg=./... -coverprofile=coverage.txt

- name: Upload Go test results
if: always()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: go-test-results
path: ./coverage.txt

- name: Quality Gate - V3 test coverage above threshold
env:
TESTCOVERAGE_THRESHOLD: 70
run: |
go test github.com/goplugin/plugin-automation/pkg/v3/... -coverprofile coverV3.out -covermode count
echo "Quality Gate: checking V3 test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=coverV3.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "V3 test coverage OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi
simulation:
strategy:
fail-fast: false
matrix:
plan: ["simplan_fast_check", "only_log_trigger"]

name: Upkeep Simulation ${{ matrix.plan }}

runs-on: ubuntu-latest
# runs-on: ubuntu20.04-64cores-256GB <-- run on specific machine with more resources
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Set up go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"

- name: Run Simulation Plan
run: make simulator && ./bin/simulator --simulate --verbose -f ./tools/simulator/plans/${{ matrix.plan }}.json -o ./${{ matrix.plan }}

- name: Archive Simulation Output
run: tar -czvf ${{ matrix.plan }}.tar.gz ./${{ matrix.plan }}

- name: Store Simulation Artifacts
if: always()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: ${{ matrix.plan }}_logs
path: |
./${{ matrix.plan }}.tar.gz
race-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"

- name: Run Race Tests
run: go test -race ./... -coverpkg=./... -coverprofile=race_coverage.txt

- name: Upload Go race test results
if: always()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: go-race-test-results
path: ./race_coverage.txt

fuzz-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"

- name: Run Keepers Package v2 Fuzz Tests
run: go test --fuzz=Fuzz --fuzztime=10s -run=^# github.com/goplugin/plugin-automation/pkg/v2

- name: Run Keepers Package v3 Fuzz Tests
run: go test --fuzz=Fuzz --fuzztime=10s -run=^# github.com/goplugin/plugin-automation/pkg/v3

sonar-scan:
name: SonarQube
needs: [lint, unit-test, race-test, simulation]
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout the repo
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0 # fetches all history for all tags and branches to provide more metadata for sonar reports

- name: Download all workflow run artifacts
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7

- name: Set SonarQube Report Paths
id: sonarqube_report_paths
shell: bash
run: |
echo "sonarqube_coverage_report_paths=$(find -type f -name '*coverage.txt' -printf "%p,")" >> $GITHUB_OUTPUT
echo "sonarqube_golangci_report_paths=$(find -type f -name 'golangci-lint-report.xml' -printf "%p,")" >> $GITHUB_OUTPUT
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@53c3e3207fe4b8d52e2f1ac9d6eb1d2506f626c0 # v2.0.2
with:
args: >
-Dsonar.go.coverage.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }}
-Dsonar.go.golangci-lint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_golangci_report_paths }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
22 changes: 22 additions & 0 deletions .github/workflows/scheduled-dependency-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Weekly Dependency Check

on:
schedule:
- cron: '0 0 */7 * *'

jobs:
dependency-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"

- name: Write Go Dep list
run: go list -json -m all > go.list

- name: Nancy Scan
uses: sonatype-nexus-community/nancy-github-action@726e338312e68ecdd4b4195765f174d3b3ce1533 # v1.0.3
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Output of any log files generated while testing
*.log

# Dependency directories (remove the comment below to include it)
# vendor/

# OS specific
.DS_Store

# Editor specific
.vscode
.idea/

# executable output folder
bin/

# default simulation output folders
reports/
simulation_plan_logs/
simulation_plans/

# Linter output
golangci-lint/
121 changes: 121 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
run:
timeout: 10m0s
linters:
enable:
- exhaustive
- exportloopref
- revive
- goimports
- gosec
- misspell
- rowserrcheck
- errorlint
- unconvert
- sqlclosecheck
- noctx
- whitespace
- depguard
- containedctx
linters-settings:
exhaustive:
default-signifies-exhaustive: true
goimports:
local-prefixes: github.com/goplugin/pluginv3.0
golint:
min-confidence: 1.0
gosec:
excludes:
- G101
- G104
# - G204
# - G304
# - G404
govet:
# report about shadowed variables
check-shadowing: true
errorlint:
# Allow formatting of errors without %w
errorf: false
revive:
confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
# - name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
# - name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
- name: waitgroup-by-value
- name: unconditional-recursion
- name: struct-tag
# - name: string-format
- name: string-of-int
# - name: range-val-address
- name: range-val-in-closure
- name: modifies-value-receiver
- name: modifies-parameter
- name: identical-branches
- name: get-return
# - name: flag-parameter
- name: early-return
- name: defer
- name: constant-logical-expr
# - name: confusing-naming
# - name: confusing-results
- name: bool-literal-in-expr
- name: atomic
depguard:
rules:
main:
list-mode: lax
deny:
- pkg: "cosmossdk.io/errors"
desc: Use the standard library instead
- pkg: "github.com/ethereum/go-ethereum"
desc: This is a chain-agnostic repo
- pkg: "github.com/go-gorm/gorm"
desc: Use github.com/jmoiron/sqlx directly instead
- pkg: "github.com/gofrs/uuid"
desc: Use github.com/google/uuid instead
- pkg: "github.com/pkg/errors"
desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join
- pkg: "github.com/satori/go.uuid"
desc: Use github.com/google/uuid instead
- pkg: "github.com/test-go/testify/assert"
desc: Use github.com/stretchr/testify/assert instead
- pkg: "github.com/test-go/testify/mock"
desc: Use github.com/stretchr/testify/mock instead
- pkg: "github.com/test-go/testify/require"
desc: Use github.com/stretchr/testify/require instead
- pkg: "go.uber.org/multierr"
desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join
- pkg: "gopkg.in/guregu/null.v1"
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: "gopkg.in/guregu/null.v2"
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: "gopkg.in/guregu/null.v3"
desc: Use gopkg.in/guregu/null.v4 instead
issues:
exclude-rules:
- path: test
text: "^G404:"
linters:
- gosec
Loading

0 comments on commit 5404290

Please sign in to comment.