-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (133 loc) · 5.25 KB
/
deploy.yml
File metadata and controls
139 lines (133 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Deploy to Cloudflare Pages
on:
pull_request:
branches: [develop]
types: [opened, synchronize, reopened, closed]
push:
branches: [main, develop]
permissions:
contents: read
pull-requests: write
jobs:
deploy-preview:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
runs-on: ubuntu-latest
environment: Preview
env:
CONVEX_PREVIEW_NAME: pr-${{ github.event.pull_request.number }}-deploy
steps:
- uses: actions/checkout@v6
- name: Setup
uses: ./.github/actions/setup
- name: Deploy Convex Preview
id: convex
run: |
npx convex deploy --preview-create "$CONVEX_PREVIEW_NAME" \
--cmd 'echo "PREVIEW_URL=$CONVEX_URL" >> "$GITHUB_OUTPUT"' \
--cmd-url-env-var-name CONVEX_URL
env:
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}
- name: Seed Database
run: |
npx convex import --replace-all convex-seeds/seeds/db.zip --yes \
--preview-name "${{ env.CONVEX_PREVIEW_NAME }}"
env:
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}
- name: Build
run: pnpm build
env:
VITE_CONVEX_URL: ${{ steps.convex.outputs.PREVIEW_URL }}
VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }}
- name: Deploy to Cloudflare Pages
id: deploy
run: |
DEPLOY_OUTPUT=$(npx wrangler pages deploy dist \
--project-name dev-yps-crispy-carnival \
--branch "pr-${{ github.event.pull_request.number }}" 2>&1)
echo "$DEPLOY_OUTPUT"
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -oP 'https://[^\s]+\.pages\.dev' | tail -1)
echo "DEPLOY_URL=$DEPLOY_URL" >> "$GITHUB_OUTPUT"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Comment PR with Deploy URL
uses: actions/github-script@v8
with:
script: |
const deployUrl = '${{ steps.deploy.outputs.DEPLOY_URL }}';
const convexUrl = '${{ steps.convex.outputs.PREVIEW_URL }}';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## 🚀 Preview Deploy\n\n**App:** ${deployUrl}\n**Convex:** ${convexUrl}`
});
cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
environment: Preview
steps:
- name: Delete Cloudflare Pages preview
run: |
DEPLOYMENTS=$(curl -s \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/dev-yps-crispy-carnival/deployments" \
| jq -r ".result[] | select(.deployment_trigger.metadata.branch == \"pr-${{ github.event.pull_request.number }}\") | .id")
for ID in $DEPLOYMENTS; do
echo "Deleting deployment $ID"
curl -s -X DELETE \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/dev-yps-crispy-carnival/deployments/$ID?force=true"
done
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
deploy-develop:
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
environment: Develop
steps:
- uses: actions/checkout@v6
- name: Setup
uses: ./.github/actions/setup
- name: Deploy Convex
run: npx convex deploy
env:
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}
- name: Build
run: pnpm build
env:
VITE_CONVEX_URL: ${{ secrets.VITE_CONVEX_URL }}
VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }}
- name: Deploy to Cloudflare Pages
run: |
npx wrangler pages deploy dist \
--project-name dev-yps-crispy-carnival
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
deploy-production:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: Production
steps:
- uses: actions/checkout@v6
- name: Setup
uses: ./.github/actions/setup
- name: Deploy Convex
run: npx convex deploy
env:
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}
- name: Build
run: pnpm build
env:
VITE_CONVEX_URL: ${{ secrets.VITE_CONVEX_URL }}
VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }}
- name: Deploy to Cloudflare Pages
run: |
npx wrangler pages deploy dist \
--project-name yps-crispy-carnival \
--branch main
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}