@@ -3,16 +3,17 @@ name: Deploy to Cloudflare Pages
33on :
44 pull_request :
55 branches : [develop]
6+ types : [opened, synchronize, reopened, closed]
67 push :
7- branches : [develop]
8+ branches : [main, develop]
89
910permissions :
1011 contents : read
1112 pull-requests : write
1213
1314jobs :
1415 deploy-preview :
15- if : github.event_name == 'pull_request'
16+ if : github.event_name == 'pull_request' && github.event.action != 'closed'
1617 runs-on : ubuntu-latest
1718 environment : Preview
1819 env :
6566 body: `## 🚀 Preview Deploy\n\n**App:** ${deployUrl}\n**Convex:** ${convexUrl}`
6667 });
6768
69+ cleanup-preview :
70+ if : github.event_name == 'pull_request' && github.event.action == 'closed'
71+ runs-on : ubuntu-latest
72+ environment : Preview
73+ steps :
74+ - name : Delete Cloudflare Pages preview
75+ run : |
76+ DEPLOYMENTS=$(curl -s \
77+ -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
78+ "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/yps-crispy-carnival/deployments" \
79+ | jq -r ".result[] | select(.deployment_trigger.metadata.branch == \"pr-${{ github.event.pull_request.number }}\") | .id")
80+ for ID in $DEPLOYMENTS; do
81+ echo "Deleting deployment $ID"
82+ curl -s -X DELETE \
83+ -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
84+ "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/yps-crispy-carnival/deployments/$ID?force=true"
85+ done
86+ env :
87+ CLOUDFLARE_API_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
88+ CLOUDFLARE_ACCOUNT_ID : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
89+
90+ deploy-develop :
91+ if : github.event_name == 'push' && github.ref == 'refs/heads/develop'
92+ runs-on : ubuntu-latest
93+ environment : Preview
94+ steps :
95+ - uses : actions/checkout@v6
96+ - name : Setup
97+ uses : ./.github/actions/setup
98+ - name : Build
99+ run : pnpm build
100+ env :
101+ VITE_CONVEX_URL : ${{ secrets.VITE_CONVEX_URL }}
102+ VITE_CLERK_PUBLISHABLE_KEY : ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }}
103+ - name : Deploy to Cloudflare Pages
104+ run : |
105+ npx wrangler pages deploy dist \
106+ --project-name yps-crispy-carnival \
107+ --branch develop
108+ env :
109+ CLOUDFLARE_API_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
110+ CLOUDFLARE_ACCOUNT_ID : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
111+
68112 deploy-production :
69- if : github.event_name == 'push'
113+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
70114 runs-on : ubuntu-latest
71115 environment : Production
72116 steps :
0 commit comments