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
2 changes: 1 addition & 1 deletion .github/workflows/contribs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
matrix:
program: ${{ fromJson(needs.setup.outputs.programs) }}
name: Run Main
uses: ./.github/workflows/main_template.yml
uses: ./.github/workflows/template_main.yml
with:
modulepath: contribs/${{ matrix.program }}
go-version: ${{ (fromJson(needs.setup.outputs.go-versions))[matrix.program] }}
Expand Down
57 changes: 16 additions & 41 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,31 @@ jobs:
- run: go install -v ./gnovm/cmd/gno
- run: go run ./gnovm/cmd/gno tool transpile -v --gobuild ./examples
test:
strategy:
fail-fast: false
matrix:
goversion:
- "1.23.x"
# unittests: TODO: matrix with contracts
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.goversion }}
- name: Set environment variables for debug mode
if: env.ACTIONS_STEP_DEBUG == 'true'
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
- run: go install -v ./gnovm/cmd/gno
- run: cd examples && go run ../gnovm/cmd/gno test -v -print-runtime-metrics -print-events ./...
name: Run gno test
uses: ./.github/workflows/template_gnotest.yml
with:
debug: env.ACTIONS_STEP_DEBUG == 'true'
path: "examples"
go-version: "1.23.x"

lint:
strategy:
fail-fast: false
matrix:
goversion:
- "1.23.x"
# unittests: TODO: matrix with contracts
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.goversion }}
# testing official directories, basically examples/ minus examples/.../x/.
- run: make lint -C ./examples
# TODO: consider running lint on every other directories, maybe in "warning" mode?
name: Run gno lint
uses: ./.github/workflows/template_gnolint.yml
with:
path: "examples"
go-version: "1.23.x"
# TODO: consider running lint on every other directories, maybe in "warning" mode?
# TODO: track coverage

fmt:
name: Run gno fmt on examples
uses: ./.github/workflows/gnofmt_template.yml
uses: ./.github/workflows/template_gnofmt.yml
with:
path: "examples/..."
path: "examples"

generate:
name: Check generated files are up to date
uses: ./.github/workflows/build_template.yml
uses: ./.github/workflows/template_build.yml
with:
modulepath: "examples"
go-version: "1.23.x"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gnoland.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
jobs:
main:
name: Run gno.land suite
uses: ./.github/workflows/main_template.yml
uses: ./.github/workflows/template_main.yml
with:
modulepath: "gno.land"
tests-extra-args: "-coverpkg=github.com/gnolang/gno/gno.land/..."
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/gnovm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ on:
jobs:
main:
name: Run GnoVM suite
uses: ./.github/workflows/main_template.yml
uses: ./.github/workflows/template_main.yml
with:
modulepath: "gnovm"
tests-extra-args: "-coverpkg=github.com/gnolang/gno/gnovm/..."
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
fmt:
name: Run gno fmt on stdlibs
uses: ./.github/workflows/gnofmt_template.yml
stdlibs-fmt:
name: stdlibs - Run fmt
uses: ./.github/workflows/template_gnofmt.yml
with:
path: "gnovm/stdlibs/..."
path: "gnovm/stdlibs"
stdlibs-test:
name: stdlibs - Run tests
uses: ./.github/workflows/template_gnotest.yml
with:
path: "gnovm/stdlibs"
stdlibs-lint:
name: stdlibs - Run lint
uses: ./.github/workflows/template_gnolint.yml
with:
path: "gnovm/stdlibs"
2 changes: 1 addition & 1 deletion .github/workflows/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- goscan
- loop
name: Run misc suite
uses: ./.github/workflows/main_template.yml
uses: ./.github/workflows/template_main.yml
with:
modulepath: misc/${{ matrix.program }}
tests-extra-args: "-coverpkg=github.com/gnolang/gno/misc/..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ jobs:
fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Checkout code
uses: actions/checkout@v5

- name: Format code with gno fmt
env:
GNOFMT_PATH: ${{ inputs.path }}
run: go run ./gnovm/cmd/gno fmt -v -diff $GNOFMT_PATH

- name: Check for unformatted code
run: |
git diff --exit-code || (echo "Some gno files are not formatted, please run 'make fmt'." && exit 1)
run: go run ./gnovm/cmd/gno -C ${{ inputs.path }} fmt -diff ./...
34 changes: 34 additions & 0 deletions .github/workflows/template_gnolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
workflow_call:
inputs:
path:
description: "Path to run gno lint on"
required: true
type: string
go-version:
description: "Go version to use"
required: false
type: string
default: "1.23.x"
debug:
description: "Enable debug logs"
required: false
type: boolean

jobs:
lint:
strategy:
fail-fast: false
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Run gno lint
run: go run ./gnovm/cmd/gno lint -C ${{ inputs.path }} -v ./...
42 changes: 42 additions & 0 deletions .github/workflows/template_gnotest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
workflow_call:
inputs:
path:
description: "Path to run gno test on"
required: true
type: string
go-version:
description: "Go version to use"
required: false
type: string
default: "1.23.x"
debug:
description: "Enable debug logs"
required: false
type: boolean

jobs:
test:
strategy:
fail-fast: false
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Setup debug env
if: ${{ inputs.debug }}
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV

- name: Run gno test
run: go run ./gnovm/cmd/gno test -C ${{ inputs.path }} -v -print-runtime-metrics -print-events ./...
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ on:
jobs:
lint:
name: Go Lint
uses: ./.github/workflows/lint_template.yml
uses: ./.github/workflows/template_lint.yml
with:
modulepath: ${{ inputs.modulepath }}
go-version: ${{ inputs.go-version }}
build:
name: Go Build
uses: ./.github/workflows/build_template.yml
uses: ./.github/workflows/template_build.yml
with:
modulepath: ${{ inputs.modulepath }}
go-version: ${{ inputs.go-version }}
test:
name: Go Test
uses: ./.github/workflows/test_template.yml
uses: ./.github/workflows/template_test.yml
with:
modulepath: ${{ inputs.modulepath }}
tests-ts-seq: ${{ inputs.tests-ts-seq }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tm2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
jobs:
main:
name: Run TM2 suite
uses: ./.github/workflows/main_template.yml
uses: ./.github/workflows/template_main.yml
with:
modulepath: "tm2"
tests-extra-args: "-coverpkg=github.com/gnolang/gno/tm2/..."
Expand Down
3 changes: 3 additions & 0 deletions gnovm/cmd/gno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ SUBCOMMANDS
tool run specified gno tool
version display installed gno version

FLAGS
-C ... change to directory before running command

```

## Install
Expand Down
6 changes: 4 additions & 2 deletions gnovm/cmd/gno/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func TestCleanApp(t *testing.T) {
io.SetErr(commands.WriteNopCloser(mockErr))

// dry run clean
err = newGnocliCmd(io).ParseAndRun(context.Background(), []string{"clean", "-n"})
cmd, _ := newGnocliCmd(io)
err = cmd.ParseAndRun(context.Background(), []string{"clean", "-n"})
require.NoError(t, err)
// check output
if tc.stdOut != "" {
Expand All @@ -113,7 +114,8 @@ func TestCleanApp(t *testing.T) {
}

// run clean
err = newGnocliCmd(io).ParseAndRun(context.Background(), []string{"clean"})
cmd, _ = newGnocliCmd(io)
err = cmd.ParseAndRun(context.Background(), []string{"clean"})
require.NoError(t, err)
// check files
for _, file := range tc.filesRemoved {
Expand Down
64 changes: 59 additions & 5 deletions gnovm/cmd/gno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"os"
"runtime/pprof"

Expand All @@ -23,17 +26,68 @@ func main() {
defer pprof.StopCPUProfile()
}

cmd := newGnocliCmd(commands.NewDefaultIO())
io := commands.NewDefaultIO()
cmd, cfg := newGnocliCmd(io)

cmd.Execute(context.Background(), os.Args[1:])
args := os.Args[1:]

if err := cmd.Parse(args); err != nil {
handleError(err)
return
}

// Apply directory change after parsing, before running
if err := cfg.ApplyDirectory(); err != nil {
handleError(err)
return
}

ctx := context.Background()
if err := cmd.Run(ctx); err != nil {
handleError(err)
}
}

func handleError(err error) {
var ece commands.ExitCodeError
switch {
case errors.Is(err, flag.ErrHelp): // just exit with 1 (help already printed)
case errors.As(err, &ece):
os.Exit(int(ece))
default:
fmt.Fprintf(os.Stderr, "%+v\n", err)
}
os.Exit(1)
}

func newGnocliCmd(io commands.IO) *commands.Command {
// rootConfig handles global flags
type rootConfig struct {
ChangeDir string
}

// RegisterFlags registers the -C flag for changing directory
func (cfg *rootConfig) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(&cfg.ChangeDir, "C", "", "change to directory before running command")
}

// ApplyDirectory changes to the specified directory if set
func (cfg *rootConfig) ApplyDirectory() error {
if cfg.ChangeDir != "" {
if err := os.Chdir(cfg.ChangeDir); err != nil {
return fmt.Errorf("failed to change directory to %q: %w", cfg.ChangeDir, err)
}
}
return nil
}

func newGnocliCmd(io commands.IO) (*commands.Command, *rootConfig) {
cfg := &rootConfig{}

cmd := commands.NewCommand(
commands.Metadata{
ShortUsage: "gno <command> [arguments]",
},
commands.NewEmptyConfig(),
cfg,
commands.HelpExec,
)

Expand Down Expand Up @@ -62,5 +116,5 @@ func newGnocliCmd(io commands.IO) *commands.Command {
// vet
)

return cmd
return cmd, cfg
}
3 changes: 2 additions & 1 deletion gnovm/cmd/gno/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func testMainCaseRun(t *testing.T, tc []testMainCase) {

testPackageFetcher = examplespkgfetcher.New("")

err := newGnocliCmd(io).ParseAndRun(context.Background(), test.args)
cmd, _ := newGnocliCmd(io)
err := cmd.ParseAndRun(context.Background(), test.args)

if errShouldBeEmpty {
require.Nil(t, err, "err should be nil")
Expand Down
Loading