@@ -15,12 +15,22 @@ jobs:
1515 steps :
1616 - uses : actions/checkout@v4
1717 - uses : pnpm/action-setup@v4
18- - name : Initial preview comment
18+ - name : Find or create preview comment
19+ uses : peter-evans/find-comment@v3
20+ id : find-comment
21+ with :
22+ token : ${{ secrets.GITHUB_TOKEN }}
23+ issue-number : ${{ github.event.pull_request.number }}
24+ comment-author : ' github-actions[bot]'
25+ body-includes : ' ### Docs Preview'
26+
27+ - name : Create or update initial preview comment
1928 uses : peter-evans/create-or-update-comment@v4
2029 with :
2130 token : ${{ secrets.GITHUB_TOKEN }}
2231 issue-number : ${{ github.event.pull_request.number }}
23- identifier : docs-preview
32+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
33+ edit-mode : replace
2434 body : |
2535 ### Docs Preview
2636 - Status: ⏳ Creating preview…
@@ -35,19 +45,20 @@ jobs:
3545 echo "files<<EOF" >> $GITHUB_OUTPUT
3646 echo "$CHANGED" >> $GITHUB_OUTPUT
3747 echo "EOF" >> $GITHUB_OUTPUT
48+ # 5. Build site (allow failure)
3849 - name : Build site
3950 id : build
4051 run : |
4152 pnpm run build-prod
4253 continue-on-error : true
54+ # 6. Generate the comment body
4355 - name : Generate comment body
4456 id : comment
4557 run : |
4658 # compute branch‑based preview URL
4759 BRANCH="${{ github.event.pull_request.head.ref }}"
4860 PREVIEW_URL="https://${BRANCH}.documentation-21k.pages.dev"
4961 LOG_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
50-
5162 if [ "${{ steps.build.outcome }}" = "success" ]; then
5263 STATUS="✅ Build succeeded"
5364 LINK="Preview: [${PREVIEW_URL}](${PREVIEW_URL})"
@@ -57,37 +68,27 @@ jobs:
5768 # always link to last branch preview if available
5869 LINK="${LINK} | Previous preview: [${PREVIEW_URL}](${PREVIEW_URL})"
5970 fi
60-
6171 BODY="### Docs Preview
6272 - Status: ${STATUS}
6373 - ${LINK}
6474 **Changed pages:**"
65-
66- # Process changed files using a more reliable approach
67- if [ -n "${{ steps.changes.outputs.files }}" ]; then
68- echo "${{ steps.changes.outputs.files }}" | while IFS= read -r f; do
69- [ -z "$f" ] && continue
70- REL_PATH="${f#docs/}"
71- NAME=$(basename "${REL_PATH%.*}")
72- URL="${PREVIEW_URL}/${REL_PATH%.*}.html"
73- echo "- [${NAME}](${URL})"
74- done > /tmp/changed_files_list.txt
75-
76- # Read the processed content and append to BODY
77- if [ -f /tmp/changed_files_list.txt ]; then
78- CHANGED_PAGES=$(cat /tmp/changed_files_list.txt)
79- BODY="${BODY}
80- ${CHANGED_PAGES}"
81- fi
82- fi
83-
75+ # list each changed file as a page link
76+ while IFS= read -r f; do
77+ [ -z "$f" ] && continue
78+ REL_PATH="${f#docs/}"
79+ NAME=$(basename "${REL_PATH%.*}")
80+ URL="${PREVIEW_URL}/${REL_PATH%.*}.html"
81+ BODY="${BODY}
82+ - [${NAME}](${URL})"
83+ done <<< "${{ steps.changes.outputs.files }}"
8484 echo "body<<EOF" >> $GITHUB_OUTPUT
8585 echo "$BODY" >> $GITHUB_OUTPUT
8686 echo "EOF" >> $GITHUB_OUTPUT
87- - name : Update preview comment
87+ - name : Update preview comment with results
8888 uses : peter-evans/create-or-update-comment@v4
8989 with :
9090 token : ${{ secrets.GITHUB_TOKEN }}
9191 issue-number : ${{ github.event.pull_request.number }}
92- identifier : docs-preview
92+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
93+ edit-mode : replace
9394 body : ${{ steps.comment.outputs.body }}
0 commit comments