name: Update data & deploy to Cloudflare on: schedule: - cron: "17 */6 * * *" # every 6h at 00:17, 06:17, 12:17, 18:17 UTC (off the hour to dodge the cron rush) workflow_dispatch: push: branches: [main] permissions: contents: write concurrency: group: update-and-deploy cancel-in-progress: false jobs: update: runs-on: ubuntu-latest outputs: changed: ${{ steps.commit.outputs.changed }} steps: - uses: actions/checkout@v4 with: ref: main - uses: actions/setup-node@v4 with: node-version: 22 - name: Fetch latest data from Artificial Analysis if: github.event_name != 'push' env: AA_API_KEY: ${{ secrets.AA_API_KEY }} run: node scripts/fetch-aa.mjs - name: Commit if anything changed id: commit run: | if git diff --quiet -- data; then echo "changed=false" >> "$GITHUB_OUTPUT" echo "No data changes." exit 0 fi git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add data git commit -m "data: refresh from Artificial Analysis ($(date -u +%F))" git push echo "changed=true" >> "$GITHUB_OUTPUT" cloudflare: needs: update if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.update.outputs.changed == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: ref: main - name: Require Cloudflare token env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} run: | if [ -z "$CLOUDFLARE_API_TOKEN" ]; then echo "::error::CLOUDFLARE_API_TOKEN secret is not set; nothing to deploy to." exit 1 fi - uses: actions/setup-node@v4 with: node-version: 22 - name: Install pinned wrangler and build dist/ run: | npm ci sh scripts/build.sh - name: Deploy to Cloudflare Workers (static assets) uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: 4b4ca92e0adcba79ab45737c3c2ca444 wranglerVersion: "4.138.0" command: deploy