-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Automate Node Upgrade Process: Update Script #478
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 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81daf9f
Automate Updates Script
JenabaBa 03d9b08
add versions.env
JenabaBa 9fa44e2
delete dependency_updater
JenabaBa 8cee8bd
dependency updater script updates
JenabaBa a378a95
Merge branch 'main' into Automate-Updates-Script
JenabaBa 1772cc9
Add retries/fix commit hash
danyalprout 6763ab7
Single client
danyalprout a3d699b
Sorted env file
danyalprout 16765a3
Fix dockerfile
danyalprout 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ | |
| /geth-data/ | ||
| /reth-data/ | ||
| /nethermind-data/ | ||
| /dependency_updater/dependency_updater | ||
| .DS_Store | ||
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,222 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| "log" | ||
| "context" | ||
| "github.com/urfave/cli/v3" | ||
| "github.com/google/go-github/v72/github" | ||
| ) | ||
|
|
||
| type Info struct { | ||
| RepoUrl string `json:"repoUrl"` | ||
| Tag string `json:"tag"` | ||
| Commit string `json:"commit"` | ||
| CommitUrl string `json:"commitUrl"` | ||
| VersionUrl string `json:"versionUrl"` | ||
| TagPrefix *string `json:"tagPrefix,omitempty"` | ||
| Owner string `json:"owner` | ||
| Repo string `json:"repo` | ||
| } | ||
|
|
||
| type VersionTag []struct { | ||
| Tag string `json:"tag_name"` | ||
| } | ||
|
|
||
| type Commit struct { | ||
| Commit string `json:"sha"` | ||
| } | ||
|
|
||
| type Dependencies = map[string]*Info | ||
|
|
||
| func main() { | ||
| cmd := &cli.Command { | ||
| Name: "updater", | ||
| Usage: "Updates the dependencies in the geth, nethermind and reth Dockerfiles", | ||
| Flags: | ||
| []cli.Flag{ | ||
| &cli.StringFlag { | ||
| Name: "token", | ||
| Usage: "Auth token used to make requests to the Github API must be set using export", | ||
| Sources: cli.EnvVars("GITHUB_TOKEN"), | ||
| Required: true, | ||
| }, | ||
| &cli.StringFlag { | ||
| Name: "repo", | ||
| Usage: "Specifies repo location to run the version updater on", | ||
| Required: true, | ||
| }, | ||
| }, | ||
| Action: func(ctx context.Context, cmd *cli.Command) error { | ||
| err := updater(string(cmd.String("token")), string(cmd.String("repo"))) | ||
| if err != nil { | ||
| return fmt.Errorf("error running updater: %s", err) | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| if err := cmd.Run(context.Background(), os.Args); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } | ||
|
|
||
| func updater(token string, repoPath string) error { | ||
| var err error | ||
|
|
||
| f, err := os.ReadFile(repoPath + "/versions.json") | ||
| if err != nil { | ||
| return fmt.Errorf("error reading versions JSON: %s", err) | ||
| } | ||
|
|
||
| var dependencies Dependencies | ||
|
|
||
| err = json.Unmarshal(f, &dependencies) | ||
| if err != nil { | ||
| return fmt.Errorf("error unmarshaling versions JSON to dependencies: %s", err) | ||
| } | ||
|
|
||
| for dependency := range dependencies { | ||
| err = getAndUpdateDependency( | ||
| dependency, | ||
| token, | ||
| repoPath, | ||
| dependencies, | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("error getting and updating version/commit for " + dependency + ": %s", err) | ||
| } | ||
| } | ||
|
|
||
| e := createVersionsEnv(repoPath, dependencies) | ||
| if e != nil { | ||
| return fmt.Errorf("error creating versions.env: %s", e) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func getAndUpdateDependency( | ||
| dependencyType string, | ||
| token string, | ||
| repoPath string, | ||
| dependencies Dependencies) error { | ||
| version, commit, _ := getVersionAndCommit(token, dependencies, dependencyType) | ||
|
|
||
| e := updateVersionTagAndCommit(commit, version, dependencyType, repoPath, dependencies) | ||
| if e != nil { | ||
| return fmt.Errorf("error updating version tag and commit: %s", e) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func getVersionAndCommit(token string, dependencies Dependencies, dependencyType string) (string, string, error){ | ||
| client := github.NewClient(nil).WithAuthToken(token) | ||
| ctx := context.Background() | ||
|
|
||
| var version *github.RepositoryRelease | ||
| var err error | ||
| // handle dependencies with prefix | ||
| if dependencies[dependencyType].TagPrefix != nil { | ||
| releases, _, err := client.Repositories.ListReleases( | ||
| ctx, | ||
| dependencies[dependencyType].Owner, | ||
| dependencies[dependencyType].Repo, | ||
| nil) | ||
|
|
||
| if err != nil { | ||
| return "", "", fmt.Errorf("error getting releases: %s", err) | ||
| } | ||
|
|
||
| for release := range releases { | ||
| if strings.HasPrefix(*releases[release].TagName, *dependencies[dependencyType].TagPrefix){ | ||
| version = releases[release] | ||
| break | ||
| } | ||
| } | ||
| } else { | ||
| release, _, err := client.Repositories.GetLatestRelease( | ||
| ctx, | ||
| dependencies[dependencyType].Owner, | ||
| dependencies[dependencyType].Repo) | ||
| if err != nil { | ||
| return "", "", fmt.Errorf("error getting releases: %s", err) | ||
| } | ||
| version = release | ||
| } | ||
|
|
||
| commit, _, err := client.Git.GetRef( | ||
| ctx, | ||
| dependencies[dependencyType].Owner, | ||
| dependencies[dependencyType].Repo, | ||
| "refs/tags/"+*version.TagName) | ||
| if err != nil { | ||
| return "", "", fmt.Errorf("error getting commit for "+dependencyType + ": %s", err) | ||
| } | ||
|
|
||
| return *version.TagName, *commit.Object.SHA, nil | ||
| } | ||
|
|
||
| func updateVersionTagAndCommit( | ||
| commit string, | ||
| tag string, | ||
| dependencyType string, | ||
| repoPath string, | ||
| dependencies Dependencies) error { | ||
| dependencies[dependencyType].Tag = tag | ||
| dependencies[dependencyType].Commit = commit | ||
| err := writeToVersionsEnv(repoPath, dependencies) | ||
| if err != nil { | ||
| return fmt.Errorf("error writing to versions " + dependencyType + ": %s", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func writeToVersionsEnv(repoPath string, dependencies Dependencies) error { | ||
| // formatting json | ||
| updatedJson, err := json.MarshalIndent(dependencies, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("error Marshaling dependencies json: %s", err) | ||
| } | ||
|
|
||
| e := os.WriteFile(repoPath + "/versions.json", updatedJson, 0644) | ||
| if e != nil { | ||
| return fmt.Errorf("error writing to versions.json: %s", e) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func createVersionsEnv(repoPath string, dependencies Dependencies) error { | ||
| envLines := []string{} | ||
|
|
||
| for dependency := range dependencies { | ||
| dependencyPrefix := strings.ToUpper(dependency) | ||
|
|
||
| envLines = append(envLines, fmt.Sprintf("export %s_%s=%s \n", | ||
| dependencyPrefix, "TAG", dependencies[dependency].Tag)) | ||
|
|
||
| envLines = append(envLines, fmt.Sprintf("export %s_%s=%s \n", | ||
| dependencyPrefix, "COMMIT", dependencies[dependency].Commit)) | ||
|
|
||
| envLines = append(envLines, fmt.Sprintf("export %s_%s=%s \n\n", | ||
| dependencyPrefix, "REPO", dependencies[dependency].RepoUrl)) | ||
| } | ||
|
|
||
| file, err := os.Create(repoPath + "/versions.env") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can use path.join to make this support multi-platforms in the future see: https://pkg.go.dev/path#Join |
||
| if err != nil { | ||
| return fmt.Errorf("error creating versions.env file: %s", err) | ||
| } | ||
| defer file.Close() | ||
|
|
||
| _, err = file.WriteString(strings.Join(envLines, " ")) | ||
| if err != nil { | ||
| return fmt.Errorf("error writing to versions.env file: %s", err) | ||
| } | ||
|
|
||
| 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,10 @@ | ||
| module dependency_updater | ||
|
|
||
| go 1.24.3 | ||
|
|
||
| require ( | ||
| github.com/google/go-github/v72 v72.0.0 | ||
| github.com/urfave/cli/v3 v3.3.8 | ||
| ) | ||
|
|
||
| require github.com/google/go-querystring v1.1.0 // indirect |
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,18 @@ | ||
| 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/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
| github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= | ||
| github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= | ||
| github.com/google/go-github/v72 v72.0.0 h1:FcIO37BLoVPBO9igQQ6tStsv2asG4IPcYFi655PPvBM= | ||
| github.com/google/go-github/v72 v72.0.0/go.mod h1:WWtw8GMRiL62mvIquf1kO3onRHeWWKmK01qdCY8c5fg= | ||
| github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= | ||
| github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= | ||
| 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/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||
| github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
| github.com/urfave/cli/v3 v3.3.8 h1:BzolUExliMdet9NlJ/u4m5vHSotJ3PzEqSAZ1oPMa/E= | ||
| github.com/urfave/cli/v3 v3.3.8/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo= | ||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
| gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
| gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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 dependency_updater | ||
|
|
||
| go 1.24.3 |
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 |
|---|---|---|
| @@ -1,20 +1,20 @@ | ||
| export OP_NODE_TAG=op-node/v1.13.3 | ||
| export OP_NODE_COMMIT=b1e7c63bb2ffea46771c302bcb05f72ba1a7bf61 | ||
| export OP_NODE_REPO=https://github.com/ethereum-optimism/optimism.git | ||
| export BASE_RETH_NODE_TAG=v0.1.2 | ||
| export BASE_RETH_NODE_COMMIT=7fe1d4e7c74d322d2cf78df55db40e14f466cfc6 | ||
| export BASE_RETH_NODE_REPO=https://github.com/base/node-reth.git | ||
|
|
||
| export OP_GETH_TAG=v1.101511.0 | ||
| export OP_GETH_COMMIT=68075997f33907401a93216aa426514c5ddc8870 | ||
| export OP_GETH_REPO=https://github.com/ethereum-optimism/op-geth.git | ||
| export NETHERMIND_TAG=1.31.11 | ||
| export NETHERMIND_COMMIT=2be1890ee4f21f921a471de058dcb57937bd9b90 | ||
| export NETHERMIND_REPO=https://github.com/NethermindEth/nethermind.git | ||
|
|
||
| export OP_RETH_TAG=v1.4.3 | ||
| export OP_RETH_COMMIT=fe3653ffe602d4e85ad213e8bd9f06e7b710c0c5 | ||
| export OP_RETH_REPO=https://github.com/paradigmxyz/reth.git | ||
| export OP_GETH_TAG=v1.101511.0 | ||
| export OP_GETH_COMMIT=0849d14d22f33d5ef8a872d7dbcaa68d8b085b96 | ||
| export OP_GETH_REPO=https://github.com/ethereum-optimism/op-geth.git | ||
|
|
||
| export NETHERMIND_TAG=1.31.11 | ||
| export NETHERMIND_COMMIT=2be1890ee4f21f921a471de058dcb57937bd9b90 | ||
| export NETHERMIND_REPO=https://github.com/NethermindEth/nethermind.git | ||
| export OP_NODE_TAG=op-node/v1.13.3 | ||
| export OP_NODE_COMMIT=80988e1892a7e8cdb8a35e38cdb4509afc6eec50 | ||
| export OP_NODE_REPO=https://github.com/ethereum-optimism/optimism.git | ||
|
|
||
| export BASE_RETH_NODE_TAG=v0.1.2 | ||
| export BASE_RETH_NODE_COMMIT=7fe1d4e7c74d322d2cf78df55db40e14f466cfc6 | ||
| export BASE_RETH_NODE_REPO=https://github.com/base/node-reth.git | ||
| export OP_RETH_TAG=v1.4.8 | ||
| export OP_RETH_COMMIT=127595e23079de2c494048d0821ea1f1107eb624 | ||
| export OP_RETH_REPO=https://github.com/paradigmxyz/reth.git | ||
|
|
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,48 @@ | ||
| { | ||
| "base_reth_node": { | ||
| "repoUrl": "https://github.com/base/node-reth.git", | ||
| "tag": "v0.1.2", | ||
| "commit": "7fe1d4e7c74d322d2cf78df55db40e14f466cfc6", | ||
| "commitUrl": "https://api.github.com/repos/base/node-reth/commits/", | ||
| "versionUrl": "https://api.github.com/repos/base/node-reth/releases", | ||
| "Owner": "base", | ||
| "Repo": "node-reth" | ||
| }, | ||
| "nethermind": { | ||
| "repoUrl": "https://github.com/NethermindEth/nethermind.git", | ||
| "tag": "1.31.11", | ||
| "commit": "2be1890ee4f21f921a471de058dcb57937bd9b90", | ||
| "commitUrl": "https://api.github.com/repos/NethermindEth/nethermind/commits/", | ||
| "versionUrl": "https://api.github.com/repos/NethermindEth/nethermind/releases", | ||
| "Owner": "NethermindEth", | ||
| "Repo": "nethermind" | ||
| }, | ||
| "op_geth": { | ||
| "repoUrl": "https://github.com/ethereum-optimism/op-geth.git", | ||
| "tag": "v1.101511.0", | ||
| "commit": "0849d14d22f33d5ef8a872d7dbcaa68d8b085b96", | ||
| "commitUrl": "https://api.github.com/repos/ethereum-optimism/op-geth/commits/", | ||
| "versionUrl": "https://api.github.com/repos/ethereum-optimism/op-geth/releases", | ||
| "Owner": "ethereum-optimism", | ||
| "Repo": "op-geth" | ||
| }, | ||
| "op_node": { | ||
| "repoUrl": "https://github.com/ethereum-optimism/optimism.git", | ||
| "tag": "op-node/v1.13.3", | ||
| "commit": "80988e1892a7e8cdb8a35e38cdb4509afc6eec50", | ||
| "commitUrl": "https://api.github.com/repos/ethereum-optimism/optimism/commits/", | ||
| "versionUrl": "https://api.github.com/repos/ethereum-optimism/optimism/releases", | ||
| "tagPrefix": "op-node", | ||
| "Owner": "ethereum-optimism", | ||
| "Repo": "optimism" | ||
| }, | ||
| "op_reth": { | ||
| "repoUrl": "https://github.com/paradigmxyz/reth.git", | ||
| "tag": "v1.4.8", | ||
| "commit": "127595e23079de2c494048d0821ea1f1107eb624", | ||
| "commitUrl": "https://api.github.com/repos/paradigmxyz/reth/commits/", | ||
| "versionUrl": "https://api.github.com/repos/paradigmxyz/reth/releases", | ||
| "Owner": "paradigmxyz", | ||
| "Repo": "reth" | ||
| } | ||
| } |
Oops, something went wrong.
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.