Skip to content

Commit f3b3755

Browse files
authored
Add genesis diff tool to report any changes made to genesis files (#378)
* Hoist validation diff-configs.sh to shared scripts dir * Add validation/generate-genesis tool * Update .gitignore * Add github action for genesis-diff
1 parent 2293a72 commit f3b3755

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

.github/workflows/genesis-diff.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Genesis Diff
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
compute-genesis-diff:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0 # Ensure the full history is fetched
16+
17+
- name: Fetch all branches
18+
run: git fetch --all
19+
20+
- name: Generate configs at HEAD
21+
working-directory: validation
22+
run: |
23+
go run generate-genesis/main.go HEAD
24+
25+
- name: Generate configs on base branch
26+
working-directory: validation
27+
run: |
28+
# Get the base branch revision
29+
base_rev=${{ github.event.pull_request.base.sha }}
30+
echo "Base branch revision: $base_rev"
31+
git checkout $base_rev -- ../superchain
32+
go run generate-genesis/main.go base
33+
34+
- name: compute diff
35+
working-directory: validation
36+
id: run-command
37+
run: |
38+
./scripts/diff-configs.sh ./generate-genesis/output-base ./generate-genesis/output-HEAD
39+

.github/workflows/rollup-config-diff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ jobs:
3535
working-directory: validation
3636
id: run-command
3737
run: |
38-
./generate-rollup-config/diff-configs.sh ./generate-rollup-config/output-base ./generate-rollup-config/output-HEAD
38+
./scripts/diff-configs.sh ./generate-rollup-config/output-base ./generate-rollup-config/output-HEAD
3939

validation/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
generate-rollup-config/output-*
2+
generate-genesis/output-*
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"os"
7+
"path"
8+
9+
"github.com/ethereum-optimism/superchain-registry/superchain"
10+
"github.com/ethereum/go-ethereum/core"
11+
)
12+
13+
func main() {
14+
rev := os.Args[1]
15+
16+
for chainID, chain := range superchain.OPChains {
17+
gethGenesis, err := core.LoadOPStackGenesis(chainID)
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
j, err := json.MarshalIndent(gethGenesis, "", " ")
23+
if err != nil {
24+
panic(err)
25+
}
26+
27+
dirPath := "./generate-genesis/output-" + rev
28+
29+
// Create the directory if it doesn't exist
30+
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
31+
err := os.MkdirAll(dirPath, 0o755)
32+
if err != nil {
33+
log.Fatalf("Error creating directory: %v", err)
34+
}
35+
}
36+
37+
err = os.WriteFile(path.Join(dirPath, chain.Superchain+"-"+chain.Name+".json"), j, os.FileMode(0o644))
38+
if err != nil {
39+
panic(err)
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)