-
Notifications
You must be signed in to change notification settings - Fork 3
155 lines (135 loc) · 6.14 KB
/
Copy pathdocs_pr_preview.yml
File metadata and controls
155 lines (135 loc) · 6.14 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Docs PR preview
on:
pull_request:
paths:
- "docs/**"
- "frontend/src/site/**"
- "frontend/public/**"
- "public/**"
- "scripts/build_github_pages_site.tsx"
permissions:
contents: read
pull-requests: write
concurrency:
group: docs-pr-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Validate route parity
run: npm run validate:routes
- name: Build UI (for compiled Tailwind CSS)
run: npm run build:ui
- name: Install Playwright browser (Chromium)
run: npx playwright install --with-deps chromium
- name: Build static site
env:
SITE_PREVIEW: "1"
NEOTOMA_DOCS_SHOW_INTERNAL: "false"
run: npm run build:site:pages
- name: Validate locale parity
run: npm run validate:locales
- name: Validate site export
run: npm run validate:site-export
- name: Rewrite asset paths for subdirectory deploy
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# Prerender and validation require root-absolute paths.
# Rewrite all root-absolute static asset references so they resolve
# under /pr-N/ when deployed to that subdirectory on dev.neotoma.io.
find site_pages -name "*.html" -print0 | xargs -0 sed -i \
-e "s|/assets/|/pr-${PR_NUMBER}/assets/|g" \
-e "s|/neotoma-wordmark\.svg|/pr-${PR_NUMBER}/neotoma-wordmark.svg|g" \
-e "s|/neotoma-hero\.png|/pr-${PR_NUMBER}/neotoma-hero.png|g" \
-e "s|/neotoma-og-1200x630\.png|/pr-${PR_NUMBER}/neotoma-og-1200x630.png|g" \
-e "s|/favicon\.ico|/pr-${PR_NUMBER}/favicon.ico|g" \
-e "s|/favicon\.svg|/pr-${PR_NUMBER}/favicon.svg|g" \
-e "s|/favicon-16x16\.png|/pr-${PR_NUMBER}/favicon-16x16.png|g" \
-e "s|/favicon-32x32\.png|/pr-${PR_NUMBER}/favicon-32x32.png|g" \
-e "s|/favicon-48x48\.png|/pr-${PR_NUMBER}/favicon-48x48.png|g" \
-e "s|/apple-touch-icon\.png|/pr-${PR_NUMBER}/apple-touch-icon.png|g" \
-e "s|/android-chrome-192x192\.png|/pr-${PR_NUMBER}/android-chrome-192x192.png|g" \
-e "s|/android-chrome-512x512\.png|/pr-${PR_NUMBER}/android-chrome-512x512.png|g" \
-e "s|/site\.webmanifest|/pr-${PR_NUMBER}/site.webmanifest|g"
# The preview deploy pushes to the external markmhendrickson/neotoma-dev-site
# repo using DEV_PAGES_DEPLOY_TOKEN. When that token is missing or expired the
# deploy cannot succeed — but a docs preview is a convenience, not a gate, so a
# bad/absent token must NOT paint every docs PR's checks red. We therefore gate
# the deploy on token presence and mark it continue-on-error; the build/validation
# steps above still run and still fail the check on real content problems.
- name: Check deploy token presence
id: deploy_token
env:
DEV_PAGES_DEPLOY_TOKEN: ${{ secrets.DEV_PAGES_DEPLOY_TOKEN }}
run: |
if [ -n "$DEV_PAGES_DEPLOY_TOKEN" ]; then
echo "present=true" >> "$GITHUB_OUTPUT"
else
echo "present=false" >> "$GITHUB_OUTPUT"
echo "::warning title=Docs preview not deployed::DEV_PAGES_DEPLOY_TOKEN is not set; skipping the preview deploy. The static site still built and validated above. See the preview-deploy rotation runbook to restore deploys."
fi
- name: Deploy PR preview
id: deploy
if: steps.deploy_token.outputs.present == 'true'
continue-on-error: true
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.DEV_PAGES_DEPLOY_TOKEN }}
external_repository: markmhendrickson/neotoma-dev-site
publish_branch: gh-pages
destination_dir: pr-${{ github.event.pull_request.number }}
publish_dir: ./site_pages
keep_files: true
commit_message: "PR #${{ github.event.pull_request.number }} preview from ${{ github.sha }}"
- name: Warn if preview deploy failed
if: steps.deploy.outcome == 'failure'
run: |
echo "::warning title=Docs preview deploy failed::The static site built and validated, but pushing the preview to neotoma-dev-site failed (likely an expired DEV_PAGES_DEPLOY_TOKEN). This does not block the PR. See the preview-deploy rotation runbook to restore deploys."
- name: Post preview URL as PR comment
if: steps.deploy.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request.number;
const previewUrl = `https://dev.neotoma.io/pr-${pr}/`;
const body = [
`### Docs preview`,
``,
`**Preview URL:** ${previewUrl}`,
``,
`Built from \`${{ github.sha }}\`. The preview is a static export — manifest-driven category ordering is not applied, but all doc content is rendered.`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
});
const existing = comments.find(c =>
c.user.login === 'github-actions[bot]' && c.body.startsWith('### Docs preview')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
body,
});
}