Skip to content

Commit 67c9df0

Browse files
author
Brandon Graham
authored
feat: Add sync script to push validator.json files to bucket (#524)
* feat: Adding script to sync validator-info json summary to bucket * Updating workflow path
1 parent e115e2c commit 67c9df0

File tree

2 files changed

+69
-27
lines changed

2 files changed

+69
-27
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Generate and Upload Validator Files
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'mainnet/**.json'
9+
- 'testnet/**.json'
10+
- '!mainnet/mainnet_validators.json'
11+
- '!testnet/testnet_validators.json'
12+
13+
env:
14+
R2_PATH_PREFIX: '' # Set to a path like 'validators/' if you want files under a subdirectory
15+
16+
jobs:
17+
generate-and-upload:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.x'
28+
29+
- name: Run validator generation script
30+
run: python3 scripts/generate_validators_json.py
31+
32+
- name: Install AWS CLI (for S3-compatible upload)
33+
run: |
34+
pip install awscli
35+
36+
- name: Configure AWS CLI for R2
37+
env:
38+
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
39+
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
40+
run: |
41+
aws configure set aws_access_key_id $R2_ACCESS_KEY_ID
42+
aws configure set aws_secret_access_key $R2_SECRET_ACCESS_KEY
43+
aws configure set default.region auto
44+
45+
- name: Upload files to R2
46+
env:
47+
R2_BUCKET_NAME: ${{ secrets.R2_BUCKET_NAME }}
48+
R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }}
49+
run: |
50+
# Upload mainnet validators JSON
51+
aws s3 cp mainnet/mainnet_validators.json s3://${R2_BUCKET_NAME}/validator-info/mainnet/validators.json --endpoint-url $R2_ENDPOINT
52+
53+
# Upload testnet validators JSON
54+
aws s3 cp testnet/testnet_validators.json s3://${R2_BUCKET_NAME}/validator-info/testnet/validators.json --endpoint-url $R2_ENDPOINT
55+
56+
echo "✅ Successfully uploaded validator JSON files to R2"
57+
Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env python3
2-
import csv
32
import json
43
import os
54
import glob
65

76

87
def read_validators(directory):
9-
"""Read all validator JSON files from a directory and return dict mapping secp to name."""
8+
"""Read all validator JSON files from a directory and return dict mapping secp to full validator object."""
109
validators_dict = {}
1110
json_files = glob.glob(os.path.join(directory, "*.json"))
1211

@@ -15,16 +14,15 @@ def read_validators(directory):
1514
with open(json_file, "r") as f:
1615
data = json.load(f)
1716

18-
# Extract fields
19-
name = data.get("name", "").strip()
17+
# Extract secp key
2018
secp = data.get("secp", "")
2119

22-
# Use secp as fallback if name is empty
23-
if not name:
24-
name = secp
20+
# Use secp as fallback for name if name is empty
21+
if not data.get("name", "").strip():
22+
data["name"] = secp
2523

26-
# Map secp key to validator name
27-
validators_dict[secp] = name
24+
# Map secp key to full validator object
25+
validators_dict[secp] = data
2826

2927
except (json.JSONDecodeError, IOError) as e:
3028
print(f"Warning: Failed to read {json_file}: {e}")
@@ -34,25 +32,13 @@ def read_validators(directory):
3432

3533

3634
def write_json(validators_dict, output_file):
37-
"""Write validators to JSON file with secp as key and name as value."""
35+
"""Write validators to JSON file with secp as key and full validator object as value."""
3836
with open(output_file, "w") as f:
3937
json.dump(validators_dict, f, indent=2)
4038

4139
print(f"✅ Generated {output_file} with {len(validators_dict)} validators")
4240

4341

44-
def write_csv(validators_dict, output_file):
45-
"""Write validators to CSV file with secp_key and name columns."""
46-
with open(output_file, "w", newline="") as f:
47-
writer = csv.writer(f)
48-
writer.writerow(["secp_key", "name"])
49-
50-
for secp, name in validators_dict.items():
51-
writer.writerow([secp, name])
52-
53-
print(f"✅ Generated {output_file} with {len(validators_dict)} validators")
54-
55-
5642
def main():
5743
# Get the project root directory (parent of scripts/)
5844
script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -61,16 +47,15 @@ def main():
6147
# Process mainnet validators
6248
mainnet_dir = os.path.join(project_root, "mainnet")
6349
mainnet_validators = read_validators(mainnet_dir)
64-
write_json(mainnet_validators, "mainnet_validators.json")
65-
write_csv(mainnet_validators, "mainnet_validators.csv")
50+
mainnet_json = os.path.join(mainnet_dir, "mainnet_validators.json")
51+
write_json(mainnet_validators, mainnet_json)
6652

6753
# Process testnet validators
6854
testnet_dir = os.path.join(project_root, "testnet")
6955
testnet_validators = read_validators(testnet_dir)
70-
write_json(testnet_validators, "testnet_validators.json")
71-
write_csv(testnet_validators, "testnet_validators.csv")
56+
testnet_json = os.path.join(testnet_dir, "testnet_validators.json")
57+
write_json(testnet_validators, testnet_json)
7258

7359

7460
if __name__ == "__main__":
7561
main()
76-

0 commit comments

Comments
 (0)