-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (100 loc) · 3.59 KB
/
frontend-deploy.yml
File metadata and controls
117 lines (100 loc) · 3.59 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
name: Deploy frontend
on:
push:
branches:
- main
- prod
paths:
- ".github/workflows/frontend-deploy.yml"
- "apps/frontend/**/*"
- "apps/frontend/uno.config.ts"
- "apps/frontend/nuxt.config.ts"
- "**/wrangler.jsonc"
- "**/pnpm-*.yaml"
workflow_dispatch:
workflow_call:
inputs:
environment:
required: true
type: string
description: "Environment to deploy to (staging-preview or production-preview)"
permissions:
contents: read
deployments: write
pull-requests: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Configure environment
id: metadata
run: |
echo "cmd=deploy" >> $GITHUB_OUTPUT
ENV_INPUT="${{ inputs.environment }}"
REF="${{ github.ref }}"
SHA_SHORT="${GITHUB_SHA::7}"
if [ "$ENV_INPUT" = "staging-preview" ]; then
echo "env=staging" >> $GITHUB_OUTPUT
echo "cmd=versions upload --preview-alias pr-$SHA_SHORT" >> $GITHUB_OUTPUT
echo "url=https://pr-$SHA_SHORT-frontend-staging.solitar.workers.dev" >> $GITHUB_OUTPUT
elif [ "$ENV_INPUT" = "production-preview" ]; then
echo "env=production" >> $GITHUB_OUTPUT
echo "cmd=versions upload --preview-alias pr-$SHA_SHORT" >> $GITHUB_OUTPUT
echo "url=https://pr-$SHA_SHORT-frontend.solitar.workers.dev" >> $GITHUB_OUTPUT
elif [ "$REF" = "refs/heads/main" ]; then
echo "env=staging" >> $GITHUB_OUTPUT
echo "url=https://staging.solitar.link" >> $GITHUB_OUTPUT
else
echo "env=production" >> $GITHUB_OUTPUT
echo "url=https://solitar.link" >> $GITHUB_OUTPUT
fi
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v6
with:
cache: pnpm
- name: Install dependencies
working-directory: ./apps/frontend
run: pnpm install
- name: Build
working-directory: ./apps/frontend
run: pnpm build
- name: Deploy Cloudflare Worker
id: wrangler
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
environment: ${{ steps.metadata.outputs.env != 'production' && steps.metadata.outputs.env || '' }}
workingDirectory: ./apps/frontend
packageManager: pnpm
wranglerVersion: "4.65.0"
command: ${{ steps.metadata.outputs.cmd }}
- name: Purge cache
if: github.ref == 'refs/heads/prod'
run: |
curl https://api.cloudflare.com/client/v4/zones/4ede5084774dc489678f0cf9695497b5/purge_cache \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
-d '{
"hosts": [
"www.solitar.link",
"solitar.link",
"staging.solitar.link"
]
}'
- name: Capture deployment URLs
if: ${{ inputs.environment != '' }}
run: |
echo "${{ steps.metadata.outputs.url }}" > deployment-url-${{ inputs.environment }}.txt
- name: Upload deployment URLs
if: ${{ inputs.environment != '' }}
uses: actions/upload-artifact@v6
with:
name: deployment-url-${{ inputs.environment }}
path: deployment-url-${{ inputs.environment }}.txt