Skip to content

Commit

Permalink
Merge branch 'master' into sgc
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-dambovaliev authored Sep 28, 2024
2 parents 96b5b05 + 69400d4 commit 675aee6
Show file tree
Hide file tree
Showing 120 changed files with 2,564 additions and 649 deletions.
34 changes: 0 additions & 34 deletions .benchmarks/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions .benchmarks/gobenchdata-checks.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.gno linguist-language=Go
*.pb.go linguist-generated merge=ours -diff
go.sum linguist-generated text
gnovm/stdlibs/native.go linguist-generated
gnovm/tests/stdlibs/native.go linguist-generated
gnovm/stdlibs/generated.go linguist-generated
gnovm/tests/stdlibs/generated.go linguist-generated
3 changes: 2 additions & 1 deletion .github/workflows/benchmark-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ jobs:
secrets: inherit
with:
publish: false
test-flags: "-short"
test-flags: "-short"
external-data-json-path: "./cache/benchmark-data.json"
4 changes: 3 additions & 1 deletion .github/workflows/benchmark-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # run on default branch every day

jobs:
publish:
uses: ./.github/workflows/benchmark_template.yml
secrets: inherit
with:
publish: true
test-flags: "-timeout 50m"
test-flags: "-timeout 50m"
runner-additional-tag: "benchmarks-large"
60 changes: 48 additions & 12 deletions .github/workflows/benchmark_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,65 @@ on:
test-flags:
required: true
type: string
runner-additional-tag:
type: string
default: benchmarks
external-data-json-path:
type: string

permissions:
# deployments permission to deploy GitHub pages website
deployments: write
# contents permission to update benchmark contents in gh-pages branch
contents: write

env:
CGO_ENABLED: 0

jobs:
benchmarks:
if: ${{ github.repository == 'gnolang/gno' }}
runs-on: [self-hosted, Linux, X64, benchmark-v1]
runs-on: [self-hosted, Linux, X64, "${{ inputs.runner-additional-tag }}"]
steps:
- name: checkout
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- uses: actions/setup-go@v5
with:
go-version: "1.22.x"
- name: "gobenchdata publish: ${{ inputs.publish }}"
run: go run go.bobheadxi.dev/gobenchdata@v1 action
env:
INPUT_PRUNE_COUNT: 30
INPUT_GO_TEST_FLAGS: "${{ inputs.test-flags }} -run=^$ -cpu 1,2" # executing only using one and two CPUs to not be dependant on the machine cores.
INPUT_PUBLISH: ${{ inputs.publish }}
INPUT_PUBLISH_BRANCH: gh-benchmarks
INPUT_BENCHMARKS_OUT: benchmarks.json
INPUT_CHECKS: ${{ !inputs.publish }}
INPUT_CHECKS_CONFIG: .benchmarks/gobenchdata-checks.yml

- name: Run benchmark
run: |
go test -benchmem -bench=. ./... -run=^$ \
-cpu 1,2 ${{ inputs.test-flags }} | tee benchmarks.txt
- name: Download previous benchmark data
uses: actions/cache@v4
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Store benchmark results into `gh-benchmarks` branch
uses: benchmark-action/github-action-benchmark@v1
# see https://github.com/benchmark-action/github-action-benchmark?tab=readme-ov-file#action-inputs
with:
name: Go Benchmarks
tool: 'go'
output-file-path: benchmarks.txt
# Where the previous data file is stored
external-data-json-path: ${{ inputs.external-data-json-path }}
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '20%'
fail-on-alert: true
comment-on-alert: true
# Enable Job Summary for PRs
summary-always: true
github-token: ${{ secrets.GITHUB_TOKEN }}
# NOTE you need to use a separate GITHUB PAT token that has a write access to the specified repository.
# gh-repository: 'github.com/gnolang/benchmarks' # on gh-pages branch
gh-pages-branch: gh-benchmarks
benchmark-data-dir-path: .
auto-push: ${{ inputs.publish }}
alert-comment-cc-users: '@ajnavarro,@thehowl,@zivkovicmilos'
2 changes: 1 addition & 1 deletion .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: coursier/cache-action@v6.4.6

- name: Set up JDK 17
uses: coursier/setup-action@v1.3.5
uses: coursier/setup-action@v1.3.6
with:
jvm: temurin:1.17

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightlies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
go-version: "1.22.x"
cache: true

- uses: sigstore/cosign-installer@v3.5.0
- uses: anchore/sbom-action/download-syft@v0.17.0
- uses: sigstore/cosign-installer@v3.6.0
- uses: anchore/sbom-action/download-syft@v0.17.2

- uses: docker/login-action@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/releaser-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
go-version: "1.22.x"
cache: true

- uses: sigstore/cosign-installer@v3.5.0
- uses: anchore/sbom-action/download-syft@v0.17.0
- uses: sigstore/cosign-installer@v3.6.0
- uses: anchore/sbom-action/download-syft@v0.17.2

- uses: docker/login-action@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
go-version: "1.22.x"
cache: true

- uses: sigstore/cosign-installer@v3.5.0
- uses: anchore/sbom-action/download-syft@v0.17.0
- uses: sigstore/cosign-installer@v3.6.0
- uses: anchore/sbom-action/download-syft@v0.17.2

- uses: docker/login-action@v3
with:
Expand Down
66 changes: 59 additions & 7 deletions contribs/gnodev/cmd/gnobro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"flag"
"fmt"
"io"
"log/slog"
"net"
"net/url"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/charmbracelet/wish"
"github.com/charmbracelet/wish/activeterm"
"github.com/charmbracelet/wish/bubbletea"
"github.com/charmbracelet/wish/logging"
"golang.org/x/sync/errgroup"

"github.com/gnolang/gno/contribs/gnodev/pkg/browser"
Expand All @@ -47,6 +47,7 @@ type broCfg struct {
sshListener string
sshHostKeyPath string
banner bool
jsonlog bool
}

var defaultBroOptions = broCfg{
Expand Down Expand Up @@ -152,6 +153,13 @@ func (c *broCfg) RegisterFlags(fs *flag.FlagSet) {
defaultBroOptions.readonly,
"readonly mode, no commands allowed",
)

fs.BoolVar(
&c.jsonlog,
"jsonlog",
defaultBroOptions.jsonlog,
"display server log as json format",
)
}

func execBrowser(cfg *broCfg, args []string, cio commands.IO) error {
Expand Down Expand Up @@ -277,9 +285,7 @@ func runLocal(ctx context.Context, gnocl *gnoclient.Client, cfg *broCfg, bcfg br

func runServer(ctx context.Context, gnocl *gnoclient.Client, cfg *broCfg, bcfg browser.Config, io commands.IO) error {
// setup logger
charmlogger := charmlog.New(io.Out())
charmlogger.SetLevel(charmlog.DebugLevel)
logger := slog.New(charmlogger)
logger := newLogger(io.Out(), cfg.jsonlog)

teaHandler := func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
shortid := fmt.Sprintf("%.10s", s.Context().SessionID())
Expand Down Expand Up @@ -326,8 +332,8 @@ func runServer(ctx context.Context, gnocl *gnoclient.Client, cfg *broCfg, bcfg b
bubbletea.Middleware(teaHandler),
activeterm.Middleware(), // ensure PTY
ValidatePathCommandMiddleware(bcfg.URLPrefix),
logging.StructuredMiddlewareWithLogger(
charmlogger, charmlog.DebugLevel,
StructuredMiddlewareWithLogger(
ctx, logger, slog.LevelInfo,
),
// XXX: add ip throttler
),
Expand Down Expand Up @@ -358,7 +364,9 @@ func runServer(ctx context.Context, gnocl *gnoclient.Client, cfg *broCfg, bcfg b
return err
}

io.Println("Bye!")
if !cfg.jsonlog {
io.Println("Bye!")
}
return nil
}

Expand Down Expand Up @@ -460,3 +468,47 @@ func ValidatePathCommandMiddleware(pathPrefix string) wish.Middleware {
}
}
}

func StructuredMiddlewareWithLogger(ctx context.Context, logger *slog.Logger, level slog.Level) wish.Middleware {
return func(next ssh.Handler) ssh.Handler {
return func(sess ssh.Session) {
ct := time.Now()
hpk := sess.PublicKey() != nil
pty, _, _ := sess.Pty()
logger.Log(
ctx,
level,
"connect",
"user", sess.User(),
"remote-addr", sess.RemoteAddr().String(),
"public-key", hpk,
"command", sess.Command(),
"term", pty.Term,
"width", pty.Window.Width,
"height", pty.Window.Height,
"client-version", sess.Context().ClientVersion(),
)
next(sess)
logger.Log(
ctx,
level,
"disconnect",
"user", sess.User(),
"remote-addr", sess.RemoteAddr().String(),
"duration", time.Since(ct),
)
}
}
}

func newLogger(out io.Writer, json bool) *slog.Logger {
if json {
return slog.New(slog.NewJSONHandler(out, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
}

charmlogger := charmlog.New(out)
charmlogger.SetLevel(charmlog.DebugLevel)
return slog.New(charmlogger)
}
Loading

0 comments on commit 675aee6

Please sign in to comment.