Skip to content

Commit

Permalink
Merge branch 'master' into chore/avl-pager-ro-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl authored Feb 6, 2025
2 parents 2145f1f + 08d29a5 commit 2d19b39
Show file tree
Hide file tree
Showing 134 changed files with 1,901 additions and 650 deletions.
15 changes: 3 additions & 12 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@ coverage:
round: down
precision: 2
status:
project:
patch: # new lines
default:
target: auto
threshold: 5 # Let's decrease this later.
base: parent
if_no_uploads: error
if_not_found: success
if_ci_failed: error
only_pulls: false
patch:
default:
target: auto
threshold: 5 # Let's decrease this later.
target: 80
threshold: 10
base: auto
if_no_uploads: error
if_not_found: success
Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# generate Go docs and publish on gh-pages branch
# Live at: https://gnolang.github.io/gno
name: Go Reference Docs Deployment
name: GitHub pages (godoc & stdlib_diff) build and deploy

on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:

permissions:
Expand All @@ -19,29 +22,39 @@ concurrency:

jobs:
build:
if: ${{ github.repository == 'gnolang/gno' }} # Alternatively, validate based on provided tokens and permissions.
if: github.repository == 'gnolang/gno' # Alternatively, validate based on provided tokens and permissions.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: echo "GOROOT=$(go env GOROOT)" >> $GITHUB_ENV
- run: echo $GOROOT
# Use the goroot at the top of the project to compare with the GnoVM
# stdlib, rather than the one in stdlib_diff (which may have a go.mod with
# a different toolchain version).
- run: echo "GOROOT_SAVE=$(go env GOROOT)" >> $GITHUB_ENV
- run: "cd misc/stdlib_diff && make gen"
- run: "cd misc/gendocs && make install gen"
- run: "mkdir -p pages_output/stdlib_diff"
- run: |
cp -r misc/gendocs/godoc/* pages_output/
cp -r misc/stdlib_diff/stdlib_diff/* pages_output/stdlib_diff/
# These two last steps will be skipped on pull requests
- uses: actions/configure-pages@v5
id: pages
if: github.event_name != 'pull_request'

- uses: actions/upload-pages-artifact@v3
if: github.event_name != 'pull_request'
with:
path: ./pages_output

deploy:
if: ${{ github.repository == 'gnolang/gno' }} # Alternatively, validate based on provided tokens and permissions.
if: >
github.repository == 'gnolang/gno' &&
github.ref == 'refs/heads/master' &&
github.event_name == 'push'
runs-on: ubuntu-latest
environment:
name: github-pages
Expand Down
19 changes: 14 additions & 5 deletions contribs/github-bot/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ func Config(gh *client.GitHub) ([]AutomaticCheck, []ManualCheck) {
auto := []AutomaticCheck{
{
Description: "Maintainers must be able to edit this pull request ([more info](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork))",
If: c.CreatedFromFork(),
Then: r.MaintainerCanModify(),
If: c.And(
c.BaseBranch("^master$"),
c.CreatedFromFork(),
),
Then: r.MaintainerCanModify(),
},
{
Description: "Changes to 'docs' folder must be reviewed/authored by at least one devrel and one tech-staff",
If: c.FileChanged(gh, "^docs/"),
If: c.And(
c.BaseBranch("^master$"),
c.FileChanged(gh, "^docs/"),
),
Then: r.And(
r.Or(
r.AuthorInTeam(gh, "tech-staff"),
Expand All @@ -57,7 +63,10 @@ func Config(gh *client.GitHub) ([]AutomaticCheck, []ManualCheck) {
},
{
Description: "Pending initial approval by a review team member, or review from tech-staff",
If: c.Not(c.AuthorInTeam(gh, "tech-staff")),
If: c.And(
c.BaseBranch("^master$"),
c.Not(c.AuthorInTeam(gh, "tech-staff")),
),
Then: r.
If(r.Or(
r.ReviewByOrgMembers(gh).WithDesiredState(utils.ReviewStateApproved),
Expand Down Expand Up @@ -91,7 +100,7 @@ func Config(gh *client.GitHub) ([]AutomaticCheck, []ManualCheck) {
{
Description: "Determine if infra needs to be updated before merging",
If: c.And(
c.BaseBranch("master"),
c.BaseBranch("^master$"),
c.Or(
c.FileChanged(gh, `Dockerfile`),
c.FileChanged(gh, `^misc/deployments`),
Expand Down
10 changes: 4 additions & 6 deletions docs/gno-tooling/cli/gnokey/state-changing-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ Next, let's configure the `addpkg` subcommand to publish this package to the
the `example/p/` folder, the command will look like this:

```bash
gnokey maketx addpkg \
gnokey maketx addpkg \
-pkgpath "gno.land/p/<your_namespace>/hello_world" \
-pkgdir "." \
-send "" \
-gas-fee 10000000ugnot \
-gas-wanted 8000000 \
-gas-wanted 200000 \
-broadcast \
-chainid portal-loop \
-remote "https://rpc.gno.land:443"
Expand All @@ -114,15 +113,14 @@ Once we have added a desired [namespace](../../../concepts/namespaces.md) to upl
a keypair name to use to execute the transaction:

```bash
gnokey maketx addpkg \
gnokey maketx addpkg \
-pkgpath "gno.land/p/examplenamespace/hello_world" \
-pkgdir "." \
-send "" \
-gas-fee 10000000ugnot \
-gas-wanted 200000 \
-broadcast \
-chainid portal-loop \
-remote "https://rpc.gno.land:443"
-remote "https://rpc.gno.land:443" \
mykey
```

Expand Down
12 changes: 0 additions & 12 deletions docs/reference/stdlibs/std/chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ id: chain

# Chain-related

## IsOriginCall
```go
func IsOriginCall() bool
```
Checks if the caller of the function is an EOA. Returns **true** if caller is an EOA, **false** otherwise.

#### Usage
```go
if !std.IsOriginCall() {...}
```
---

## AssertOriginCall
```go
func AssertOriginCall()
Expand Down
6 changes: 4 additions & 2 deletions examples/gno.land/p/demo/mux/handler.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type Handler struct {

type HandlerFunc func(*ResponseWriter, *Request)

// TODO: type ErrHandlerFunc func(*ResponseWriter, *Request) error
// TODO: NotFoundHandler
type ErrHandlerFunc func(*ResponseWriter, *Request) error

type NotFoundHandler func(*ResponseWriter, *Request)

// TODO: AutomaticIndex
27 changes: 16 additions & 11 deletions examples/gno.land/p/demo/mux/request.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,29 @@ type Request struct {

// GetVar retrieves a variable from the path based on routing rules.
func (r *Request) GetVar(key string) string {
var (
handlerParts = strings.Split(r.HandlerPath, "/")
reqParts = strings.Split(r.Path, "/")
)

for i := 0; i < len(handlerParts); i++ {
handlerPart := handlerParts[i]
handlerParts := strings.Split(r.HandlerPath, "/")
reqParts := strings.Split(r.Path, "/")
reqIndex := 0
for handlerIndex := 0; handlerIndex < len(handlerParts); handlerIndex++ {
handlerPart := handlerParts[handlerIndex]
switch {
case handlerPart == "*":
// XXX: implement a/b/*/d/e
panic("not implemented")
// If a wildcard "*" is found, consume all remaining segments
wildcardParts := reqParts[reqIndex:]
reqIndex = len(reqParts) // Consume all remaining segments
return strings.Join(wildcardParts, "/") // Return all remaining segments as a string
case strings.HasPrefix(handlerPart, "{") && strings.HasSuffix(handlerPart, "}"):
// If a variable of the form {param} is found we compare it with the key
parameter := handlerPart[1 : len(handlerPart)-1]
if parameter == key {
return reqParts[i]
return reqParts[reqIndex]
}
reqIndex++
default:
// continue
if reqIndex >= len(reqParts) || handlerPart != reqParts[reqIndex] {
return ""
}
reqIndex++
}
}

Expand Down
33 changes: 21 additions & 12 deletions examples/gno.land/p/demo/mux/request_test.gno
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mux

import (
"fmt"
"testing"

"gno.land/p/demo/uassert"
"gno.land/p/demo/ufmt"
)

func TestRequest_GetVar(t *testing.T) {
Expand All @@ -12,28 +14,35 @@ func TestRequest_GetVar(t *testing.T) {
getVarKey string
expectedOutput string
}{

{"users/{id}", "users/123", "id", "123"},
{"users/123", "users/123", "id", ""},
{"users/{id}", "users/123", "nonexistent", ""},
{"a/{b}/c/{d}", "a/42/c/1337", "b", "42"},
{"a/{b}/c/{d}", "a/42/c/1337", "d", "1337"},
{"{a}", "foo", "a", "foo"},
// TODO: wildcards: a/*/c
// TODO: multiple patterns per slashes: a/{b}-{c}/d
}
{"users/{userId}/posts/{postId}", "users/123/posts/456", "userId", "123"},
{"users/{userId}/posts/{postId}", "users/123/posts/456", "postId", "456"},

// Wildcards
{"*", "users/123", "*", "users/123"},
{"*", "users/123/posts/456", "*", "users/123/posts/456"},
{"*", "users/123/posts/456/comments/789", "*", "users/123/posts/456/comments/789"},
{"users/*", "users/john/posts", "*", "john/posts"},
{"users/*/comments", "users/jane/comments", "*", "jane/comments"},
{"api/*/posts/*", "api/v1/posts/123", "*", "v1/posts/123"},

// wildcards and parameters
{"api/{version}/*", "api/v1/user/settings", "version", "v1"},
}
for _, tt := range cases {
name := fmt.Sprintf("%s-%s", tt.handlerPath, tt.reqPath)
name := ufmt.Sprintf("%s-%s", tt.handlerPath, tt.reqPath)
t.Run(name, func(t *testing.T) {
req := &Request{
HandlerPath: tt.handlerPath,
Path: tt.reqPath,
}

output := req.GetVar(tt.getVarKey)
if output != tt.expectedOutput {
t.Errorf("Expected '%q, but got %q", tt.expectedOutput, output)
}
uassert.Equal(t, tt.expectedOutput, output,
"handler: %q, path: %q, key: %q",
tt.handlerPath, tt.reqPath, tt.getVarKey)
})
}
}
35 changes: 30 additions & 5 deletions examples/gno.land/p/demo/mux/router.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "strings"
// Router handles the routing and rendering logic.
type Router struct {
routes []Handler
NotFoundHandler HandlerFunc
NotFoundHandler NotFoundHandler
}

// NewRouter creates a new Router instance.
Expand All @@ -23,8 +23,14 @@ func (r *Router) Render(reqPath string) string {

for _, route := range r.routes {
patParts := strings.Split(route.Pattern, "/")

if len(patParts) != len(reqParts) {
wildcard := false
for _, part := range patParts {
if part == "*" {
wildcard = true
break
}
}
if !wildcard && len(patParts) != len(reqParts) {
continue
}

Expand All @@ -34,7 +40,7 @@ func (r *Router) Render(reqPath string) string {
reqPart := reqParts[i]

if patPart == "*" {
continue
break
}
if strings.HasPrefix(patPart, "{") && strings.HasSuffix(patPart, "}") {
continue
Expand Down Expand Up @@ -63,12 +69,31 @@ func (r *Router) Render(reqPath string) string {
return res.Output()
}

// Handle registers a route and its handler function.
// HandleFunc registers a route and its handler function.
func (r *Router) HandleFunc(pattern string, fn HandlerFunc) {
route := Handler{Pattern: pattern, Fn: fn}
r.routes = append(r.routes, route)
}

// HandleErrFunc registers a route and its error handler function.
func (r *Router) HandleErrFunc(pattern string, fn ErrHandlerFunc) {

// Convert ErrHandlerFunc to regular HandlerFunc
handler := func(res *ResponseWriter, req *Request) {
if err := fn(res, req); err != nil {
res.Write("Error: " + err.Error())
}
}

r.HandleFunc(pattern, handler)
}

// SetNotFoundHandler sets custom message for 404 defaultNotFoundHandler.
func (r *Router) SetNotFoundHandler(handler NotFoundHandler) {
r.NotFoundHandler = handler
}

// stripQueryString removes query string from the request path.
func stripQueryString(reqPath string) string {
i := strings.Index(reqPath, "?")
if i == -1 {
Expand Down
28 changes: 27 additions & 1 deletion examples/gno.land/p/demo/mux/router_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,33 @@ func TestRouter_Render(t *testing.T) {
})
},
},

{
label: "wildcard in route",
path: "hello/Alice/Bob",
expectedOutput: "Matched: Alice/Bob",
setupHandler: func(t *testing.T, r *Router) {
r.HandleFunc("hello/*", func(rw *ResponseWriter, req *Request) {
path := req.GetVar("*")
uassert.Equal(t, "Alice/Bob", path)
uassert.Equal(t, "hello/Alice/Bob", req.Path)
rw.Write("Matched: " + path)
})
},
},
{
label: "wildcard in route with query string",
path: "hello/Alice/Bob?foo=bar",
expectedOutput: "Matched: Alice/Bob",
setupHandler: func(t *testing.T, r *Router) {
r.HandleFunc("hello/*", func(rw *ResponseWriter, req *Request) {
path := req.GetVar("*")
uassert.Equal(t, "Alice/Bob", path)
uassert.Equal(t, "hello/Alice/Bob?foo=bar", req.RawPath)
uassert.Equal(t, "hello/Alice/Bob", req.Path)
rw.Write("Matched: " + path)
})
},
},
// TODO: {"hello", "Hello, world!"},
// TODO: hello/, /hello, hello//Alice, hello/Alice/, hello/Alice/Bob, etc
}
Expand Down
Loading

0 comments on commit 2d19b39

Please sign in to comment.