Skip to content

Configure CI workflows to run once per PR push #25

Configure CI workflows to run once per PR push

Configure CI workflows to run once per PR push #25

name: Cloudflare Worker
on:
push:
branches: [main]
paths:
- 'cloudflare-worker/**'
- 'data/festivals.json'
- '.github/workflows/cloudflare-worker.yml'
pull_request:
paths:
- 'cloudflare-worker/**'
- 'data/festivals.json'
- '.github/workflows/cloudflare-worker.yml'
workflow_dispatch:
permissions:
contents: read
pull-requests: write
concurrency:
group: cloudflare-worker-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
# Detect which files have changed
changes:
runs-on: ubuntu-latest
outputs:
worker: ${{ steps.filter.outputs.worker }}
festivals: ${{ steps.filter.outputs.festivals }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for file changes
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
worker:
- 'cloudflare-worker/**'
festivals:
- 'data/festivals.json'
# Validate festivals.json against schema
validate-festivals:
needs: changes
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.festivals == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: scripts/package-lock.json
- name: Install validation dependencies
working-directory: scripts
run: npm ci
- name: Validate festivals.json
run: node scripts/validate-festivals.js
# Validate Cloudflare Worker on PRs (dry-run)
validate-worker:
needs: changes
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' &&
(needs.changes.outputs.worker == 'true' || needs.changes.outputs.festivals == 'true')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install worker dependencies
working-directory: cloudflare-worker
run: npm ci
- name: Copy festivals.json to worker directory
run: cp data/festivals.json cloudflare-worker/festivals.json
- name: Validate worker (dry-run)
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: cloudflare-worker
command: deploy --dry-run
# Deploy Cloudflare Worker to production
deploy-worker:
needs: changes
runs-on: ubuntu-latest
if: |
github.ref == 'refs/heads/main' &&
(github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.worker == 'true' ||
needs.changes.outputs.festivals == 'true')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Validate festivals.json
if: |
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.festivals == 'true'
run: |
cd scripts && npm ci
node validate-festivals.js
- name: Install worker dependencies
working-directory: cloudflare-worker
run: npm ci
- name: Copy festivals.json to worker directory
run: cp data/festivals.json cloudflare-worker/festivals.json
- name: Deploy Cloudflare Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: cloudflare-worker