diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index 8554ab8..a5f42d5 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -14,7 +14,9 @@ jobs: uses: ./.github/workflows/wrangler-deploy.yml with: environment: production + worker_name: website site_url: https://johnhooks.io + domains: johnhooks.io,www.johnhooks.io ref: ${{ inputs.ref }} secrets: cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }} diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 2a337ea..4881efe 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -17,6 +17,7 @@ jobs: uses: ./.github/workflows/wrangler-deploy.yml with: environment: staging + worker_name: website-staging site_url: https://website-staging.johnhooks.workers.dev ref: ${{ inputs.ref }} secrets: diff --git a/.github/workflows/wrangler-deploy.yml b/.github/workflows/wrangler-deploy.yml index 8a64230..0269ad8 100644 --- a/.github/workflows/wrangler-deploy.yml +++ b/.github/workflows/wrangler-deploy.yml @@ -16,6 +16,15 @@ on: type: string description: Git ref to deploy default: "" + worker_name: + required: true + type: string + description: Worker name to deploy + domains: + required: false + type: string + description: Comma-separated custom domains for this environment + default: "" secrets: cloudflare_api_token: required: true @@ -42,9 +51,25 @@ jobs: SITE_URL: ${{ inputs.site_url }} - name: Deploy to Cloudflare - run: >- - pnpm wrangler deploy --env ${{ inputs.environment }} --var ENVIRONMENT:${{ - inputs.environment }} --var SITE_URL:${{ inputs.site_url }} + run: | + domain_args=() + IFS=',' read -ra domains <<< "$DOMAINS" + for domain in "${domains[@]}"; do + if [[ -n "$domain" ]]; then + domain_args+=(--domain "$domain") + fi + done + + pnpm wrangler deploy \ + --env "$ENVIRONMENT" \ + --name "$WORKER_NAME" \ + "${domain_args[@]}" \ + --var "ENVIRONMENT:$ENVIRONMENT" \ + --var "SITE_URL:$SITE_URL" env: CLOUDFLARE_API_TOKEN: ${{ secrets.cloudflare_api_token }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.cloudflare_account_id }} + ENVIRONMENT: ${{ inputs.environment }} + WORKER_NAME: ${{ inputs.worker_name }} + SITE_URL: ${{ inputs.site_url }} + DOMAINS: ${{ inputs.domains }} diff --git a/package.json b/package.json index e280383..efb22a0 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "dev": "astro dev", "build": "astro build", "preview": "astro preview", - "deploy": "pnpm build && wrangler deploy --env production --var ENVIRONMENT:production --var SITE_URL:https://johnhooks.io", - "deploy:staging": "pnpm build && wrangler deploy --env staging --var ENVIRONMENT:staging --var SITE_URL:https://website-staging.johnhooks.workers.dev", + "deploy": "pnpm build && wrangler deploy --env production --name website --domain johnhooks.io --domain www.johnhooks.io --var ENVIRONMENT:production --var SITE_URL:https://johnhooks.io", + "deploy:staging": "pnpm build && wrangler deploy --env staging --name website-staging --var ENVIRONMENT:staging --var SITE_URL:https://website-staging.johnhooks.workers.dev", "check": "astro check", "test": "vitest run", "lint": "prettier --check . && eslint .",