Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/json-primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Jan 24, 2025
2 parents 4db0338 + f67f186 commit eb85c50
Show file tree
Hide file tree
Showing 634 changed files with 28,063 additions and 18,930 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
go.sum linguist-generated text
gnovm/stdlibs/generated.go linguist-generated
gnovm/tests/stdlibs/generated.go linguist-generated
*.gen.gno linguist-generated
*.gen_test.gno linguist-generated
*.gen.go linguist-generated
*.gen_test.go linguist-generated
1 change: 1 addition & 0 deletions .github/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ issues:
- gosec # Disabled linting of weak number generators
- makezero # Disabled linting of intentional slice appends
- goconst # Disabled linting of common mnemonics and test case strings
- unused # Disabled linting of unused mock methods
- path: _\.gno
linters:
- errorlint # Disabled linting of error comparisons, because of lacking std lib support
2 changes: 2 additions & 0 deletions .github/workflows/bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ jobs:
define-prs-matrix:
name: Define PRs matrix
# Skip this workflow if:
# - the bot is not configured on this repo/fork
# - the bot is retriggering itself
# - the event is emitted by codecov
# - the event is a review on a pull request from a fork (see save-pr-number job below)
if: |
vars.GH_BOT_LOGIN != '' &&
github.actor != vars.GH_BOT_LOGIN &&
github.actor != 'codecov[bot]' &&
(github.event_name != 'pull_request_review' || github.event.pull_request.base.repo.full_name == github.event.pull_request.head.repo.full_name)
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
go-version: ${{ matrix.goversion }}
- run: go install -v ./gnovm/cmd/gno
- run: go run ./gnovm/cmd/gno transpile -v --gobuild ./examples
- run: go run ./gnovm/cmd/gno tool transpile -v --gobuild ./examples
test:
strategy:
fail-fast: false
Expand Down Expand Up @@ -71,12 +71,20 @@ jobs:
- run: make lint -C ./examples
# 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
with:
path: "examples/..."

generate:
name: Check generated files are up to date
uses: ./.github/workflows/build_template.yml
with:
modulepath: "examples"
go-version: "1.22.x"

mod-tidy:
strategy:
fail-fast: false
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/gnoland.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
# since there are integration suites that cover the gnovm / tm2
- gnovm/**
- tm2/**
# Changes to examples/ can create failures in gno.land, eg. txtars,
# see: https://github.com/gnolang/gno/pull/3590
- examples/**
workflow_dispatch:

jobs:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/releaser-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- master
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}

permissions:
contents: write # needed to write releases
id-token: write # needed for keyless signing
Expand All @@ -27,7 +30,7 @@ jobs:
cache: true

- uses: sigstore/[email protected]
- uses: anchore/sbom-action/[email protected].8
- uses: anchore/sbom-action/[email protected].9

- uses: docker/login-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releaser-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
cache: true

- uses: sigstore/[email protected]
- uses: anchore/sbom-action/[email protected].8
- uses: anchore/sbom-action/[email protected].9

- uses: docker/login-action@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ coverage.out
*.swp
*.swo
*.bak

.tmp/
wal/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Additionally, it's not possible to use `gofumpt` for code formatting with
(flycheck-define-checker gno-lint
"A GNO syntax checker using the gno lint tool."
:command ("gno" "lint" source-original)
:command ("gno" "tool" "lint" source-original)
:error-patterns (;; ./file.gno:32: error message (code=1)
(error line-start (file-name) ":" line ": " (message) " (code=" (id (one-or-more digit)) ")." line-end))
;; Ensure the file is saved, to work around
Expand Down
16 changes: 16 additions & 0 deletions contribs/github-bot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GNOROOT_DIR ?= $(abspath $(lastword $(MAKEFILE_LIST))/../../../)

rundep := go run -modfile ../../misc/devdeps/go.mod
golangci_lint := $(rundep) github.com/golangci/golangci-lint/cmd/golangci-lint

.PHONY: install
install:
go install .

.PHONY: lint
lint:
$(golangci_lint) --config ../../.github/golangci.yml run ./...

.PHONY: test
test:
go test $(GOTEST_FLAGS) -v ./...
10 changes: 5 additions & 5 deletions contribs/github-bot/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/gnolang/gno/contribs/github-bot

go 1.22
go 1.22.0

toolchain go1.22.2
toolchain go1.23.2

replace github.com/gnolang/gno => ../..

Expand All @@ -11,7 +11,7 @@ require (
github.com/google/go-github/v64 v64.0.0
github.com/migueleliasweb/go-github-mock v1.0.1
github.com/sethvargo/go-githubactions v1.3.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/xlab/treeprint v1.2.0
)

Expand All @@ -21,8 +21,8 @@ require (
github.com/gorilla/mux v1.8.1 // indirect
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions contribs/github-bot/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contribs/github-bot/internal/check/comment.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.

##### 📚 Resources:
- [Report a bug with the bot](https://github.com/gnolang/gno/issues/3238).
- [Report a bug with the bot](https://www.github.com/gnolang/gno/issues/3238).
- [View the bot’s configuration file](https://github.com/gnolang/gno/tree/master/contribs/github-bot/internal/config/config.go).

{{ if or .AutoRules .ManualRules }}<details><summary><b>Debug</b></summary><blockquote>
Expand Down
21 changes: 21 additions & 0 deletions contribs/github-bot/internal/conditions/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,24 @@ func (a *authorInTeam) IsMet(pr *github.PullRequest, details treeprint.Tree) boo
func AuthorInTeam(gh *client.GitHub, team string) Condition {
return &authorInTeam{gh: gh, team: team}
}

type authorAssociationIs struct {
assoc string
}

var _ Condition = &authorAssociationIs{}

func (a *authorAssociationIs) IsMet(pr *github.PullRequest, details treeprint.Tree) bool {
detail := fmt.Sprintf("Pull request author has author_association: %q", a.assoc)

return utils.AddStatusNode(pr.GetAuthorAssociation() == a.assoc, detail, details)
}

// AuthorAssociationIs asserts that the author of the PR has the given value for
// the GitHub "author association" field, on the PR.
//
// See https://docs.github.com/en/graphql/reference/enums#commentauthorassociation
// for a list of possible values and descriptions.
func AuthorAssociationIs(association string) Condition {
return &authorAssociationIs{assoc: association}
}
27 changes: 27 additions & 0 deletions contribs/github-bot/internal/conditions/author_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,30 @@ func TestAuthorInTeam(t *testing.T) {
})
}
}

func TestAuthorAssociationIs(t *testing.T) {
t.Parallel()

for _, testCase := range []struct {
name string
association string
associationWant string
isMet bool
}{
{"has", "MEMBER", "MEMBER", true},
{"hasNot", "COLLABORATOR", "MEMBER", false},
} {
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

pr := &github.PullRequest{
AuthorAssociation: github.String(testCase.association),
}
details := treeprint.New()
condition := AuthorAssociationIs(testCase.associationWant)

assert.Equal(t, condition.IsMet(pr, details), testCase.isMet, fmt.Sprintf("condition should have a met status: %t", testCase.isMet))
assert.True(t, utils.TestLastNodeStatus(t, testCase.isMet, details), fmt.Sprintf("condition details should have a status: %t", testCase.isMet))
})
}
}
2 changes: 1 addition & 1 deletion contribs/github-bot/internal/conditions/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Draft Condition.
type draft struct{}

var _ Condition = &baseBranch{}
var _ Condition = &draft{}

func (*draft) IsMet(pr *github.PullRequest, details treeprint.Tree) bool {
return utils.AddStatusNode(pr.GetDraft(), "This pull request is a draft", details)
Expand Down
44 changes: 35 additions & 9 deletions contribs/github-bot/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gnolang/gno/contribs/github-bot/internal/client"
c "github.com/gnolang/gno/contribs/github-bot/internal/conditions"
r "github.com/gnolang/gno/contribs/github-bot/internal/requirements"
"github.com/gnolang/gno/contribs/github-bot/internal/utils"
)

type Teams []string
Expand Down Expand Up @@ -38,17 +39,39 @@ func Config(gh *client.GitHub) ([]AutomaticCheck, []ManualCheck) {
{
Description: "Changes to 'docs' folder must be reviewed/authored by at least one devrel and one tech-staff",
If: c.FileChanged(gh, "^docs/"),
Then: r.Or(
r.And(
r.AuthorInTeam(gh, "devrels"),
r.ReviewByTeamMembers(gh, "tech-staff", 1),
),
r.And(
Then: r.And(
r.Or(
r.AuthorInTeam(gh, "tech-staff"),
r.ReviewByTeamMembers(gh, "devrels", 1),
r.ReviewByTeamMembers(gh, "tech-staff").WithDesiredState(utils.ReviewStateApproved),
),
r.Or(
r.AuthorInTeam(gh, "devrels"),
r.ReviewByTeamMembers(gh, "devrels").WithDesiredState(utils.ReviewStateApproved),
),
),
},
{
Description: "Must not contain the \"don't merge\" label",
If: c.Label("don't merge"),
Then: r.Never(),
},
{
Description: "Pending initial approval by a review team member, or review from tech-staff",
If: c.Not(c.AuthorInTeam(gh, "tech-staff")),
Then: r.
If(r.Or(
r.ReviewByOrgMembers(gh).WithDesiredState(utils.ReviewStateApproved),
r.ReviewByTeamMembers(gh, "tech-staff"),
r.Draft(),
)).
// Either there was a first approval from a member, and we
// assert that the label for triage-pending is removed...
Then(r.Not(r.Label(gh, "review/triage-pending", r.LabelRemove))).
// Or there was not, and we apply the triage pending label.
// The requirement should always fail, to mark the PR is not
// ready to be merged.
Else(r.And(r.Label(gh, "review/triage-pending", r.LabelApply), r.Never())),
},
}

manual := []ManualCheck{
Expand All @@ -59,8 +82,11 @@ func Config(gh *client.GitHub) ([]AutomaticCheck, []ManualCheck) {
},
{
Description: "The pull request description provides enough details",
If: c.Not(c.AuthorInTeam(gh, "core-contributors")),
Teams: Teams{"core-contributors"},
If: c.And(
c.Not(c.AuthorInTeam(gh, "core-contributors")),
c.Not(c.Author("dependabot[bot]")),
),
Teams: Teams{"core-contributors"},
},
{
Description: "Determine if infra needs to be updated before merging",
Expand Down
66 changes: 66 additions & 0 deletions contribs/github-bot/internal/requirements/boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,69 @@ func (n *not) IsSatisfied(pr *github.PullRequest, details treeprint.Tree) bool {
func Not(req Requirement) Requirement {
return &not{req}
}

// IfCondition executes the condition, and based on the result then runs Then
// or Else.
type IfCondition struct {
cond Requirement
then Requirement
els Requirement
}

var _ Requirement = &IfCondition{}

func (i *IfCondition) IsSatisfied(pr *github.PullRequest, details treeprint.Tree) bool {
if i.then == nil {
i.then = Always()
}
ifBranch := details.AddBranch("")
condBranch := ifBranch.AddBranch("")

var (
target Requirement
targetName string
)

if i.cond.IsSatisfied(pr, condBranch) {
condBranch.SetValue(fmt.Sprintf("%s Condition", utils.Success))
target, targetName = i.then, "Then"
} else {
condBranch.SetValue(fmt.Sprintf("%s Condition", utils.Fail))
target, targetName = i.els, "Else"
}

targBranch := ifBranch.AddBranch("")
if target == nil || target.IsSatisfied(pr, targBranch) {
ifBranch.SetValue(fmt.Sprintf("%s If", utils.Success))
targBranch.SetValue(fmt.Sprintf("%s %s", utils.Success, targetName))
return true
} else {
ifBranch.SetValue(fmt.Sprintf("%s If", utils.Fail))
targBranch.SetValue(fmt.Sprintf("%s %s", utils.Fail, targetName))
return false
}
}

// If returns a conditional requirement, which runs Then if cond evaluates
// successfully, or Else otherwise.
//
// Then / Else are optional, and always evaluate to true by default.
func If(cond Requirement) *IfCondition {
return &IfCondition{cond: cond}
}

func (i *IfCondition) Then(then Requirement) *IfCondition {
if i.then != nil {
panic("'Then' is already set")
}
i.then = then
return i
}

func (i *IfCondition) Else(els Requirement) *IfCondition {
if i.els != nil {
panic("'Else' is already set")
}
i.els = els
return i
}
Loading

0 comments on commit eb85c50

Please sign in to comment.