|
1 | 1 | name: CI |
2 | 2 |
|
3 | | -on: [push] |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + - synchronize |
4 | 9 |
|
5 | 10 | env: |
6 | 11 | BUILD_CACHE_KEY: ${{ github.sha }}-dist |
@@ -103,12 +108,47 @@ jobs: |
103 | 108 | run: >- |
104 | 109 | npx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} && |
105 | 110 | npx vercel build && |
106 | | - npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} |
| 111 | + npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > url.txt |
107 | 112 |
|
108 | 113 | - name: Vercel Pull/Build/Deploy (Production) |
109 | 114 | working-directory: examples/vite |
110 | 115 | if: ${{ github.ref_name == 'master' }} |
111 | 116 | run: >- |
112 | 117 | npx vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} && |
113 | 118 | npx vercel build --prod && |
114 | | - npx vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }} |
| 119 | + npx vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > url.txt |
| 120 | +
|
| 121 | + - name: Add links |
| 122 | + working-directory: examples/vite |
| 123 | + env: |
| 124 | + GH_TOKEN: ${{ github.token }} |
| 125 | + run: | |
| 126 | + npx zx << 'EOF' |
| 127 | + import project from './.vercel/project.json' with {type:"json"}; |
| 128 | +
|
| 129 | + const [pr, url] = await Promise.all([$`gh pr view ${{ github.event.number }} --json body`, $`cat ./url.txt`]); |
| 130 | + const body = JSON.parse(pr.stdout).body; |
| 131 | + const lines = body.split('\n'); |
| 132 | +
|
| 133 | + let linkIndex; |
| 134 | +
|
| 135 | + const linkText = `- [${project.projectName}](${url.stdout})`; |
| 136 | +
|
| 137 | + for (const lineIndex in lines) { |
| 138 | + const line = lines[lineIndex]; |
| 139 | +
|
| 140 | + if (line.startsWith(`- [${project.projectName}]`)) { |
| 141 | + lines[lineIndex] = linkText; |
| 142 | + linkIndex = +lineIndex; |
| 143 | + continue; |
| 144 | + } |
| 145 | + } |
| 146 | +
|
| 147 | + if (typeof linkIndex !== 'number') { |
| 148 | + lines.push('\n', linkText); |
| 149 | + } |
| 150 | +
|
| 151 | + $.sync`echo ${lines.join('\n').trim()} > ./body.txt` |
| 152 | +
|
| 153 | + $.sync`gh issue edit ${{ github.event.number }} --body-file ./body.txt`; |
| 154 | + EOF |
0 commit comments