Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 121 additions & 2 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: Build and Deploy Augur Site with Fork Risk Monitoring

on:
schedule:
# Run every hour at minute 5 for fork risk monitoring
- cron: '5 * * * *'
# Run every 6 hours at minute 5 for fork risk monitoring
# Runs at 00:05, 06:05, 12:05, 18:05 UTC
- cron: '5 */6 * * *'
workflow_dispatch:
# Allow manual trigger with deployment control
inputs:
Expand Down Expand Up @@ -47,6 +48,34 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Fetch event cache from gh-pages
run: |
# Incremental Event Caching Strategy:
# - Loads cached events from gh-pages branch
# - Only queries blockchain for new blocks since last run
# - Re-queries last 32 blocks for finality safety
# - Reduces RPC calls from ~51/hour to ~2/6-hours (98% reduction)
# - See docs/rpc-caching-strategy.md for details

# Create cache directory in public/ (will be copied to dist/ by Astro build)
mkdir -p public/cache

# Try to fetch cache from gh-pages branch
if git show origin/gh-pages:cache/event-cache.json > public/cache/event-cache.json 2>/dev/null; then
echo "✓ Cache loaded from gh-pages"
echo "Cache size: $(wc -c < public/cache/event-cache.json) bytes"
echo "Cache version: $(jq -r '.version // "unknown"' public/cache/event-cache.json)"
echo "Last queried block: $(jq -r '.lastQueriedBlock // 0' public/cache/event-cache.json)"
else
echo "⚠️ No cache found on gh-pages, will perform full 7-day query"
# Create valid empty cache structure (matches EventCache interface)
NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
jq -n \
--arg now "$NOW" \
'{version: "1.0.0", lastQueriedBlock: 0, lastQueriedTimestamp: $now, oldestEventBlock: 0, events: {created: [], contributions: [], completed: []}, metadata: {totalEventsTracked: 0, cacheGeneratedAt: $now, blockchainSyncStatus: "stale"}}' \
> public/cache/event-cache.json
fi

- name: Calculate fork risk data
run: npm run build:fork-data
env:
Expand Down Expand Up @@ -100,6 +129,96 @@ jobs:
id: deployment
uses: actions/deploy-pages@v4

- name: Checkout gh-pages for cache management
uses: actions/checkout@v4
with:
ref: gh-pages
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Detect meaningful changes (smart commit)
id: changes
run: |
# Smart Commit Strategy:
# - Immediate: Risk data changes (new disputes detected)
# - Daily: Cache-only updates (midnight run at 00:05 UTC)
# - Skip: No changes

# Get current risk from deployed site
CURRENT_RISK=$(jq -r '.riskPercentage // 0' data/fork-risk.json 2>/dev/null || echo "0")
CURRENT_BLOCK=$(jq -r '.blockNumber // "Unknown"' data/fork-risk.json 2>/dev/null || echo "Unknown")

# Get previous risk from git history
PREVIOUS_RISK=$(git show HEAD:data/fork-risk.json 2>/dev/null | jq -r '.riskPercentage // 0' 2>/dev/null || echo "0")

# Check if risk changed meaningfully (numeric comparison with rounding tolerance)
RISK_CHANGED=$(awk -v curr="$CURRENT_RISK" -v prev="$PREVIOUS_RISK" \
'BEGIN {if (int(curr*100) != int(prev*100)) print "true"; else print "false"}')

# Get cache stats for commit message (verify file exists)
EVENTS="0"
if [ -f cache/event-cache.json ]; then
EVENTS=$(jq -r '.metadata.totalEventsTracked // 0' cache/event-cache.json 2>/dev/null || echo "0")
fi
HOUR=$(date -u +%H)

# Determine commit strategy
if [ "$RISK_CHANGED" = "true" ]; then
# Meaningful risk change - immediate commit
echo "status=immediate" >> $GITHUB_OUTPUT
echo "block=$CURRENT_BLOCK" >> $GITHUB_OUTPUT
echo "risk=$CURRENT_RISK" >> $GITHUB_OUTPUT
echo "events=$EVENTS" >> $GITHUB_OUTPUT
echo "✅ Immediate commit: Risk changed from $PREVIOUS_RISK% to $CURRENT_RISK%"
elif [ "${EVENTS:-0}" -gt 0 ] && [ "$HOUR" = "00" ]; then
# Daily cache refresh at midnight (00:05 UTC) - only if events tracked
echo "status=daily-cache" >> $GITHUB_OUTPUT
echo "block=$CURRENT_BLOCK" >> $GITHUB_OUTPUT
echo "events=$EVENTS" >> $GITHUB_OUTPUT
echo "📅 Daily cache refresh commit"
else
# No meaningful changes
echo "status=skip" >> $GITHUB_OUTPUT
echo "⏭️ Skipping commit (no meaningful changes)"
fi

- name: Commit risk changes
if: steps.changes.outputs.status == 'immediate'
run: |
git add data/fork-risk.json cache/event-cache.json 2>/dev/null || true
git commit -m "chore: update fork risk data

Block: ${{ steps.changes.outputs.block }}
Risk: ${{ steps.changes.outputs.risk }}%
Cached events: ${{ steps.changes.outputs.events }}

New dispute activity detected. Risk changed due to active disputes."
git push origin gh-pages

- name: Commit daily cache refresh
if: steps.changes.outputs.status == 'daily-cache'
run: |
git add cache/event-cache.json 2>/dev/null || true
git commit -m "chore: daily event cache refresh

Block: ${{ steps.changes.outputs.block }}
Risk: ${{ steps.changes.outputs.risk }}%
Cached events: ${{ steps.changes.outputs.events }}

Routine cache update (no new disputes)."
git push origin gh-pages

- name: Skip commit
if: steps.changes.outputs.status == 'skip'
run: |
echo "⏭️ No meaningful changes, skipping commit"
git restore --staged data/ cache/ 2>/dev/null || true

summary:
needs: build
runs-on: ubuntu-latest
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ Changes to the main branch trigger an automated workflow that:
6. Ensures consistency across both hosting platforms

**Fork Risk Data Collection:**
- Runs automatically every hour via GitHub Actions
- Runs automatically every 6 hours via GitHub Actions (00:05, 06:05, 12:05, 18:05 UTC)
- Uses incremental event caching to minimize RPC calls (98% reduction)
- Event cache stored publicly on gh-pages branch for transparency
- Smart commit strategy: only updates when risk changes or daily at midnight
- Uses public Ethereum RPC endpoints with failover
- Monitors Augur v2 dispute events for accurate stake tracking and fork risk calculation
- Monitors Augur v2 dispute events for accurate stake tracking
- Zero infrastructure costs - completely serverless data pipeline
- See [RPC Caching Strategy](docs/rpc-caching-strategy.md) for technical details

### Manual Deployment

Expand Down
Loading