-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (150 loc) · 5.67 KB
/
Copy pathupdate.yml
File metadata and controls
174 lines (150 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Update Bootstrap Node Lists
on:
schedule:
# Run every 6 hours. The check job uses the GitHub API to detect whether
# all.json has actually changed before downloading the large file.
- cron: '0 */6 * * *'
push:
branches:
- main
paths:
- 'chains_config.json'
- 'config/**'
- 'main.go'
- 'go.mod'
- 'go.sum'
- 'output/base-mainnet.json'
- 'output/base-sepolia.json'
workflow_dispatch:
inputs:
force:
description: "Force rebuild (skip change detection and assume all.json changed)"
type: boolean
default: false
permissions:
contents: write
env:
ALL_JSON_URL: "https://raw.githubusercontent.com/ethereum/discv4-dns-lists/master/all.json"
ALL_JSON_REPO: "ethereum/discv4-dns-lists"
ALL_JSON_PATH: "all.json"
STATE_FILE: "output/.state"
jobs:
check:
name: Decide whether to run
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.decide.outputs.should_run }}
new_commit: ${{ steps.decide.outputs.new_commit }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Decide (force vs changed)
id: decide
env:
GH_TOKEN: ${{ github.token }}
FORCE: ${{ inputs.force }}
EVENT_NAME: ${{ github.event_name }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "push" ]; then
echo "Config/code change pushed; running update workflow."
echo "should_run=true" >> "$GITHUB_OUTPUT"
echo "new_commit=" >> "$GITHUB_OUTPUT"
exit 0
fi
# If force=true, do not hit the GitHub API at all.
if [ "${FORCE}" = "true" ]; then
echo "Force rebuild requested; skipping change detection."
echo "should_run=true" >> "$GITHUB_OUTPUT"
echo "new_commit=" >> "$GITHUB_OUTPUT"
exit 0
fi
# Use the GitHub API to get the latest commit SHA that touched all.json.
# This is a tiny (~1 KB) API response — no need to download the full file.
LATEST_COMMIT=$(gh api \
"repos/${ALL_JSON_REPO}/commits?path=${ALL_JSON_PATH}&per_page=1" \
--jq '.[0].sha')
if [ -z "$LATEST_COMMIT" ]; then
echo "::error::GitHub API did not return a commit SHA — check rate limits or repo access"
exit 1
fi
OLD_COMMIT=""
if [ -f "$STATE_FILE" ]; then
OLD_COMMIT=$(cat "$STATE_FILE")
fi
echo "Stored commit : ${OLD_COMMIT:0:7}..."
echo "Latest commit : ${LATEST_COMMIT:0:7}..."
if [ -n "$OLD_COMMIT" ] && [ "$LATEST_COMMIT" = "$OLD_COMMIT" ]; then
echo "all.json unchanged — skipping run"
echo "should_run=false" >> "$GITHUB_OUTPUT"
echo "new_commit=$LATEST_COMMIT" >> "$GITHUB_OUTPUT"
else
echo "all.json changed (or first run) — will run"
echo "should_run=true" >> "$GITHUB_OUTPUT"
echo "new_commit=$LATEST_COMMIT" >> "$GITHUB_OUTPUT"
fi
update:
name: Download & filter discv4 node lists
needs: check
if: needs.check.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Download all.json
run: curl -fsSL "$ALL_JSON_URL" -o /tmp/all.json
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Build filter tool
run: go build -o filter_nodes .
- name: Run filter (write output/{chain}.json files)
run: ./filter_nodes -config chains_config.json -input /tmp/all.json
- name: Run discovery summary
run: ./filter_nodes -config chains_config.json -input /tmp/all.json -discover 2>/dev/null || true
- name: Update state file (record processed all.json commit SHA)
# If force=true, we intentionally don't compute/record a new upstream commit.
if: ${{ inputs.force != true && needs.check.outputs.new_commit != '' }}
run: echo "${{ needs.check.outputs.new_commit }}" > "$STATE_FILE"
- name: Commit and push updated node lists
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add output/
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "chore: update bootstrap node lists [skip ci]"
git push
fi
- name: Upload chain_enodes.gz to Cloudflare R2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
run: |
pip install boto3==1.26.137
python3 << 'EOF'
import boto3
import gzip
import os
with open('output/chain_enodes.json', 'rb') as f:
compressed = gzip.compress(f.read())
s3 = boto3.client(
service_name='s3',
endpoint_url=f'https://{os.getenv("ACCOUNT_ID")}.r2.cloudflarestorage.com',
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
region_name='auto',
)
s3.put_object(
Bucket='gnusai',
Key='chain_enodes.json.gz',
Body=compressed,
ContentType='application/json',
ContentEncoding='gzip',
)
print("Upload complete!")
EOF