-
Notifications
You must be signed in to change notification settings - Fork 145
140 lines (115 loc) · 3.96 KB
/
pr_helper.yml
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
name: PR Helper
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
pull-requests: write
jobs:
screenshot:
runs-on: ubuntu-latest
name: Screenshot
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
registry-url: 'https://registry.npmjs.org'
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Take Screenshot
id: screenshot
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
sha="$GITHUB_SHA"
pnpm install
git fetch origin
networks=$(
git diff --name-only origin/$GITHUB_BASE_REF \
| grep db/ \
| sed -E 's/db\/(.*)[.]json/\1/'
)
mkdir -p build
./cli build:visual
pnpm vite preview \
--host 0.0.0.0 \
--port 4173 \
--strictPort \
-c test/visual/vite.config.js \
-l silent \
"test/visual" \
&
pid="$!"
scale=2
pnpx playwright install
for network in $networks
do
pnpx playwright screenshot \
--viewport-size="$((850 * $scale)), $((400 * $scale))" \
"http://localhost:4173?network=$network&knobs=false&scale=$scale" \
"./build/$network.png"
done
pnpx playwright screenshot \
--full-page \
"http://localhost:4173?knobs=false&scale=$scale" \
"./build/index.png"
kill $pid
link_networks=""
for network in $networks
do
pnpm wrangler r2 object put \
-f ./build/$network.png \
react-social-icons/pr-images/$sha/$network.png
link_networks="$link_networks,https://static.react-social-icons.com/pr-images/$sha/$network.png"
done
pnpm wrangler r2 object put \
-f ./build/index.png \
react-social-icons/pr-images/$sha/index.png
link_index="https://static.react-social-icons.com/pr-images/$sha/index.png"
echo "link_networks=$link_networks" >> $GITHUB_OUTPUT
echo "link_index=$link_index" >> $GITHUB_OUTPUT
- name: Comment on PR with screenshots
uses: actions/github-script@v7
with:
script: |
const link_networks = '${{ steps.screenshot.outputs.link_networks }}'.split(',');
const link_index = '${{ steps.screenshot.outputs.link_index }}'
github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.number,
event: 'COMMENT',
body: `
<h1>Screenshots</h1>
${link_networks
.filter(link => link.length > 0)
.sort((a, b) => a.localeCompare(b))
.map(link => {
const filename = link.replace(/^.*\//u, '')
const network = filename.replace('.png', '')
return `
<details>
<summary>
${network}
</summary>
<img
src="${link}"
alt="screenshot of an updated social network"
/>
</details>
`;
})
}
<details>
<summary>All Networks</summary>
<img
src="${link_index}"
alt="screenshot of all networks"
/>
</details>
`.replace(/^\s+/gm, '').trim()
})