Repository navigation
67 lines (59 loc) · 2.25 KB
/
Copy pathtailwind-play-pr-preview.yml
File metadata and controls
67 lines (59 loc) · 2.25 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
name: "🆚 PR basic preview"
on:
pull_request_target:
types: [opened, synchronize]
paths:
- "packages/daisyui/src/components/*.css"
permissions:
contents: read
pull-requests: write
jobs:
preview:
name: "Create before/after links"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# pull_request_target has a write-capable token. Keep the checkout pinned to
# trusted base-branch code and read PR files only through git object data.
- name: Checkout trusted base revision
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.sha }}
fetch-depth: 1
persist-credentials: false
- name: Fetch PR revision as data
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: git fetch --no-tags --depth=1 origin "refs/pull/${PR_NUMBER}/head"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.4.0"
- name: Create Tailwind Play comparisons
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PREVIEW_OUTPUT: ${{ runner.temp }}/tailwind-play-preview.json
run: |
bun packages/tailwind-play-share/pr-preview.mjs \
--base-sha "$BASE_SHA" \
--head-sha "$HEAD_SHA" \
--output "$PREVIEW_OUTPUT"
- name: Comment on PR
uses: actions/github-script@v8
env:
PREVIEW_OUTPUT: ${{ runner.temp }}/tailwind-play-preview.json
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require("node:fs")
const preview = JSON.parse(fs.readFileSync(process.env.PREVIEW_OUTPUT, "utf8"))
const count = preview.components.length
const componentLabel = count === 1 ? "component" : "components"
const body = `${count} ${componentLabel} changed. Basic playground: [Before](${preview.beforeUrl}) vs. [After](${preview.afterUrl}).`
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
})