-
Notifications
You must be signed in to change notification settings - Fork 3
79 lines (70 loc) · 2.58 KB
/
deploy.yml
File metadata and controls
79 lines (70 loc) · 2.58 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
name: Deploy to Cloudflare Pages
on:
push:
branches: [master]
workflow_run:
workflows: ["PR Build"]
types: [completed]
permissions:
actions: read
contents: read
deployments: write
pull-requests: write
jobs:
deploy:
if: |
github.event_name == 'push' ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request')
runs-on: ubuntu-latest
steps:
- name: Checkout repository (push deployments)
if: github.event_name == 'push'
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Node.js (push deployments)
if: github.event_name == 'push'
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies (push deployments)
if: github.event_name == 'push'
run: npm ci
- name: Build docs (push deployments)
if: github.event_name == 'push'
run: npm run build
- name: Download build artifact (PR previews)
if: github.event_name == 'workflow_run'
uses: actions/download-artifact@v4
with:
name: docusaurus-build
path: build
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy build --project-name=redot-docs-site --branch=${{ github.event_name == 'workflow_run' && format('pr-{0}', github.event.workflow_run.pull_requests[0].number) || github.ref_name }}
- name: Comment PR with preview URL
if: github.event_name == 'workflow_run' && github.event.workflow_run.pull_requests[0].number
uses: actions/github-script@v7
env:
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
with:
script: |
const prNumber = context.payload.workflow_run.pull_requests[0]?.number;
const deployUrl = process.env.DEPLOY_URL;
if (prNumber && deployUrl) {
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 **Preview deployment ready!**\n\n🔗 ${deployUrl}`
});
}