Skip to content

Commit 0b9fdb4

Browse files
authored
ci: workflow support for dependency preview and online docs (#268)
1 parent f5442f3 commit 0b9fdb4

6 files changed

Lines changed: 345 additions & 91 deletions

File tree

.github/workflows/e2e-tests.yml

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

.github/workflows/pr-ci-build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: 'CI: Build'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
skip-playground:
7+
description: 'Skip playground build'
8+
type: boolean
9+
default: false
10+
11+
jobs:
12+
build-job:
13+
name: build
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
27+
- name: Get pnpm store directory
28+
id: pnpm-cache
29+
run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
30+
31+
- name: Setup pnpm cache
32+
uses: actions/cache@v4
33+
with:
34+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
35+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
36+
restore-keys: |
37+
${{ runner.os }}-pnpm-store-
38+
39+
- name: Install dependencies
40+
run: pnpm i --no-frozen-lockfile
41+
42+
- name: Build components
43+
run: pnpm build
44+
45+
- name: Upload build artifacts
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: build-${{ github.sha }}
49+
path: |
50+
packages/components/dist
51+
packages/kit/dist
52+
packages/svgs/dist
53+
retention-days: 1
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'CI: E2E Test'
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
test-job:
8+
name: e2e-test
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 60
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Setup pnpm
16+
uses: pnpm/action-setup@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
23+
- name: Get pnpm store directory
24+
id: pnpm-cache
25+
run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
26+
27+
- name: Setup pnpm cache
28+
uses: actions/cache@v4
29+
with:
30+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
31+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
32+
restore-keys: |
33+
${{ runner.os }}-pnpm-store-
34+
35+
- name: Install dependencies
36+
run: pnpm i --no-frozen-lockfile
37+
38+
- name: Download build artifacts
39+
uses: actions/download-artifact@v4
40+
with:
41+
name: build-${{ github.sha }}
42+
path: packages
43+
44+
- name: Install Playwright Browser
45+
run: |
46+
cd packages/test
47+
npx playwright install --with-deps chromium
48+
49+
- name: Run Playwright Tests
50+
run: pnpm test
51+
52+
- name: Upload Playwright Test Report
53+
uses: actions/upload-artifact@v4
54+
if: always()
55+
with:
56+
name: playwright-report-${{ github.sha }}
57+
path: packages/test/playwright-report/
58+
retention-days: 13
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: 'CI: Preview'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
pr-number:
7+
description: 'Pull Request number'
8+
type: number
9+
required: true
10+
11+
jobs:
12+
preview-job:
13+
name: preview
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
registry-url: 'https://registry.npmjs.org'
27+
28+
- name: Get pnpm store directory
29+
id: pnpm-cache
30+
run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
31+
32+
- name: Setup pnpm cache
33+
uses: actions/cache@v4
34+
with:
35+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
36+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37+
restore-keys: |
38+
${{ runner.os }}-pnpm-store-
39+
40+
- name: Install dependencies
41+
run: pnpm i --no-frozen-lockfile
42+
43+
- name: Download build artifacts
44+
uses: actions/download-artifact@v4
45+
with:
46+
name: build-${{ github.sha }}
47+
path: packages
48+
49+
- name: Build docs only (components already built)
50+
run: pnpm -F docs build
51+
52+
- name: Comment build generating
53+
if: github.event_name == 'pull_request'
54+
uses: actions-cool/maintain-one-comment@v3.1.1
55+
with:
56+
token: ${{ secrets.GITHUB_TOKEN }}
57+
body: |
58+
[<img width="400" src="https://github.com/user-attachments/assets/c25bbbe4-0cf5-4aca-b4b3-db49e7a264d9">](#)
59+
60+
🔨 Building packages...
61+
<!-- TINY_ROBOT_BUILD -->
62+
body-include: '<!-- TINY_ROBOT_BUILD -->'
63+
number: ${{ inputs.pr-number }}
64+
65+
- name: Publish to pkg.pr.new
66+
id: pkg-pr-new
67+
run: |
68+
npx pkg-pr-new publish \
69+
./packages/components \
70+
./packages/kit \
71+
./packages/svgs \
72+
--pnpm \
73+
--json output.json \
74+
--comment=off
75+
76+
- name: Post or update pkg.pr.new comment
77+
if: github.event_name == 'pull_request'
78+
uses: actions/github-script@v7
79+
with:
80+
github-token: ${{ secrets.GITHUB_TOKEN }}
81+
script: |
82+
const fs = require('fs');
83+
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
84+
85+
const sha = context.payload.pull_request.head.sha.substring(0, 7);
86+
87+
const packages = output.packages.map((p) => {
88+
const shortUrl = p.url.replace(/@[a-f0-9]{40}/, '@' + sha);
89+
return 'pnpm add ' + shortUrl;
90+
}).join('\n\n');
91+
92+
const commitUrl = 'https://github.com/' + context.repo.owner + '/' + context.repo.repo + '/commit/' + sha;
93+
94+
const body = '## 📦 Package Preview\n\n' + packages + '\n\n**commit:** [' + sha + '](' + commitUrl + ')\n\n<!-- PKG_PR_NEW_COMMENT -->';
95+
const botCommentIdentifier = '<!-- PKG_PR_NEW_COMMENT -->';
96+
97+
const comments = await github.rest.issues.listComments({
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
issue_number: context.issue.number,
101+
});
102+
103+
const existingComment = comments.data.find((comment) =>
104+
comment.body.includes(botCommentIdentifier)
105+
);
106+
107+
if (existingComment) {
108+
await github.rest.issues.updateComment({
109+
owner: context.repo.owner,
110+
repo: context.repo.repo,
111+
comment_id: existingComment.id,
112+
body: body,
113+
});
114+
} else {
115+
await github.rest.issues.createComment({
116+
issue_number: context.issue.number,
117+
owner: context.repo.owner,
118+
repo: context.repo.repo,
119+
body: body,
120+
});
121+
}
122+
123+
- name: Deploy Site to Surge
124+
id: deploy
125+
run: |
126+
DEPLOY_DOMAIN=preview-${{ inputs.pr-number }}-tiny-robot.surge.sh
127+
echo "Deploying to: https://$DEPLOY_DOMAIN"
128+
npx surge --project ./docs/dist --domain $DEPLOY_DOMAIN --token $SURGE_TOKEN
129+
echo "url=https://$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
130+
env:
131+
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
132+
133+
- name: Comment build success
134+
if: ${{ success() && github.event_name == 'pull_request' }}
135+
uses: actions-cool/maintain-one-comment@v3.1.1
136+
with:
137+
token: ${{ secrets.GITHUB_TOKEN }}
138+
body: |
139+
[<img width="400" src="https://github.com/user-attachments/assets/2a0bb639-dfaf-4384-8d73-cec616ea4b97">](https://preview-${{ inputs.pr-number }}-tiny-robot.surge.sh)
140+
141+
✅ Preview build completed successfully!
142+
143+
> Click the image above to preview.
144+
> Preview will be automatically removed when this PR is closed.
145+
<!-- TINY_ROBOT_BUILD -->
146+
body-include: '<!-- TINY_ROBOT_BUILD -->'
147+
number: ${{ inputs.pr-number }}
148+
149+
- name: Comment build failed
150+
if: ${{ failure() && github.event_name == 'pull_request' }}
151+
uses: actions-cool/maintain-one-comment@v3.1.1
152+
with:
153+
token: ${{ secrets.GITHUB_TOKEN }}
154+
body: |
155+
[<img width="400" src="https://github.com/user-attachments/assets/acfe799d-40be-4ffb-8190-da33f84056dc">](#)
156+
157+
❌ Build failed. Please check the logs for details.
158+
<!-- TINY_ROBOT_BUILD -->
159+
body-include: '<!-- TINY_ROBOT_BUILD -->'
160+
number: ${{ inputs.pr-number }}

0 commit comments

Comments
 (0)