|
1 | 1 | name: CI |
2 | 2 |
|
3 | | -on: [push] |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + - synchronize |
| 9 | + - edited |
4 | 10 |
|
5 | 11 | env: |
6 | 12 | BUILD_CACHE_KEY: ${{ github.sha }}-dist |
@@ -103,12 +109,47 @@ jobs: |
103 | 109 | run: >- |
104 | 110 | npx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} && |
105 | 111 | npx vercel build && |
106 | | - npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} |
| 112 | + npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > url.txt |
107 | 113 |
|
108 | 114 | - name: Vercel Pull/Build/Deploy (Production) |
109 | 115 | working-directory: examples/vite |
110 | 116 | if: ${{ github.ref_name == 'master' }} |
111 | 117 | run: >- |
112 | 118 | npx vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} && |
113 | 119 | 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