-
-
Notifications
You must be signed in to change notification settings - Fork 6
108 lines (93 loc) · 3.27 KB
/
deploy-docs.yml
File metadata and controls
108 lines (93 loc) · 3.27 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
name: Deploy Docs to Cloudflare Pages
on:
push:
branches: [main]
paths:
- 'docs/**'
pull_request:
paths:
- 'docs/**'
workflow_dispatch:
permissions:
contents: read
deployments: write
pull-requests: write
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup pnpm
uses: pnpm/action-setup@v5
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'pnpm'
cache-dependency-path: docs/pnpm-lock.yaml
- name: Install dependencies
working-directory: docs
run: pnpm install --frozen-lockfile
- name: Build docs
working-directory: docs
run: pnpm build
- name: Generate SEO/AEO assets
working-directory: docs
run: |
pnpm seo:check || true
pnpm seo:sync || true
# Production deploy (push to main)
- name: Deploy to Production
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: cloudflare/wrangler-action@v3
id: deploy-production
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy docs/build --project-name=ralph-starter-docs --branch=main
# Preview deploy (pull requests)
- name: Deploy Preview
if: github.event_name == 'pull_request'
uses: cloudflare/wrangler-action@v3
id: deploy-preview
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy docs/build --project-name=ralph-starter-docs --branch=${{ github.head_ref }}
# Comment preview URL on the PR
- name: Comment Preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v8
with:
script: |
const branch = context.payload.pull_request.head.ref
.replace(/[^a-zA-Z0-9-]/g, '-')
.substring(0, 28);
const previewUrl = `https://${branch}.ralph-starter-docs.pages.dev`;
// Check for existing bot comment to avoid duplicates
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('Docs Preview')
);
const body = `### 🔗 Docs Preview\n\n**Preview URL:** ${previewUrl}\n\nThis preview was deployed from the latest commit on this PR.`;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}