-
Notifications
You must be signed in to change notification settings - Fork 3.9k
ops: add check-op-geth-version CI check #18854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "regexp" | ||
|
|
||
| "golang.org/x/mod/modfile" | ||
|
|
||
| opservice "github.com/ethereum-optimism/optimism/op-service" | ||
| ) | ||
|
|
||
| const ( | ||
| goEthereumPath = "github.com/ethereum/go-ethereum" | ||
| opGethPath = "github.com/ethereum-optimism/op-geth" | ||
| ) | ||
|
|
||
| // The op-geth minor version encodes the upstream geth version as exactly 6 digits: | ||
| // - 2 digits for geth major version (zero-padded) | ||
| // - 2 digits for geth minor version (zero-padded) | ||
| // - 2 digits for geth patch version (zero-padded) | ||
| // | ||
| // Examples: | ||
| // - v1.101407.0 -> geth v1.14.7 | ||
| // - v1.101605.0-rc.2 -> geth v1.16.5 | ||
| var opGethVersionPattern = regexp.MustCompile(`^v\d+\.\d{6}\.\d+(-rc\.\d+)?$`) | ||
|
|
||
| func main() { | ||
| if err := run("."); err != nil { | ||
| fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| func run(dir string) error { | ||
| root, err := opservice.FindMonorepoRoot(dir) | ||
| if err != nil { | ||
| return fmt.Errorf("finding monorepo root: %w", err) | ||
| } | ||
|
|
||
| goModPath := filepath.Join(root, "go.mod") | ||
| content, err := os.ReadFile(goModPath) | ||
| if err != nil { | ||
| return fmt.Errorf("reading go.mod: %w", err) | ||
| } | ||
|
|
||
| modFile, err := modfile.Parse(goModPath, content, nil) | ||
| if err != nil { | ||
| return fmt.Errorf("parsing go.mod: %w", err) | ||
| } | ||
|
|
||
| // Find the replace directive for go-ethereum -> op-geth | ||
| var opGethVersion string | ||
| for _, rep := range modFile.Replace { | ||
| if rep.Old.Path == goEthereumPath { | ||
| if rep.New.Path != opGethPath { | ||
| return fmt.Errorf("go-ethereum replacement must point to %s, got %s", opGethPath, rep.New.Path) | ||
| } | ||
| opGethVersion = rep.New.Version | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if opGethVersion == "" { | ||
| return fmt.Errorf("no replace directive found for %s", goEthereumPath) | ||
| } | ||
|
|
||
| if !opGethVersionPattern.MatchString(opGethVersion) { | ||
| return fmt.Errorf("invalid op-geth version %q", opGethVersion) | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestRun(t *testing.T) { | ||
| tests := map[string]string{ | ||
| "valid": "", | ||
| "valid-rc": "", | ||
| "invalid-version": "invalid op-geth version", | ||
| "invalid-geth-encoding": "invalid op-geth version", | ||
| "wrong-replacement": "must point to github.com/ethereum-optimism/op-geth", | ||
| "no-replacement": "no replace directive found", | ||
| } | ||
| for name, errContains := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| testDir, err := filepath.Abs(filepath.Join("testdata", name)) | ||
| require.NoError(t, err) | ||
| if err = run(testDir); errContains == "" { | ||
| require.NoError(t, err) | ||
| } else { | ||
| require.Error(t, err) | ||
| require.ErrorContains(t, err, errContains) | ||
| } | ||
| }) | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
ops/scripts/check-op-geth-version/testdata/invalid-geth-encoding/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module github.com/ethereum-optimism/optimism | ||
|
|
||
| go 1.22.0 | ||
|
|
||
| replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.11407.0 |
5 changes: 5 additions & 0 deletions
5
ops/scripts/check-op-geth-version/testdata/invalid-version/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module github.com/ethereum-optimism/optimism | ||
|
|
||
| go 1.22.0 | ||
|
|
||
| replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101605.0-beta.1 |
3 changes: 3 additions & 0 deletions
3
ops/scripts/check-op-geth-version/testdata/no-replacement/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module github.com/ethereum-optimism/optimism | ||
|
|
||
| go 1.22.0 |
5 changes: 5 additions & 0 deletions
5
ops/scripts/check-op-geth-version/testdata/pseudoversion/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module github.com/ethereum-optimism/optimism | ||
|
|
||
| go 1.22.0 | ||
|
|
||
| replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101605.1-0.20260113212524-7f3b615ab10d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module github.com/ethereum-optimism/optimism | ||
|
|
||
| go 1.22.0 | ||
|
|
||
| replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101605.0-rc.2 | ||
joshklop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module github.com/ethereum-optimism/optimism | ||
|
|
||
| go 1.22.0 | ||
|
|
||
| replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101605.0 |
5 changes: 5 additions & 0 deletions
5
ops/scripts/check-op-geth-version/testdata/wrong-replacement/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module github.com/ethereum-optimism/optimism | ||
|
|
||
| go 1.22.0 | ||
|
|
||
| replace github.com/ethereum/go-ethereum => github.com/some-other/fork v1.0.0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.