Skip to content

Commit e28e57e

Browse files
Initial commit
1 parent 3d6bd9f commit e28e57e

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: CI
22

3-
on: [push]
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- edited
410

511
env:
612
BUILD_CACHE_KEY: ${{ github.sha }}-dist
@@ -103,12 +109,47 @@ jobs:
103109
run: >-
104110
npx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} &&
105111
npx vercel build &&
106-
npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
112+
npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > url.txt
107113
108114
- name: Vercel Pull/Build/Deploy (Production)
109115
working-directory: examples/vite
110116
if: ${{ github.ref_name == 'master' }}
111117
run: >-
112118
npx vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} &&
113119
npx vercel build --prod &&
114-
npx vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
120+
npx vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > url.txt
121+
122+
- name: Add links
123+
working-directory: examples/vite
124+
env:
125+
GH_TOKEN: ${{ github.token }}
126+
run: |
127+
npx zx << 'EOF'
128+
import project from './.vercel/project.json' with {type:"json"};
129+
130+
const [pr, url] = await Promise.all([$`gh pr view ${{ github.event.number }} --json body`, $`cat ./url.txt`]);
131+
const body = JSON.parse(pr.stdout).body;
132+
const lines = body.split('\n');
133+
134+
let linkIndex;
135+
136+
const linkText = `- [${project.projectName}](${url.stdout})`;
137+
138+
for (const lineIndex in lines) {
139+
const line = lines[lineIndex];
140+
141+
if (line.startsWith(`- [${project.projectName}]`)) {
142+
lines[lineIndex] = linkText;
143+
linkIndex = +lineIndex;
144+
continue;
145+
}
146+
}
147+
148+
if (typeof linkIndex !== 'number') {
149+
lines.push('\n', linkText);
150+
}
151+
152+
$.sync`echo ${lines.join('\n').trim()} > ./body.txt`
153+
154+
$.sync`gh issue edit ${{ github.event.number }} --body-file ./body.txt`;
155+
EOF

0 commit comments

Comments
 (0)