Skip to content

update-chain-specs

update-chain-specs #10

name: update-chain-specs
on:
schedule:
- cron: '0 0 */3 * *' # 3 days once
workflow_dispatch:
permissions:
contents: write
jobs:
download-and-validate-specs:
runs-on: ubuntu-latest
strategy:
matrix:
rpc-node-address:
[
'wss://rpc.polkadot.io',
'wss://kusama-rpc.polkadot.io',
'wss://westend-rpc.polkadot.io',
'wss://rpc.dotters.network/paseo',
]
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
path: repo
ref: main
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install websocat
run: |
curl -L -O https://github.com/vi/websocat/releases/download/v1.9.0/websocat_linux64
chmod +x websocat_linux64
- name: Download chain spec
run: |
echo '{"id":1,"jsonrpc":"2.0","method":"sync_state_genSyncSpec","params":[true]}' \
| ./websocat_linux64 -n1 -B 99999999 ${{ matrix.rpc-node-address }} > rpc_answer.json
- name: Extract chain spec result
run: cat ./rpc_answer.json | jq .result > chain_spec.json
- name: Get chain ID
id: get-chain-id
run: echo "id=$(jq -r .id ./chain_spec.json)" >> $GITHUB_OUTPUT
- name: Upload failed response
if: ${{ steps.get-chain-id.outputs.id == '' }}
uses: actions/upload-artifact@v4
with:
name: failed-response-${{ github.run_id }}
path: rpc_answer.json
- name: Update chain spec file
if: ${{ steps.get-chain-id.outputs.id != '' }}
run: |
tmp=$(mktemp)
output="./repo/packages/chain-specs/specs/${{ steps.get-chain-id.outputs.id }}.json"
jq --slurpfile downloaded ./chain_spec.json \
'.lightSyncState = $downloaded[0].lightSyncState' "$output" > "$tmp"
mv "$tmp" "$output"
# 🧩 Install only required dependencies
- name: Install dependencies for validation
if: ${{ steps.get-chain-id.outputs.id != '' }}
working-directory: repo
run: |
yarn add @dedot/providers smoldot
# ✅ Validate updated chain spec
- name: Validate updated chain spec
if: ${{ steps.get-chain-id.outputs.id != '' }}
working-directory: repo
run: |
echo "Validating updated chain spec: ${{ steps.get-chain-id.outputs.id }}.json"
node ./packages/chain-specs/scripts/validate-chain-spec.js "./packages/chain-specs/specs/${{ steps.get-chain-id.outputs.id }}.json"
- name: Upload updated chain spec
if: ${{ steps.get-chain-id.outputs.id != '' }}
uses: actions/upload-artifact@v4
with:
name: chain-spec-${{ steps.get-chain-id.outputs.id }}
path: repo/**/${{ steps.get-chain-id.outputs.id }}.json
commit-to-main:
runs-on: ubuntu-latest
needs: download-and-validate-specs
if: ${{ always() }}
steps:
- uses: actions/checkout@v4
with:
path: repo
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4
with:
path: .
- name: Copy updated specs
run: |
cp -r ./chain-spec-*/* ./repo
- name: Commit and push changes
working-directory: repo
run: |
git config user.name "debot"
git config user.email "hello@dedot.dev"
# Add all changes if any
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "feat: update chain specs [auto]"
git push origin main
else
echo "No changes to commit."
fi