Skip to content

Commit 61c7249

Browse files
authored
Add GitHub Actions workflow for publishing design system preview (#103778)
* Add GitHub Actions workflow for publishing design system preview * Limit Design System Docs workflow to edits on relevant paths * Fix quoting on worker upload script * Output URL for debugging * Condition to avoid running actions on fork PRs * Avoid duplicate comment for calypso.live preview * Revert "Avoid duplicate comment for calypso.live preview" This reverts commit d74f7fb. * Use pull request HEAD SHA for commit reference See: #103778 (comment)
1 parent efd740f commit 61c7249

File tree

3 files changed

+95
-5
lines changed

3 files changed

+95
-5
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Publish Design System Docs PR Preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
paths:
7+
- 'apps/design-system-docs/**'
8+
- .github/workflows/design-system-docs.yml
9+
10+
# Ensure only one preview build runs per-PR at a time
11+
concurrency:
12+
group: pr-${{ github.event.pull_request.number }}-preview
13+
cancel-in-progress: true
14+
15+
jobs:
16+
preview:
17+
# Avoid running this workflow for pull requests from forks, which would fail due to missing secrets
18+
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
# 1. Checkout the PR code
24+
- uses: actions/checkout@v4
25+
26+
# 2. Set up Node
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version-file: .nvmrc
30+
cache: yarn
31+
32+
# 3. Install dependencies for just the design-system-docs package
33+
- run: yarn workspaces focus --production @automattic/design-system-docs
34+
35+
# 4. Build the design-system-docs workspace
36+
- name: Build design system docs
37+
run: yarn workspace @automattic/design-system-docs build
38+
39+
# 5. Install Wrangler
40+
- run: npm install -g wrangler
41+
42+
# 6. Upload a new Worker version and capture the preview URL
43+
- name: Upload Worker version
44+
id: upload
45+
env:
46+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.DESIGN_SYSTEM_PREVIEW_CLOUDFLARE_ACCOUNT }}
47+
CLOUDFLARE_API_TOKEN: ${{ secrets.DESIGN_SYSTEM_PREVIEW_CLOUDFLARE_TOKEN }}
48+
run: |
49+
# Run the upload and tee output so it's visible in the GitHub Actions log
50+
OUT=$(wrangler versions upload --cwd apps/design-system-docs 2>&1 | tee /dev/stderr)
51+
52+
# Extract the preview URL from the output
53+
URL=$(echo "$OUT" | grep -oE 'https://[a-z0-9-]+-preview\.a8cds\.workers\.dev/?')
54+
55+
# Output the URL to the GitHub Actions log for debugging
56+
echo "URL: $URL"
57+
58+
# Expose it to later steps
59+
echo "url=$URL" >> "$GITHUB_OUTPUT"
60+
61+
# 7. Try to find an existing comment with our marker
62+
- name: Find preview comment
63+
id: find_comment
64+
uses: peter-evans/find-comment@v3
65+
with:
66+
issue-number: ${{ github.event.pull_request.number }}
67+
body-includes: '<!-- cf-preview-comment -->'
68+
69+
# 8. Create or update a comment that shows the preview URL
70+
- name: Comment (create or update)
71+
uses: peter-evans/create-or-update-comment@v4
72+
with:
73+
issue-number: ${{ github.event.pull_request.number }}
74+
comment-id: ${{ steps.find_comment.outputs.comment-id }}
75+
edit-mode: replace
76+
body: |
77+
<!-- cf-preview-comment -->
78+
**Design System Reference Site Preview:**
79+
80+
${{ steps.upload.outputs.url }}
81+
82+
(Latest commit: ${{ github.event.pull_request.head.sha }})

apps/design-system-docs/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626
"@docusaurus/core": "^3.7.0",
2727
"@docusaurus/preset-classic": "^3.7.0",
2828
"@mdx-js/react": "^3.1.0",
29+
"@wordpress/base-styles": "^5.23.0",
30+
"@wordpress/browserslist-config": "^6.23.0",
2931
"@wordpress/components": "^29.9.0",
32+
"docusaurus-plugin-sass": "^0.2.6",
3033
"prism-react-renderer": "^2.4.1",
3134
"react": "^18.3.1",
32-
"react-dom": "^18.3.1"
35+
"react-dom": "^18.3.1",
36+
"sass": "^1.54.0"
3337
},
3438
"devDependencies": {
3539
"@docusaurus/module-type-aliases": "^3.7.0",
3640
"@docusaurus/tsconfig": "^3.7.0",
3741
"@docusaurus/types": "^3.7.0",
3842
"@types/react": "^18.3.21",
39-
"@wordpress/base-styles": "^5.23.0",
40-
"@wordpress/browserslist-config": "^6.23.0",
41-
"docusaurus-plugin-sass": "^0.2.6",
42-
"sass": "^1.54.0",
4343
"typescript": "^5.8.3"
4444
},
4545
"optionalDependencies": {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "preview",
3+
"compatibility_date": "2025-05-28",
4+
"assets": {
5+
"directory": "./dist/",
6+
"not_found_handling": "404-page"
7+
}
8+
}

0 commit comments

Comments
 (0)