Skip to content

Commit 3b9515a

Browse files
committed
chore: update workflows
1 parent 28939d2 commit 3b9515a

7 files changed

Lines changed: 213 additions & 145 deletions
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Cloudflare Preview Build
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
build-preview:
9+
runs-on: ubuntu-latest
10+
if: github.repository == 'doocs/md'
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v5
14+
with:
15+
ref: ${{ github.event.pull_request.head.sha }}
16+
17+
- name: Set up node
18+
uses: actions/setup-node@v6
19+
with:
20+
node-version: 22
21+
22+
- name: Setup pnpm
23+
uses: pnpm/action-setup@v4
24+
with:
25+
version: 10
26+
27+
- name: Install dependencies
28+
run: pnpm install
29+
30+
- name: Build for Cloudflare Workers
31+
run: pnpm web build:h5-netlify
32+
env:
33+
CF_WORKERS: 1
34+
35+
- name: Upload dist artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: cloudflare-dist
39+
path: apps/web/dist
40+
retention-days: 5
41+
42+
- name: Save PR number
43+
if: ${{ always() }}
44+
run: echo ${{ github.event.number }} > ./pr-id.txt
45+
46+
- name: Upload PR number
47+
if: ${{ always() }}
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: cloudflare-pr
51+
path: ./pr-id.txt
File renamed without changes.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Cloudflare Preview Deploy
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Cloudflare Preview Build"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && github.repository == 'doocs/md'
13+
permissions:
14+
contents: read
15+
deployments: write
16+
pull-requests: write
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v5
20+
21+
- name: Download PR artifact
22+
uses: dawidd6/action-download-artifact@v11
23+
with:
24+
workflow: ${{ github.event.workflow_run.workflow_id }}
25+
run_id: ${{ github.event.workflow_run.id }}
26+
name: cloudflare-pr
27+
28+
- name: Save PR id
29+
id: pr
30+
run: |
31+
pr_id=$(<pr-id.txt)
32+
if ! [[ "$pr_id" =~ ^[0-9]+$ ]]; then
33+
echo "Error: pr-id.txt does not contain a valid numeric PR id. Please check."
34+
exit 1
35+
fi
36+
echo "id=$pr_id" >> $GITHUB_OUTPUT
37+
38+
- name: Download dist artifact
39+
uses: dawidd6/action-download-artifact@v11
40+
with:
41+
workflow: ${{ github.event.workflow_run.workflow_id }}
42+
run_id: ${{ github.event.workflow_run.id }}
43+
workflow_conclusion: success
44+
name: cloudflare-dist
45+
46+
- name: Set up node
47+
uses: actions/setup-node@v6
48+
with:
49+
node-version: 22
50+
51+
- name: Setup pnpm
52+
uses: pnpm/action-setup@v4
53+
with:
54+
version: 10
55+
56+
- name: Install dependencies
57+
run: |
58+
cd apps/web
59+
pnpm install --prod
60+
61+
- name: Deploy to Cloudflare Workers
62+
id: deploy
63+
uses: cloudflare/wrangler-action@v3
64+
with:
65+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
66+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
67+
command: deploy --name md-pr-${{ steps.pr.outputs.id }}
68+
workingDirectory: apps/web
69+
env:
70+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
71+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
72+
73+
- name: Comment PR with preview link
74+
uses: actions-cool/maintain-one-comment@v3
75+
with:
76+
token: ${{ secrets.GITHUB_TOKEN }}
77+
body: |
78+
🚀 Cloudflare Workers Preview has been successfully deployed!
79+
80+
**Preview URL:** https://md-pr-${{ steps.pr.outputs.id }}.doocs.workers.dev
81+
82+
<sub>Built with commit ${{ github.event.workflow_run.head_sha }}</sub>
83+
84+
<!-- Cloudflare Workers Preview Comment -->
85+
body-include: '<!-- Cloudflare Workers Preview Comment -->'
86+
number: ${{ steps.pr.outputs.id }}
87+
88+
- name: Deploy failed
89+
if: ${{ failure() }}
90+
uses: actions-cool/maintain-one-comment@v3
91+
with:
92+
token: ${{ secrets.GITHUB_TOKEN }}
93+
body: |
94+
😭 Cloudflare Workers Preview deployment failed.
95+
96+
Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
97+
98+
<!-- Cloudflare Workers Preview Comment -->
99+
body-include: '<!-- Cloudflare Workers Preview Comment -->'
100+
number: ${{ steps.pr.outputs.id }}
101+
102+
failed:
103+
runs-on: ubuntu-latest
104+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' && github.repository == 'doocs/md'
105+
steps:
106+
- name: Download PR artifact
107+
uses: dawidd6/action-download-artifact@v11
108+
with:
109+
workflow: ${{ github.event.workflow_run.workflow_id }}
110+
name: cloudflare-pr
111+
112+
- name: Save PR id
113+
id: pr
114+
run: |
115+
pr_id=$(<pr-id.txt)
116+
if ! [[ "$pr_id" =~ ^[0-9]+$ ]]; then
117+
echo "Error: pr-id.txt does not contain a valid numeric PR id. Please check."
118+
exit 1
119+
fi
120+
echo "id=$pr_id" >> $GITHUB_OUTPUT
121+
122+
- name: Comment PR with build failure
123+
uses: actions-cool/maintain-one-comment@v3
124+
with:
125+
token: ${{ secrets.GITHUB_TOKEN }}
126+
body: |
127+
😭 Cloudflare Workers Preview build failed.
128+
129+
Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) for details.
130+
131+
<!-- Cloudflare Workers Preview Comment -->
132+
body-include: '<!-- Cloudflare Workers Preview Comment -->'
133+
number: ${{ steps.pr.outputs.id }}

.github/workflows/cloudflare-preview.yml

Lines changed: 0 additions & 107 deletions
This file was deleted.

.github/workflows/preview-start.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Preview Build
1+
name: Surge Preview Build
22

33
on:
44
pull_request:

0 commit comments

Comments
 (0)