Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/debug-pkg
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/test-integration.yml
#	examples/health-monitor/go.sum
#	explorer/go.mod
#	explorer/go.sum
#	explorer/integration/gex_test.go
#	hermes/go.mod
#	hermes/go.sum
#	integration/explorer/gex_test.go
#	integration/go.sum
#	marketplace/cmd/info.go
#	marketplace/cmd/list.go
#	marketplace/pkg/apps/details.go
#	marketplace/pkg/apps/search.go
#	marketplace/pkg/tree/tree_test.go
#	test/debug/go.mod
#	test/debug/go.sum
#	test/debug/tools.go
#	test/integration/explorer/gex_test.go
  • Loading branch information
Pantani authored and Pantani committed Feb 16, 2024
2 parents feb0f68 + 6f846a5 commit 977cf1d
Show file tree
Hide file tree
Showing 63 changed files with 7,583 additions and 1,614 deletions.
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 test/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
test/integration/go.mod
test/integration/go.sum
test/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 ./test/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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.vscode
*.test
*.ign
go.work
go.work.sum
93 changes: 78 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,85 @@
# Project variables.
PROJECT_NAME = 'ignite apps'

## govet: Run go vet.
## goget: Run go get for all apps.
goget:
@echo Running go mod tidy...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go get $(REPO) in $$dir"; \
cd "$$dir" && go get $(REPO); \
fi \
done

## modtidy: Run go mod tidy for all apps.
modtidy:
@echo Running go mod tidy...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go mod tidy in $$dir"; \
cd "$$dir" && go mod tidy; \
fi \
done

## govet: Run go vet for all apps.
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: Run govulncheck for all apps.
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: Run Golang CI Lint for all apps.
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 for all apps.
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 +91,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
26 changes: 26 additions & 0 deletions app.ignite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 1
apps:
explorer:
description: Easy to use terminal chain explorer for testing your Ignite blockchains
path: ./explorer
hermes:
description: A wrapper around the hermes IBC relayer
path: ./hermes
marketplace:
description: Explore the world of Ignite applications and more!
path: ./marketplace
chain-info:
description: A simple chain information application
path: ./examples/chain-info
flags:
description: A simple flags usage application
path: ./examples/flags
health-monitor:
description: A simple health monitor application
path: ./examples/health-monitor
hello-world:
description: A simple hello world application
path: ./examples/hello-world
hooks:
description: A simple hooks application
path: ./examples/hooks
52 changes: 52 additions & 0 deletions examples/chain-info/cmd/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cmd

import (
"context"
"fmt"
"os"
"path"

"github.com/ignite/cli/v28/ignite/pkg/cache"
"github.com/ignite/cli/v28/ignite/services/chain"
"github.com/ignite/cli/v28/ignite/services/plugin"
"github.com/spf13/pflag"
)

// ExecuteBuild executes the build subcommand.
func ExecuteBuild(ctx context.Context, cmd *plugin.ExecutedCommand, c *chain.Chain) error {
flags, err := cmd.NewFlags()
if err != nil {
return err
}
output, err := getOutputFlag(flags)
if err != nil {
return err
}

tempDir, err := os.MkdirTemp(os.TempDir(), "buildcache-*")
if err != nil {
return fmt.Errorf("could not create a temp dir: %w", err)
}
cacheStorage, err := cache.NewStorage(path.Join(tempDir, "cacheStorage.db"))
if err != nil {
return fmt.Errorf("could not prepare a cache storage for building chain: %w", err)
}
binaryName, err := c.Build(ctx, cacheStorage, nil, output, false, true)
if err != nil {
return fmt.Errorf("building chain failed with error: %w", err)
}
fmt.Printf("Chain built successfully at %s\n", binaryName)
return nil
}

func getOutputFlag(flags *pflag.FlagSet) (string, error) {
out, err := flags.GetString("output")
if err != nil {
return "", fmt.Errorf("could not get --output flag: %w", err)
}

if out == "" {
return ".", nil
}
return out, nil
}
32 changes: 32 additions & 0 deletions examples/chain-info/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import "github.com/ignite/cli/v28/ignite/services/plugin"

// GetCommands returns the list of chain-info app commands.
func GetCommands() []*plugin.Command {
return []*plugin.Command{
{
Use: "chain-info",
Short: "chain-info is a simple application that demonstrates how to get information or manipulate the chains",
Commands: []*plugin.Command{
{
Use: "info",
Short: "Prints out some basic informations about the chain in the current directory",
},
{
Use: "build",
Short: "Builds the chain app in the current directory with help of ignite helper functions",
Flags: []*plugin.Flag{
{
Name: "output",
Shorthand: "o",
Usage: "The path to output binary file",
DefaultValue: ".",
Type: plugin.FlagTypeString,
},
},
},
},
},
}
}
36 changes: 36 additions & 0 deletions examples/chain-info/cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"context"
"fmt"
"os"
"text/tabwriter"

"github.com/ignite/cli/v28/ignite/services/chain"
"github.com/ignite/cli/v28/ignite/services/plugin"
)

// ExecuteInfo executes the info subcommand.
func ExecuteInfo(ctx context.Context, cmd *plugin.ExecutedCommand, c *chain.Chain) error {
w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
write := func(s string, v interface{}) {
fmt.Fprintf(w, "%s:\t%v\n", s, v)
}

write("Version", c.Version)
write("App Path", c.AppPath())
write("Config Path", c.ConfigPath())
init, err := c.IsInitialized()
if err != nil {
return fmt.Errorf("could not find out if the chain is initialized: %w", err)
}
write("Is Initialized", init)
bin, err := c.Binary()
if err != nil {
return fmt.Errorf("could not find out chain's binary file name: %w", err)
}
write("Binary File", bin)
w.Flush()

return nil
}
Loading

0 comments on commit 977cf1d

Please sign in to comment.