Skip to content

Commit 17530fa

Browse files
committed
refactor: separate deployment jobs for dev and production environments in GitHub Actions
- Created distinct jobs for deploying to development and production environments in the GitHub Actions workflow. - Updated environment variables to use dynamic values for Sanity Studio deployment. - Streamlined build and deployment steps for both environments, enhancing clarity and maintainability.
1 parent 43c2388 commit 17530fa

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

.github/workflows/deploy.yml

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ on:
55
branches: [dev, main]
66

77
jobs:
8-
deploy:
8+
deploy-dev:
9+
if: github.ref == 'refs/heads/dev'
910
runs-on: ubuntu-latest
11+
environment: dev
1012

1113
steps:
1214
- uses: actions/checkout@v4
@@ -24,49 +26,64 @@ jobs:
2426
- name: Install wrangler
2527
run: pnpm add -Dw wrangler
2628

27-
- name: Build (dev)
28-
if: github.ref == 'refs/heads/dev'
29+
- name: Build
2930
run: pnpm --filter @codingcatdev/web build
3031
env:
31-
SANITY_PROJECT_ID: hfh83o0w
32-
SANITY_DATASET: dev
33-
PUBLIC_SANITY_STUDIO_URL: https://codingcat-dev.sanity.studio
32+
SANITY_PROJECT_ID: ${{ vars.SANITY_STUDIO_PROJECT_ID }}
33+
SANITY_DATASET: ${{ vars.SANITY_STUDIO_DATASET }}
34+
PUBLIC_SANITY_STUDIO_URL: https://${{ vars.SANITY_STUDIO_HOSTNAME }}.sanity.studio
3435

35-
- name: Build (production)
36-
if: github.ref == 'refs/heads/main'
37-
run: pnpm --filter @codingcatdev/web build
38-
env:
39-
SANITY_PROJECT_ID: hfh83o0w
40-
SANITY_DATASET: production
41-
42-
- name: Deploy to dev
43-
if: github.ref == 'refs/heads/dev'
36+
- name: Deploy to Cloudflare
4437
run: pnpm exec wrangler deploy
4538
working-directory: apps/web
4639
env:
4740
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
4841
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
4942

50-
- name: Deploy to production
51-
if: github.ref == 'refs/heads/main'
43+
- name: Deploy Sanity Studio
44+
run: npx sanity deploy -y
45+
working-directory: apps/sanity
46+
env:
47+
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
48+
SANITY_STUDIO_HOSTNAME: ${{ vars.SANITY_STUDIO_HOSTNAME }}
49+
50+
deploy-production:
51+
if: github.ref == 'refs/heads/main'
52+
runs-on: ubuntu-latest
53+
environment: production
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- uses: pnpm/action-setup@v4
59+
60+
- uses: actions/setup-node@v4
61+
with:
62+
node-version: "22"
63+
cache: "pnpm"
64+
65+
- name: Install dependencies
66+
run: pnpm install --frozen-lockfile
67+
68+
- name: Install wrangler
69+
run: pnpm add -Dw wrangler
70+
71+
- name: Build
72+
run: pnpm --filter @codingcatdev/web build
73+
env:
74+
SANITY_PROJECT_ID: ${{ vars.SANITY_STUDIO_PROJECT_ID }}
75+
SANITY_DATASET: ${{ vars.SANITY_STUDIO_DATASET }}
76+
77+
- name: Deploy to Cloudflare
5278
run: pnpm exec wrangler deploy --env production
5379
working-directory: apps/web
5480
env:
5581
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
5682
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
5783

58-
- name: Deploy Sanity Studio (dev)
59-
if: github.ref == 'refs/heads/dev'
60-
run: npx sanity deploy -y
61-
working-directory: apps/sanity
62-
env:
63-
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
64-
SANITY_STUDIO_HOSTNAME: codingcat-dev
65-
66-
- name: Deploy Sanity Studio (production)
67-
if: github.ref == 'refs/heads/main'
84+
- name: Deploy Sanity Studio
6885
run: npx sanity deploy -y
6986
working-directory: apps/sanity
7087
env:
7188
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
72-
SANITY_STUDIO_HOSTNAME: codingcat.dev
89+
SANITY_STUDIO_HOSTNAME: ${{ vars.SANITY_STUDIO_HOSTNAME }}

0 commit comments

Comments
 (0)