|
| 1 | +name: CDN Configuration Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + paths: |
| 7 | + - 'infra/fastly/**' |
| 8 | + - '.github/workflows/cdn-deploy.yml' |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + provider: |
| 12 | + description: 'CDN provider' |
| 13 | + required: true |
| 14 | + default: 'fastly' |
| 15 | + type: choice |
| 16 | + options: |
| 17 | + - fastly |
| 18 | + - cloudflare |
| 19 | + |
| 20 | +env: |
| 21 | + NODE_VERSION: '20' |
| 22 | + |
| 23 | +jobs: |
| 24 | + validate-vcl: |
| 25 | + name: Validate Fastly VCL |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Check VCL syntax (basic) |
| 32 | + run: | |
| 33 | + test -f infra/fastly/snippets/recv.vcl |
| 34 | + test -f infra/fastly/snippets/fetch.vcl |
| 35 | + grep -q "s-maxage" infra/fastly/snippets/fetch.vcl |
| 36 | + grep -q "/plans" infra/fastly/snippets/recv.vcl |
| 37 | + echo "VCL snippet validation passed" |
| 38 | +
|
| 39 | + deploy-fastly: |
| 40 | + name: Deploy Fastly VCL Snippet |
| 41 | + needs: validate-vcl |
| 42 | + if: > |
| 43 | + github.event_name == 'push' || |
| 44 | + (github.event_name == 'workflow_dispatch' && github.event.inputs.provider == 'fastly') |
| 45 | + runs-on: ubuntu-latest |
| 46 | + environment: production |
| 47 | + steps: |
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Deploy VCL snippet to Fastly |
| 52 | + env: |
| 53 | + FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }} |
| 54 | + FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }} |
| 55 | + run: | |
| 56 | + if [ -z "$FASTLY_API_TOKEN" ] || [ -z "$FASTLY_SERVICE_ID" ]; then |
| 57 | + echo "Fastly credentials not configured — skipping deploy (CI validation only)" |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | + chmod +x scripts/deploy-fastly-vcl.sh |
| 61 | + ./scripts/deploy-fastly-vcl.sh infra/fastly/snippets |
| 62 | +
|
| 63 | + deploy-cloudflare: |
| 64 | + name: Deploy Cloudflare Cache Rules |
| 65 | + needs: validate-vcl |
| 66 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.provider == 'cloudflare' |
| 67 | + runs-on: ubuntu-latest |
| 68 | + environment: production |
| 69 | + steps: |
| 70 | + - name: Checkout code |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Verify Cloudflare cache tag support |
| 74 | + env: |
| 75 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 76 | + CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }} |
| 77 | + run: | |
| 78 | + if [ -z "$CLOUDFLARE_API_TOKEN" ] || [ -z "$CLOUDFLARE_ZONE_ID" ]; then |
| 79 | + echo "Cloudflare credentials not configured — skipping deploy" |
| 80 | + exit 0 |
| 81 | + fi |
| 82 | + echo "Cloudflare purge-by-tag configured via CDN_PROVIDER=cloudflare" |
| 83 | + echo "Origin sets Cache-Tag header alongside Surrogate-Key" |
| 84 | +
|
| 85 | + run-cache-tests: |
| 86 | + name: CDN Cache Unit Tests |
| 87 | + needs: validate-vcl |
| 88 | + runs-on: ubuntu-latest |
| 89 | + steps: |
| 90 | + - name: Checkout code |
| 91 | + uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Setup Node.js |
| 94 | + uses: actions/setup-node@v4 |
| 95 | + with: |
| 96 | + node-version: ${{ env.NODE_VERSION }} |
| 97 | + cache: 'npm' |
| 98 | + |
| 99 | + - name: Install dependencies |
| 100 | + run: npm ci --legacy-peer-deps |
| 101 | + |
| 102 | + - name: Run CDN cache tests |
| 103 | + run: npm run test:cdn |
0 commit comments