Skip to content

Commit

Permalink
tools: Run the Cross Repo Type Checker in C.I. (#5326)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaffi committed May 9, 2023
1 parent 7920f21 commit 6bfe03a
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ testresults.json
tools/block-generator/block-generator

# cross repo types tool binary
tools/x-repo-types/xrt
tools/x-repo-types/x-repo-types
14 changes: 7 additions & 7 deletions tools/x-repo-types/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ all: goal-v-sdk goal-v-spv
goal-v-sdk: goal-v-sdk-state-delta goal-v-sdk-genesis goal-v-sdk-block goal-v-sdk-blockheader goal-v-sdk-stateproof

goal-v-sdk-state-delta:
./xrt --x-package "github.com/algorand/go-algorand/ledger/ledgercore" \
x-repo-types --x-package "github.com/algorand/go-algorand/ledger/ledgercore" \
--x-type "StateDelta" \
--y-branch "develop" \
--y-package "github.com/algorand/go-algorand-sdk/v2/types" \
--y-type "LedgerStateDelta"

goal-v-sdk-genesis:
./xrt --x-package "github.com/algorand/go-algorand/data/bookkeeping" \
x-repo-types --x-package "github.com/algorand/go-algorand/data/bookkeeping" \
--x-type "Genesis" \
--y-branch "develop" \
--y-package "github.com/algorand/go-algorand-sdk/v2/types" \
--y-type "Genesis"

goal-v-sdk-block:
./xrt --x-package "github.com/algorand/go-algorand/data/bookkeeping" \
x-repo-types --x-package "github.com/algorand/go-algorand/data/bookkeeping" \
--x-type "Block" \
--y-branch "develop" \
--y-package "github.com/algorand/go-algorand-sdk/v2/types" \
--y-type "Block"

goal-v-sdk-blockheader:
./xrt --x-package "github.com/algorand/go-algorand/data/bookkeeping" \
x-repo-types --x-package "github.com/algorand/go-algorand/data/bookkeeping" \
--x-type "BlockHeader" \
--y-branch "develop" \
--y-package "github.com/algorand/go-algorand-sdk/v2/types" \
--y-type "BlockHeader"

goal-v-sdk-stateproof:
./xrt --x-package "github.com/algorand/go-algorand/crypto/stateproof" \
x-repo-types --x-package "github.com/algorand/go-algorand/crypto/stateproof" \
--x-type "StateProof" \
--y-branch "develop" \
--y-package "github.com/algorand/go-algorand-sdk/v2/types" \
Expand All @@ -44,15 +44,15 @@ goal-v-sdk-stateproof:
goal-v-spv: goal-v-spv-stateproof

goal-v-spv-stateproof:
./xrt --x-package "github.com/algorand/go-algorand/crypto/stateproof" \
x-repo-types --x-package "github.com/algorand/go-algorand/crypto/stateproof" \
--x-type "StateProof" \
--y-package "github.com/algorand/go-stateproof-verification/stateproof" \
--y-type "StateProof"

# reset typeAnalyzer/main.go for passing checks:

reset-dummy-main:
./xrt --x-package "github.com/algorand/go-algorand/ledger/ledgercore" \
x-repo-types --x-package "github.com/algorand/go-algorand/ledger/ledgercore" \
--x-type "StateDelta" \
--y-package "github.com/algorand/go-algorand/data/bookkeeping" \
--y-type "Genesis"
12 changes: 3 additions & 9 deletions tools/x-repo-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
Given two types **X** and **Y** from separate repositories, compare the types and generate a report of any differences to the serialized shape of the types. In particular it ignores different embedding of structs, different field names if `codec` tags are used, and different types if they map to the same primitives.
This tool is designed to be used in CI systems to alert us if a change is made to one repo without a corresponding change to another. For example the `Genesis` type in `go-algorand` and `go-algorand-sdk`. See the [Makefile](./Makefile) for additional examples.

## Build the `xrt` binary

```sh
go build -o xrt
```

## Example run

```sh
goal-v-sdk-state-delta-xrt:
./xrt --x-package "github.com/algorand/go-algorand/ledger/ledgercore" \
x-repo-types --x-package "github.com/algorand/go-algorand/ledger/ledgercore" \
--x-type "StateDelta" \
--y-branch "develop" \
--y-package "github.com/algorand/go-algorand-sdk/v2/types" \
Expand All @@ -24,8 +18,8 @@ goal-v-sdk-state-delta-xrt:

### Cross Type Comparison Process

1. Inside of `tools/x-repo-types` run the command `./xrt --x-package X_PACKAGE_NAME ...`
2. `xrt` then does the following:
1. Inside of `tools/x-repo-types` run the command `x-repo-types --x-package X_PACKAGE_NAME ...`
2. `x-repo-types` then does the following:
1. `go get`'s the package
2. Populates the template `typeAnalyzer/main.tmpl` with comparison types
3. Saves it in `typeAnalyzer/main.go`
Expand Down
20 changes: 20 additions & 0 deletions tools/x-repo-types/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/algorand/go-algorand/tools/x-repo-types

go 1.17

replace github.com/algorand/go-algorand => ../..

require (
github.com/algorand/go-algorand v0.0.0-20230502140608-e24a35add0bb
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 29 additions & 0 deletions tools/x-repo-types/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 6 additions & 6 deletions tools/x-repo-types/typeAnalyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/*
WARNING
THIS FILE ONLY EXISTS FOR DEBUGGING AND TO MAKE THE BUILD HAPPY
!!!!! IT IS OVERWRITTEN BY AT RUNTIME !!!!!
!!!!! IT IS OVERWRITTEN AT RUNTIME !!!!!
*/

package main
Expand All @@ -26,13 +26,13 @@ import (
"fmt"
"os"

ypkg "github.com/algorand/go-algorand/data/bookkeeping"
xpkg "github.com/algorand/go-algorand/ledger/ledgercore"
xpkg "net/http"
ypkg "time"
)

func main() {
xRoot := MakeType(xpkg.StateDelta{})
yRoot := MakeType(ypkg.Genesis{})
xRoot := MakeType(xpkg.Request{})
yRoot := MakeType(ypkg.Time{})

// ---- BUILD ---- //
x, y := xRoot.Type, yRoot.Type
Expand Down Expand Up @@ -71,7 +71,7 @@ func main() {
// ---- DIFF ---- //

fmt.Printf("\n\nCompare the Type Trees %q v %q\n", x, y)
xType, yType, diff, err := StructDiff(xpkg.StateDelta{}, ypkg.Genesis{}, diffExclusions)
xType, yType, diff, err := StructDiff(xpkg.Request{}, ypkg.Time{}, diffExclusions)
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions tools/x-repo-types/typeAnalyzer/typeAnalyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func Report(x, y TypeNode, d *Diff) string {

sb.WriteString(`
========================================================
REPORT
STRUCT DIFF REPORT
comparing
<<<<<`)
sb.WriteString(x.String())
Expand Down Expand Up @@ -469,7 +469,7 @@ SOURCE: %s
}
sb.WriteString(`
========================================================
=============== REPORT END ===============
=============== STRUCT DIFF REPORT END ===============
========================================================`)

return sb.String()
Expand Down
Loading

0 comments on commit 6bfe03a

Please sign in to comment.