Skip to content
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

chore: improve makefile to avoid the tools file #59

Merged
merged 6 commits into from
Feb 15, 2024
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
11 changes: 5 additions & 6 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v3.4.0
- name: Finding files and store to output
id: set-matrix
run: echo "matrix=$({ cd integration && find . -type d ! -name testdata -maxdepth 1 -print; } | tail -n +2 | cut -c 3- | jq -R . | jq -cs .)" >> $GITHUB_OUTPUT
run: echo "matrix=$(find . -type d -name "integration" -exec dirname {} \; | sort -u | jq -R . | jq -cs .)" >> $GITHUB_OUTPUT

integration:
name: test ${{ matrix.test-path }}
Expand All @@ -40,11 +40,10 @@ jobs:
- uses: technote-space/get-diff-action@v6.1.2
with:
PATTERNS: |
${{ matrix.test-path }}/**
${{ matrix.test-path }}/**/*.go
${{ matrix.test-path }}/*/go.mod
${{ matrix.test-path }}/*/go.sum
!${{ matrix.test-path }}/README.md
integration/go.mod
integration/go.sum
integration/${{ matrix.test-path }}/**

- uses: actions/setup-go@v4
if: env.GIT_DIFF
Expand All @@ -56,7 +55,7 @@ jobs:
env:
GOTOOLCHAIN: local+path
GOSUMDB: off
run: go test -v -timeout 120m ./integration/${{ matrix.test-path }}
run: go test -v -timeout 120m ${{ matrix.test-path }}/integration/...

status:
runs-on: ubuntu-latest
Expand Down
31 changes: 6 additions & 25 deletions .github/workflows/test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,9 @@ concurrency:
cancel-in-progress: true

jobs:
list-directories:
name: List root package directories
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3.4.0
- id: set-matrix
run: |
PATHS=$(find . -maxdepth 2 -type f -name go.mod -printf '"%h",')
echo "matrix=[${PATHS%?}]" >> $GITHUB_OUTPUT

lint:
name: 'Lint Go Code: ${{ matrix.package-directory }}'
name: 'Lint Go Code'
runs-on: ubuntu-latest
timeout-minutes: 6
needs: list-directories
strategy:
matrix:
package-directory: ${{ fromJson(needs.list-directories.outputs.matrix) }}
steps:
- uses: actions/checkout@v3.4.0
- uses: technote-space/get-diff-action@v6.1.2
Expand All @@ -44,11 +27,9 @@ jobs:
if: env.GIT_DIFF
with:
go-version: '1.21'
- uses: golangci/golangci-lint-action@v3
- name: Run Lint Tests
if: env.GIT_DIFF
with:
version: v1.52.1
install-mode: goinstall
args: --timeout 10m
github-token: ${{ secrets.github_token }}
working-directory: ${{ matrix.package-directory }}
env:
GOTOOLCHAIN: local+path
GOSUMDB: off
run: make check
67 changes: 55 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,62 @@ PROJECT_NAME = 'ignite apps'
## govet: Run go vet.
govet:
@echo Running go vet...
@go list -f '{{.Dir}}/...' -m | xargs go vet
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go vet in $$dir"; \
cd "$$dir" && go vet ./...; \
fi \
done

## govulncheck: Run govulncheck
govulncheck:
@command -v govulncheck >/dev/null 2>&1 || { \
echo "Installing govulncheck..."; \
go install golang.org/x/vuln/cmd/govulncheck@latest; \
}
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go vet in $$dir"; \
cd "$$dir" && govulncheck ./...; \
fi \
done
@echo Running govulncheck...
@go list -f '{{.Dir}}/...' -m | grep -v integration |xargs go run golang.org/x/vuln/cmd/govulncheck

## format: Install and run goimports and gofumpt
format:
@echo Formatting...
@go run mvdan.cc/gofumpt -w .
@go run golang.org/x/tools/cmd/goimports -w -local github.com/ignite/apps .

## lint: Run Golang CI Lint.
lint:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "Installing golangci-lint..."; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.42.1; \
}
@echo Running golangci-lint...
@go list -f '{{.Dir}}/...' -m | xargs go run github.com/golangci/golangci-lint/cmd/golangci-lint run --out-format=tab --issues-exit-code=0
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running golangci-lint in $$dir"; \
cd "$$dir" && golangci-lint run --out-format=tab --issues-exit-code=0; \
fi \
done

## check: Run govet, govulncheck and lint
check: govet govulncheck lint

## format: Install and run goimports and gofumpt
format:
@echo Formatting...
@command -v gofumpt >/dev/null 2>&1 || { \
echo "Installing gofumpt..."; \
go install mvdan.cc/gofumpt@latest; \
}
@command -v goimports >/dev/null 2>&1 || { \
echo "Installing goimports..."; \
go install golang.org/x/tools/cmd/goimports@latest; \
}
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running format in $$dir"; \
cd "$$dir" && gofumpt -w .; \
cd "$$dir" && goimports -w -local github.com/ignite/apps .; \
fi \
done

.PHONY: govet format lint

Expand All @@ -32,9 +71,13 @@ test-unit:
@go list -f '{{.Dir}}/...' -m | xargs go test -race -failfast -v

## test-integration: Run the integration tests.
test-integration: install
@echo Running integration tests...
@go test -race -failfast -v -timeout 60m ./integration/...
test-integration:
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ] && [ -d "$$dir/integration" ]; then \
echo "Running integration tests in $$dir"; \
cd "$$dir" && go test -race -failfast -v -timeout 60m ./integration/...; \
fi \
done

## test: Run unit and integration tests.
test: govet govulncheck test-unit test-integration
Expand Down
2 changes: 1 addition & 1 deletion examples/health-monitor/cmd/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ExecuteMonitor(ctx context.Context, cmd *plugin.ExecutedCommand, chainInfo
}
rpcURL, err := xurl.HTTP(rpcAddress)
if err != nil {
return fmt.Errorf("invalid rpc address %s: %w", &rpcAddress, err)
return fmt.Errorf("invalid rpc address %s: %w", rpcAddress, err)
}

httpClient, err := client.NewClientFromNode(rpcURL)
Expand Down
1 change: 0 additions & 1 deletion examples/health-monitor/integration/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func TestHealthMonitor(t *testing.T) {
require.Contains(buf.String(), "Version:")
require.Contains(buf.String(), "Height:")
require.Contains(buf.String(), "Latest Block Hash:")

}

func assertLocalPlugins(t *testing.T, app envtest.App, expectedPlugins []pluginsconfig.Plugin) {
Expand Down
Loading
Loading