|
| 1 | +name: Validate README |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "**" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: validate-readme-${{ github.workflow }}-${{ github.ref }} |
| 13 | + cancel-in-progress: false |
| 14 | + |
| 15 | +jobs: |
| 16 | + validate: |
| 17 | + name: "Validate README" |
| 18 | + runs-on: ubuntu-latest |
| 19 | + timeout-minutes: 20 |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: 20 |
| 28 | + |
| 29 | + - name: Setup pnpm |
| 30 | + uses: pnpm/action-setup@v4 |
| 31 | + with: |
| 32 | + version: 9 |
| 33 | + |
| 34 | + - name: Install Foundry |
| 35 | + uses: foundry-rs/foundry-toolchain@v1 |
| 36 | + with: |
| 37 | + version: nightly |
| 38 | + |
| 39 | + - name: Determine pnpm store path |
| 40 | + id: pnpm-store |
| 41 | + shell: bash |
| 42 | + run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV |
| 43 | + |
| 44 | + - name: Cache pnpm store |
| 45 | + uses: actions/cache@v4 |
| 46 | + with: |
| 47 | + path: ${{ env.STORE_PATH }} |
| 48 | + key: ${{ runner.os }}-node-20-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }} |
| 49 | + restore-keys: | |
| 50 | + ${{ runner.os }}-node-20-pnpm-store- |
| 51 | +
|
| 52 | + - name: Cache node_modules |
| 53 | + id: cache-node-modules |
| 54 | + uses: actions/cache@v4 |
| 55 | + with: |
| 56 | + path: node_modules |
| 57 | + key: ${{ runner.os }}-node-20-node_modules-${{ hashFiles('pnpm-lock.yaml') }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-node-20-node_modules- |
| 60 | +
|
| 61 | + - name: Install dependencies |
| 62 | + if: steps.cache-node-modules.outputs.cache-hit != 'true' |
| 63 | + run: | |
| 64 | + pnpm install --frozen-lockfile --ignore-scripts |
| 65 | +
|
| 66 | + - name: Start Anvil |
| 67 | + run: | |
| 68 | + # Kill any existing anvil processes |
| 69 | + pkill anvil || true |
| 70 | +
|
| 71 | + # Start Anvil with explicit nonce management |
| 72 | + anvil --host 0.0.0.0 --port 8545 --accounts 10 --balance 10000 & |
| 73 | + ANVIL_PID=$! |
| 74 | +
|
| 75 | + # Wait for Anvil to be ready |
| 76 | + echo "Waiting for Anvil to be ready..." |
| 77 | + for i in {1..30}; do |
| 78 | + if curl -s -X POST -H "Content-Type: application/json" \ |
| 79 | + --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' \ |
| 80 | + http://localhost:8545 > /dev/null 2>&1; then |
| 81 | + echo "Anvil is ready!" |
| 82 | + break |
| 83 | + fi |
| 84 | + echo "Attempt $i/30: Anvil not ready yet, waiting 1 second..." |
| 85 | + sleep 1 |
| 86 | + done |
| 87 | +
|
| 88 | + # Final check to ensure Anvil is responding |
| 89 | + if ! curl -s -X POST -H "Content-Type: application/json" \ |
| 90 | + --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' \ |
| 91 | + http://localhost:8545 > /dev/null 2>&1; then |
| 92 | + echo "ERROR: Anvil failed to start properly!" |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | +
|
| 96 | + # Store the PID for cleanup |
| 97 | + echo $ANVIL_PID > anvil.pid |
| 98 | +
|
| 99 | + - name: Reset Nonce and Deploy |
| 100 | + run: | |
| 101 | + set -euo pipefail |
| 102 | +
|
| 103 | + # Use the first anvil account private key for deployment |
| 104 | + export PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" |
| 105 | + export ACCOUNT_ADDRESS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" |
| 106 | +
|
| 107 | + # Reset nonce by sending a dummy transaction if needed |
| 108 | + echo "Checking current nonce..." |
| 109 | + CURRENT_NONCE=$(curl -s -X POST -H "Content-Type: application/json" \ |
| 110 | + --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionCount\",\"params\":[\"$ACCOUNT_ADDRESS\",\"latest\"],\"id\":1}" \ |
| 111 | + http://localhost:8545 | jq -r '.result' | xargs printf "%d") |
| 112 | +
|
| 113 | + echo "Current nonce: $CURRENT_NONCE" |
| 114 | +
|
| 115 | + # If nonce is not 0, reset it by mining a new block |
| 116 | + if [ "$CURRENT_NONCE" -gt 0 ]; then |
| 117 | + echo "Nonce is not 0, mining a new block to reset state..." |
| 118 | + curl -s -X POST -H "Content-Type: application/json" \ |
| 119 | + --data '{"jsonrpc":"2.0","method":"evm_mine","params":[],"id":1}' \ |
| 120 | + http://localhost:8545 |
| 121 | + fi |
| 122 | +
|
| 123 | + # Deploy contracts to anvil using catapult with custom RPC URL |
| 124 | + echo "Deploying contracts to anvil..." |
| 125 | + pnpm run deploy --rpc-url http://localhost:8545 |
| 126 | +
|
| 127 | + echo "Deployment completed successfully!" |
| 128 | +
|
| 129 | + - name: Generate Table and Validate README |
| 130 | + run: | |
| 131 | + set -euo pipefail |
| 132 | +
|
| 133 | + # Generate the table and save to temp file |
| 134 | + echo "Generating deployment table..." |
| 135 | + pnpm -s run gen-table > gen-table.txt |
| 136 | +
|
| 137 | + # Extract the table section from README.md (from the start of the table to the end) |
| 138 | + echo "Extracting table from README.md..." |
| 139 | + sed -n '/^┌.*┬.*┬.*┐$/,/^└.*┴.*┴.*┘$/p' README.md > readme-table.txt |
| 140 | +
|
| 141 | + # Compare the files directly |
| 142 | + echo "Comparing generated table with README table..." |
| 143 | + if ! diff -w gen-table.txt readme-table.txt; then |
| 144 | + echo "ERROR: The table in README.md does not match the current deployment table" |
| 145 | + echo "Please run 'pnpm run gen-table' and update README.md with the latest table" |
| 146 | + echo "" |
| 147 | + echo "Generated table:" |
| 148 | + cat gen-table.txt |
| 149 | + echo "" |
| 150 | + echo "README table:" |
| 151 | + cat readme-table.txt |
| 152 | + exit 1 |
| 153 | + fi |
| 154 | +
|
| 155 | + echo "✅ README table validation passed!" |
| 156 | +
|
| 157 | + - name: Cleanup |
| 158 | + if: always() |
| 159 | + run: | |
| 160 | + # Clean up Anvil process |
| 161 | + if [ -f anvil.pid ]; then |
| 162 | + ANVIL_PID=$(cat anvil.pid) |
| 163 | + kill $ANVIL_PID 2>/dev/null || true |
| 164 | + rm -f anvil.pid |
| 165 | + fi |
| 166 | +
|
| 167 | + # Kill any remaining anvil processes |
| 168 | + pkill anvil || true |
0 commit comments