-
Notifications
You must be signed in to change notification settings - Fork 2
74 lines (65 loc) · 2.55 KB
/
deploy.yml
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
name: Deploy API and Web
on:
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
# Step 1: Checkout the code
- uses: actions/checkout@v4
# Step 2: Setup pnpm
- uses: pnpm/action-setup@v4
# Step 3: Setup Node.js with pnpm cache
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: pnpm
# Step 4: Install dependencies
- run: pnpm install
# Step 5: Replace placeholders in wrangler.toml with GitHub Secrets
- name: Replace wrangler.toml values
run: |
sed -i "s|{{KV_ID}}|${{ secrets.CLOUDFLARE_KV_ID }}|g" apps/api/wrangler.toml
if [ -n "${{ secrets.API_CUSTOM_DOMAIN }}" ]; then
sed -i "s|{{CUSTOM_DOMAIN}}|${{ secrets.API_CUSTOM_DOMAIN }}|g" apps/api/wrangler.toml
sed -i "s|#route|route|g" apps/api/wrangler.toml
else
echo "Custom domain not set, skipping..."
fi
# Step 6: Set up Cloudflare Wrangler
- name: Set up Wrangler for API
id: wrangler-api
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: 'apps/api'
preCommands: |
pnpm db:migrate:apply
pnpm db:seed
echo "$NEON_DATABASE_URL" | pnpm wrangler secret put NEON_DATABASE_URL
echo "$JWT_SECRET" | pnpm wrangler secret put JWT_SECRET
command: deploy --minify
env:
NEON_DATABASE_URL: ${{ secrets.NEON_DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
DEFAULT_USER: ${{ secrets.DEFAULT_USER }}
DEFAULT_PASSWORD: ${{ secrets.DEFAULT_PASSWORD }}
- name: Set NEXT_PUBLIC_WORKER
run: |
if [ -n "${{ secrets.API_CUSTOM_DOMAIN }}" ]; then
echo "Custom domain set, using it..."
echo "NEXT_PUBLIC_WORKER=${{ secrets.API_CUSTOM_DOMAIN }}" >> $GITHUB_ENV
echo "API URL: $NEXT_PUBLIC_WORKER"
else
echo "Custom domain not set, using the API Worker URL..."
API_WORKER_URL=${{ steps.wrangler-api.outputs.deployment-url }}
echo "NEXT_PUBLIC_WORKER=$API_WORKER_URL" >> $GITHUB_ENV
echo "API URL: $API_WORKER_URL"
fi
# Step 7: Deploy Web App to Cloudflare Pages
- name: Deploy Web to Cloudflare Pages
env:
NEXT_PUBLIC_WORKER: ${{ env.NEXT_PUBLIC_WORKER }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: pnpm pages:deploy:web