Skip to content

Merge pull request #38 from cloudflavor/feature/clo-47-bug-fix-multip… #46

Merge pull request #38 from cloudflavor/feature/clo-47-bug-fix-multip…

Merge pull request #38 from cloudflavor/feature/clo-47-bug-fix-multip… #46

Workflow file for this run

name: Deploy to Cloudflare Workers
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [21.x, 22.x]
steps:
- uses: actions/checkout@v2
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install -g yarn && yarn install
- name: Run tests
run: yarn test
env:
CI: true
deploy-staging:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '21'
- name: Install dependencies
run: npm install -g yarn && yarn install
- name: Install Wrangler
run: npm install -g wrangler
- name: Install uuidgen
run: sudo apt-get update -qq && sudo apt-get install -y uuid-runtime -qq
- name: Generate unique hash
id: generate_hash
run: |
UNIQUE_HASH=$(uuidgen | cut -c1-8)
echo "UNIQUE_HASH=$UNIQUE_HASH" >> $GITHUB_ENV
- name: Create wrangler environment for staging
run: |
cat <<EOF >> wrangler.toml
[env.stg-${{ env.UNIQUE_HASH }}]
routes = [{ pattern = "svc-stg.cloudflavor.io/${{ env.UNIQUE_HASH }}/*", zone_name = "cloudflavor.io" }]
[env.stg-${{ env.UNIQUE_HASH }}.unsafe]
[[env.stg-${{ env.UNIQUE_HASH }}.unsafe.bindings]]
name = "OSCAR_RATE_LIMITER"
type = "ratelimit"
namespace_id = "1507"
simple = { limit = 100, period = 60 }
[env.stg-${{ env.UNIQUE_HASH }}.vars]
OSCAR_LOG_LEVEL = "debug"
EOF
env:
UNIQUE_HASH: ${{ env.UNIQUE_HASH }}
- name: Publish to Cloudflare Workers (Staging)
run: wrangler deploy --env stg-${{ env.UNIQUE_HASH }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_WORKERS_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
UNIQUE_HASH: ${{ env.UNIQUE_HASH }}
deploy-production:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '21'
- name: Install dependencies
run: npm install -g yarn && yarn install
- name: Install Wrangler
run: npm install -g wrangler
- name: Publish to Cloudflare Workers (Production)
run: yarn run deploy:prd
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_WORKERS_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}