Skip to content

Commit e427771

Browse files
committed
github: update preview action
1 parent 9a141e3 commit e427771

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

.github/workflows/build-prev.yml

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
name: Build Docs Preview
2-
32
permissions:
43
pull-requests: write
5-
64
on:
75
pull_request:
8-
96
jobs:
107
build:
118
name: Build Docs Preview
@@ -15,11 +12,9 @@ jobs:
1512
ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME }}
1613
ALGOLIA_SEARCH_API_KEY: ${{ secrets.ALGOLIA_SEARCH_API_KEY }}
1714
NODE_OPTIONS: --max_old_space_size=8192
18-
1915
steps:
2016
- uses: actions/checkout@v4
2117
- uses: pnpm/action-setup@v4
22-
2318
- name: Initial preview comment
2419
uses: peter-evans/create-or-update-comment@v4
2520
with:
@@ -29,10 +24,8 @@ jobs:
2924
body: |
3025
### Docs Preview
3126
- Status: ⏳ Creating preview…
32-
3327
- name: Install dependencies
3428
run: pnpm install
35-
3629
- name: Identify changed docs
3730
id: changes
3831
run: |
@@ -42,23 +35,19 @@ jobs:
4235
echo "files<<EOF" >> $GITHUB_OUTPUT
4336
echo "$CHANGED" >> $GITHUB_OUTPUT
4437
echo "EOF" >> $GITHUB_OUTPUT
45-
46-
# 5. Build site (allow failure)
4738
- name: Build site
4839
id: build
4940
run: |
5041
pnpm run build-prod
5142
continue-on-error: true
52-
53-
# 6. Generate the comment body
5443
- name: Generate comment body
5544
id: comment
5645
run: |
5746
# compute branch‑based preview URL
5847
BRANCH="${{ github.event.pull_request.head.ref }}"
5948
PREVIEW_URL="https://${BRANCH}.documentation-21k.pages.dev"
6049
LOG_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
61-
50+
6251
if [ "${{ steps.build.outcome }}" = "success" ]; then
6352
STATUS="✅ Build succeeded"
6453
LINK="Preview: [${PREVIEW_URL}](${PREVIEW_URL})"
@@ -68,31 +57,37 @@ jobs:
6857
# always link to last branch preview if available
6958
LINK="${LINK} | Previous preview: [${PREVIEW_URL}](${PREVIEW_URL})"
7059
fi
71-
60+
7261
BODY="### Docs Preview
7362
- Status: ${STATUS}
7463
- ${LINK}
75-
7664
**Changed pages:**"
77-
78-
# list each changed file as a page link
79-
while IFS= read -r f; do
80-
[ -z "$f" ] && continue
81-
REL_PATH="${f#docs/}"
82-
NAME=$(basename "${REL_PATH%.*}")
83-
URL="${PREVIEW_URL}/${REL_PATH%.*}.html"
84-
BODY="${BODY}
85-
- [${NAME}](${URL})"
86-
done <<< "${{ steps.changes.outputs.files }}"
87-
88-
echo "body<<EOF" >> $GITHUB_OUTPUT
89-
echo "$BODY" >> $GITHUB_OUTPUT
90-
echo "EOF" >> $GITHUB_OUTPUT
91-
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+
84+
echo "body<<EOF" >> $GITHUB_OUTPUT
85+
echo "$BODY" >> $GITHUB_OUTPUT
86+
echo "EOF" >> $GITHUB_OUTPUT
9287
- name: Update preview comment
9388
uses: peter-evans/create-or-update-comment@v4
9489
with:
9590
token: ${{ secrets.GITHUB_TOKEN }}
9691
issue-number: ${{ github.event.pull_request.number }}
9792
identifier: docs-preview
98-
body: ${{ steps.comment.outputs.body }}
93+
body: ${{ steps.comment.outputs.body }}

0 commit comments

Comments
 (0)