Skip to content
name: Health Check for New Network Deployment
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'config/networks.json'
jobs:
check-new-network-health:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if config/networks.json was changed in this branch
id: check-file-change
run: |
if git diff --name-only origin/main...HEAD | grep -q "config/networks.json"; then
echo "config/networks.json has been modified in this branch"
echo "CONTINUE=true" >> $GITHUB_ENV
else
echo "No changes in config/networks.json detected in this branch"
echo "CONTINUE=false" >> $GITHUB_ENV
fi
- name: Detect Newly Added Networks
if: env.CONTINUE == 'true'
id: detect-changes
run: |
echo "Comparing config/networks.json with the previous commit..."
git fetch origin main --depth=1 || echo "No previous commit found."
if git show origin/main:config/networks.json > /dev/null 2>&1; then
OLD_NETWORKS=$(git show origin/main:config/networks.json | jq 'keys')
else
echo "No previous networks.json found, assuming all networks are new."
OLD_NETWORKS="[]"
fi
NEW_NETWORKS=$(jq 'keys' config/networks.json)
echo "New Networks: $NEW_NETWORKS"
ADDED_NETWORKS=$(jq -n --argjson old "$OLD_NETWORKS" --argjson new "$NEW_NETWORKS" '$new - $old')
if [[ "$ADDED_NETWORKS" == "[]" ]]; then
echo "No new networks detected."
echo "SKIP_CHECK=true" >> $GITHUB_ENV
else
echo "New networks detected: $ADDED_NETWORKS"
echo "added_networks=$(echo $ADDED_NETWORKS | jq -c .)" >> $GITHUB_ENV
fi
- name: Validate Network Deployment Files
if: env.CONTINUE == 'true' && env.SKIP_CHECK != 'true'
run: |
echo "Validating required files for new networks..."
for network in $(echo $added_networks | jq -r '.[]'); do
echo "πŸ” Checking files for network: $network"
# Check if network exists in _targetState.json
if ! jq -e 'has("'"$network"'")' script/deploy/_targetState.json > /dev/null; then
echo "❌ Error: Network '$network' not found in script/deploy/_targetState.json"
exit 1
fi
# Check if deployments/{network}.json file exists
if [[ ! -f "deployments/$network.json" ]]; then
echo "❌ Error: Missing deployment file: deployments/$network.json"
exit 1
fi
done
- name: Install Bun
if: env.CONTINUE == 'true' && env.SKIP_CHECK != 'true'
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install Foundry (provides cast)
if: env.CONTINUE == 'true' && env.SKIP_CHECK != 'true'
uses: foundry-rs/foundry-toolchain@v1
- name: Install dependencies
if: env.CONTINUE == 'true' && env.SKIP_CHECK != 'true'
run: bun install
- name: Run Health Checks on New Networks
if: env.CONTINUE == 'true' && env.SKIP_CHECK != 'true'
run: |
echo "Running health check for new networks..."
set -e
for network in $(echo $added_networks | jq -r '.[]'); do
echo "πŸ” Checking network: $network"
if bun run script/deploy/healthCheck.ts --network "$network"; then
echo "βœ… $network is fine."
else
echo "❌ Health check failed for $network. Exiting..."
exit 1
fi
done