|
26 | 26 | with: |
27 | 27 | token: ${{ secrets.GITHUB_TOKEN }} |
28 | 28 |
|
29 | | - - name: 🧹 Strip stale deployment markers from README |
30 | | - if: github.event_name == 'push' |
31 | | - run: | |
32 | | - if [ -f README.md ] && grep -q '<!-- DEPLOYMENT-URL:START -->' README.md; then |
33 | | - echo "Stripping stale deployment markers from README..." |
34 | | - # Remove everything between markers (inclusive), handling duplicates |
35 | | - sed -i '/<!-- DEPLOYMENT-URL:START -->/,/<!-- DEPLOYMENT-URL:END -->/d' README.md |
36 | | - # Also clean up any git conflict markers that might be left over |
37 | | - sed -i '/^<<<<<<</d; /^=======/d; /^>>>>>>>/d' README.md |
38 | | - # Remove resulting double-blank-lines |
39 | | - sed -i '/^$/N;/^\n$/d' README.md |
40 | | - if ! git diff --quiet README.md; then |
41 | | - git config user.name "github-actions" |
42 | | - git config user.email "github-actions@github.com" |
43 | | - git add README.md |
44 | | - git commit -m "ci: clean stale deployment markers from README [skip ci]" |
45 | | - git push |
46 | | - echo "Cleaned up stale deployment markers." |
47 | | - fi |
48 | | - fi |
49 | | -
|
50 | 29 | - name: 🔧 Set deployment variables |
51 | 30 | id: vars |
52 | 31 | run: | |
@@ -210,73 +189,7 @@ jobs: |
210 | 189 | }); |
211 | 190 | } |
212 | 191 |
|
213 | | - - name: 📝 Update README with deployment URL |
214 | | - uses: actions/github-script@v7 |
215 | | - with: |
216 | | - script: | |
217 | | - const owner = context.repo.owner; |
218 | | - const repo = context.repo.repo; |
219 | | - const branch = '${{ steps.vars.outputs.branch }}'; |
220 | | - const previewUrl = '${{ steps.vars.outputs.preview_url }}'; |
221 | | - const sha = context.sha.substring(0, 7); |
222 | | - const date = new Date().toISOString().split('T')[0]; |
223 | | -
|
224 | | - // Fetch current README from the source branch |
225 | | - let readmeData; |
226 | | - try { |
227 | | - readmeData = await github.rest.repos.getContent({ |
228 | | - owner, repo, path: 'README.md', ref: branch, |
229 | | - }); |
230 | | - } catch (e) { |
231 | | - console.log('No README.md found, skipping update.'); |
232 | | - return; |
233 | | - } |
234 | | -
|
235 | | - const content = Buffer.from(readmeData.data.content, 'base64').toString('utf8'); |
236 | | -
|
237 | | - const marker = { |
238 | | - start: '<!-- DEPLOYMENT-URL:START -->', |
239 | | - end: '<!-- DEPLOYMENT-URL:END -->', |
240 | | - }; |
241 | | -
|
242 | | - const section = [ |
243 | | - marker.start, |
244 | | - `🌐 **Live Preview:** [${previewUrl}](${previewUrl})`, |
245 | | - `<sub>Deployed from \`${sha}\` on ${date}</sub>`, |
246 | | - marker.end, |
247 | | - ].join('\n'); |
248 | | -
|
249 | | - let updated; |
250 | | - if (content.includes(marker.start)) { |
251 | | - // Replace existing section |
252 | | - const re = new RegExp( |
253 | | - `${marker.start}[\\s\\S]*?${marker.end}`, |
254 | | - ); |
255 | | - updated = content.replace(re, section); |
256 | | - } else { |
257 | | - // Insert after the first heading line |
258 | | - const lines = content.split('\n'); |
259 | | - const headingIdx = lines.findIndex(l => l.startsWith('# ')); |
260 | | - if (headingIdx !== -1) { |
261 | | - lines.splice(headingIdx + 1, 0, '', section, ''); |
262 | | - updated = lines.join('\n'); |
263 | | - } else { |
264 | | - updated = section + '\n\n' + content; |
265 | | - } |
266 | | - } |
267 | | -
|
268 | | - if (updated !== content) { |
269 | | - await github.rest.repos.createOrUpdateFileContents({ |
270 | | - owner, repo, path: 'README.md', |
271 | | - message: `docs: update deployment URL for ${branch} [skip ci]`, |
272 | | - content: Buffer.from(updated).toString('base64'), |
273 | | - sha: readmeData.data.sha, |
274 | | - branch, |
275 | | - }); |
276 | | - console.log(`README updated with preview URL: ${previewUrl}`); |
277 | | - } |
278 | | -
|
279 | | - - name: 📌 Update PR description with preview URL |
| 192 | + - name: Update PR description with preview URL |
280 | 193 | uses: actions/github-script@v7 |
281 | 194 | with: |
282 | 195 | script: | |
|
0 commit comments