Skip to content

Commit eae8a61

Browse files
committed
ci: deploy to cloudflare pages (#10)
1 parent d90fd2e commit eae8a61

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed

.github/workflows/pr-preview.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
2+
#
3+
#
4+
#
5+
# IF YOU DON'T KNOW WHAT YOU'RE DOING, YOU CAN EASILY LEAK SECRETS BY USING A
6+
# `pull_request_target` WORKFLOW INSTEAD OF `pull_request`! SERIOUSLY, DO NOT
7+
# BLINDLY COPY AND PASTE THIS FILE WITHOUT UNDERSTANDING THE FULL IMPLICATIONS
8+
# OF WHAT YOU'RE DOING! WE HAVE TESTED THIS FOR OUR OWN USE CASES, WHICH ARE
9+
# NOT NECESSARILY THE SAME AS YOURS! WHILE WE AREN'T EXPOSING ANY OF OUR SECRETS,
10+
# ONE COULD EASILY DO SO BY MODIFYING OR ADDING A STEP TO THIS WORKFLOW!
11+
#
12+
#
13+
#
14+
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
15+
16+
name: Preview Deployment
17+
on:
18+
pull_request_target:
19+
types:
20+
- opened
21+
- synchronize
22+
- closed
23+
24+
# cancel in-progress runs on new commits to same PR (github.event.number)
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
27+
cancel-in-progress: true
28+
29+
env:
30+
PROJECT_NAME: playground
31+
32+
jobs:
33+
deploy-preview:
34+
if: ${{ github.event.action != 'closed' }}
35+
permissions:
36+
contents: read
37+
pull-requests: write
38+
deployments: write
39+
runs-on: ubuntu-latest
40+
name: Deploy Preview to Cloudflare Pages
41+
env:
42+
BRANCH_NAME: preview-${{ github.head_ref }}
43+
ACTION_RUN: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
submodules: "recursive"
48+
ref: ${{ github.event.pull_request.head.ref }}
49+
repository: ${{ github.event.pull_request.head.repo.full_name }}
50+
51+
- name: Create comment
52+
id: comment
53+
uses: peter-evans/create-or-update-comment@v4
54+
with:
55+
issue-number: ${{ github.event.pull_request.number }}
56+
comment-author: "github-actions[bot]"
57+
body: |
58+
## ⚡ Cloudflare Pages Deployment
59+
| Name | Status | Preview |
60+
| :--- | :----- | :------ |
61+
| ${{env.BRANCH_NAME}} | 🔨 Building ([Logs](${{env.ACTION_RUN}})) | waiting... |
62+
63+
# Build
64+
- uses: pnpm/action-setup@v4
65+
with:
66+
version: 9
67+
- name: Install Deps
68+
run: pnpm i -C frontend
69+
- name: Build
70+
run: pnpm run -C frontend build
71+
env:
72+
VITE_BACKEND_HOST: ${{ secrets.BACKEND_HOST }}
73+
74+
# Deploy steps
75+
- name: Deploy
76+
id: deploy
77+
uses: cloudflare/wrangler-action@v3
78+
with:
79+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
80+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
81+
command: pages deploy ./frontend/dist --project-name "${{ env.PROJECT_NAME }}" --branch "${{ env.BRANCH_NAME }}"
82+
83+
- name: Extract hash from CF url Deploy
84+
run: |
85+
url_hash=$(echo "${{ steps.deploy.outputs.deployment-url }}" | sed -n 's|https://\([^.]*\).${{env.PROJECT_NAME}}.*|\1|p')
86+
echo "SHA_SHORT=$url_hash" >> $GITHUB_ENV
87+
88+
- name: Create comment
89+
uses: peter-evans/create-or-update-comment@v4
90+
with:
91+
issue-number: ${{ github.event.pull_request.number }}
92+
comment-id: ${{ steps.comment.outputs.comment-id }}
93+
edit-mode: replace
94+
body: |
95+
## ⚡ Cloudflare Pages Deployment
96+
| Name | Status | Preview |
97+
| :--- | :----- | :------ |
98+
| ${{env.BRANCH_NAME}} | ✅ Ready ([Logs](${{env.ACTION_RUN}})) | [${{env.SHA_SHORT}}](${{ steps.deploy.outputs.deployment-url }}) |
99+
100+
# remove-preview:
101+
# if: ${{ github.event.action == "closed" }}
102+
# permissions:
103+
# contents: read
104+
# pull-requests: write
105+
# deployments: write
106+
# runs-on: ubuntu-latest
107+
# name: Remove Preview of Cloudflare Pages
108+
# steps:
109+
# - uses: actions/checkout@v3
110+
# with:
111+
# submodules: "recursive"
112+
# ref: ${{ github.event.pull_request.head.ref }}
113+
# repository: ${{ github.event.pull_request.head.repo.full_name }}
114+
115+
# - name: Deploy
116+
# id: deploy
117+
# uses: cloudflare/wrangler-action@v3
118+
# with:
119+
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
120+
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
121+
# command: pages --project-name=homepage --branch="${ env.BRANCH_NAME }"
122+
123+
# - name: Create comment
124+
# uses: peter-evans/create-or-update-comment@v4
125+
# with:
126+
# issue-number: ${{ github.event.pull_request.number }}
127+
# comment-author: 'github-actions[bot]'
128+
# body: |
129+
# ## ⚡ Removing Cloudflare Pages Preview
130+
# | Name | Status |
131+
# | :--- | :----- |
132+
# | ${{env.BRANCH_NAME}} | ✅ Removed |

.github/workflows/web.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Deploy to production
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- '.github/workflows/deploy.yml'
10+
- 'frontend/**'
11+
12+
env:
13+
PROJECT_NAME: playground
14+
15+
jobs:
16+
deploy:
17+
runs-on: ubuntu-22.04
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- uses: pnpm/action-setup@v4
22+
with:
23+
version: 9
24+
- name: Install Deps
25+
run: pnpm i -C frontend
26+
- name: Build
27+
run: pnpm run -C frontend build
28+
env:
29+
VITE_BACKEND_HOST: ${{ secrets.BACKEND_HOST }}
30+
- name: Deploy
31+
uses: cloudflare/wrangler-action@v3
32+
# env:
33+
# AUTH_GITHUB_ID: ${{ secrets.AUTH_GITHUB_ID }}
34+
# AUTH_GITHUB_SECRET: ${{ secrets.AUTH_GITHUB_SECRET }}
35+
# AUTH_SECRET: ${{ secrets.AUTH_SECRET }}
36+
# AUTH_TRUST_HOST: ${{ secrets.AUTH_TRUST_HOST }}
37+
# ADMINS: ${{ secrets.ADMINS }}
38+
with:
39+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
40+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
41+
command: pages deploy ./frontend/dist --project-name "${{ env.PROJECT_NAME }}"
42+
# secrets: |
43+
# ADMINS
44+
# AUTH_GITHUB_ID
45+
# AUTH_GITHUB_SECRET
46+
# AUTH_SECRET
47+
# AUTH_TRUST_HOST

0 commit comments

Comments
 (0)