Skip to content

Commit d58ea68

Browse files
EdwardAngertclaude
andcommitted
fix: ensure docs preview comment updates properly
- Refactor docs-preview.yaml to use unified workflow for better consistency - Fix document change detection to only count actual doc files - Add PR number prioritization and passing between workflows - Improve debugging output for easier troubleshooting - Fix issues with comment not updating on doc changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ddc128b commit d58ea68

File tree

3 files changed

+59
-97
lines changed

3 files changed

+59
-97
lines changed

.github/docs/actions/docs-shared/action.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ runs:
173173
echo "$DELETED_FILES" | jq -r '.[] | select(endswith(".md"))' >> $GITHUB_OUTPUT
174174
echo "EOF" >> $GITHUB_OUTPUT
175175
176-
# Determine if docs have changed
177-
DOC_COUNT=$(echo "$CHANGED_FILES" | jq '. | length')
176+
# Determine if docs have changed - count ONLY doc files, not all files
177+
DOC_FILES=$(echo "$CHANGED_FILES" | jq -r '.[] | select(endswith(".md") or endswith(".png") or endswith(".jpg") or endswith(".jpeg") or endswith(".gif") or endswith(".svg")) | select(startswith("docs/") or startswith("${{ inputs.docs-dir }}/"))')
178+
DOC_COUNT=$(echo "$DOC_FILES" | grep -v '^$' | wc -l | tr -d ' ')
179+
180+
echo "::debug::Documentation file detection: Found $DOC_COUNT doc files"
181+
178182
if [ "$DOC_COUNT" -gt 0 ]; then
179183
echo "has_changes=true" >> $GITHUB_OUTPUT
180184
else
@@ -736,6 +740,9 @@ runs:
736740
if: inputs.post-comment == 'true' && steps.process-files.outputs.has_changes == 'true'
737741
shell: bash
738742
run: |
743+
# Force PR number to be visible in logs (debugging)
744+
echo "::notice::PR number for commenting: '${{ inputs.pr-number }}'"
745+
739746
if [ -z "${{ inputs.pr-number }}" ]; then
740747
echo "::warning::PR number not provided for commenting. Skipping comment creation."
741748
echo "valid=false" >> $GITHUB_OUTPUT

.github/workflows/docs-preview.yaml

Lines changed: 30 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4,106 +4,43 @@ on:
44
types: [opened, synchronize, reopened]
55
paths:
66
- 'docs/**'
7+
- '**.md'
8+
- '.github/docs/**'
9+
- '.github/workflows/docs-preview.yaml'
710

811
permissions:
912
contents: read
1013

1114
jobs:
12-
preview:
13-
name: Generate docs preview
15+
# Extract PR information for the unified workflow
16+
prepare:
17+
name: Extract PR Information
1418
runs-on: ubuntu-latest
15-
permissions:
16-
pull-requests: write # needed for commenting on PRs
19+
outputs:
20+
pr_number: ${{ steps.pr_info.outputs.pr_number }}
1721
steps:
18-
- name: Harden Runner
19-
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
20-
with:
21-
egress-policy: audit
22-
23-
- name: Checkout
24-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25-
with:
26-
fetch-depth: 0
27-
2822
- name: Get PR info
2923
id: pr_info
3024
run: |
31-
set -euo pipefail
32-
PR_NUMBER=${{ github.event.pull_request.number }}
33-
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
34-
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_OUTPUT
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
38-
- name: Get changed files
39-
id: changed-files
40-
uses: tj-actions/changed-files@v45
41-
with:
42-
files: |
43-
docs/**
44-
45-
- name: Debug changed files
46-
run: |
47-
echo "All changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
48-
echo "JSON format: ${{ steps.changed-files.outputs.all_changed_files_json }}"
49-
50-
- name: Check if manifest changed
51-
id: manifest-check
52-
run: |
53-
echo "changed=${{ contains(steps.changed-files.outputs.all_changed_files, 'docs/manifest.json') }}" >> $GITHUB_OUTPUT
54-
55-
- name: Generate docs preview
56-
id: docs-preview
57-
uses: ./.github/docs/actions/docs-preview
58-
with:
59-
github-token: ${{ secrets.GITHUB_TOKEN }}
60-
changed-files: ${{ steps.changed-files.outputs.all_changed_files_json }}
61-
manifest-changed: ${{ steps.manifest-check.outputs.changed }}
62-
63-
- name: Debug outputs
64-
run: |
65-
echo "Has changes: ${{ steps.docs-preview.outputs.has_changes }}"
66-
echo "URL: ${{ steps.docs-preview.outputs.url }}"
67-
echo "Changed files:"
68-
echo "${{ steps.docs-preview.outputs.changed_files }}"
69-
70-
- name: Find existing comment
71-
if: steps.docs-preview.outputs.has_changes == 'true'
72-
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
73-
id: find-comment
74-
with:
75-
issue-number: ${{ env.PR_NUMBER }}
76-
comment-author: 'github-actions[bot]'
77-
body-includes: '## 📚 Docs Preview'
78-
direction: last
79-
80-
- name: Create or update preview comment
81-
if: steps.docs-preview.outputs.has_changes == 'true'
82-
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
83-
env:
84-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85-
with:
86-
comment-id: ${{ steps.find-comment.outputs.comment-id }}
87-
issue-number: ${{ env.PR_NUMBER }}
88-
body: |
89-
## 📚 Docs Preview
90-
91-
Your documentation changes are available for preview at:
92-
**🔗 [Documentation Preview](${{ steps.docs-preview.outputs.url }})**
93-
94-
> Note: Branch names with slashes (e.g., `username/feature`) are converted to dashes (e.g., `username-feature`) in the preview URL.
95-
96-
### Changed Documentation Files
97-
${{ steps.docs-preview.outputs.changed_files }}
98-
99-
${{ steps.docs-preview.outputs.has_new_docs == 'true' && '### Newly Added Documentation' || '' }}
100-
${{ steps.docs-preview.outputs.has_new_docs == 'true' && steps.docs-preview.outputs.new_docs || '' }}
101-
102-
${{ steps.docs-preview.outputs.has_new_docs == 'true' && '### Preview Links for New Docs' || '' }}
103-
${{ steps.docs-preview.outputs.has_new_docs == 'true' && steps.docs-preview.outputs.preview_links || '' }}
104-
105-
---
106-
<sub>🤖 This comment is automatically generated and updated when documentation changes.</sub>
107-
edit-mode: replace
108-
reactions: eyes
109-
reactions-edit-mode: replace
25+
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
26+
echo "::notice::Extracted PR number: ${{ github.event.pull_request.number }}"
27+
28+
# Use the unified workflow to generate the preview and validation results
29+
docs-preview:
30+
name: Generate Docs Preview
31+
needs: prepare
32+
uses: ./.github/workflows/docs-unified.yaml
33+
permissions:
34+
contents: read
35+
pull-requests: write
36+
with:
37+
# Focus on the preview and validation
38+
lint-markdown: true
39+
check-format: true
40+
check-links: true
41+
check-cross-references: true
42+
lint-vale: true
43+
generate-preview: true
44+
post-comment: true
45+
fail-on-error: false
46+
pr-number: ${{ needs.prepare.outputs.pr_number }}

.github/workflows/docs-unified.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ on:
4242
required: false
4343
type: boolean
4444
default: false
45+
pr-number:
46+
description: 'PR number for commenting (if passed from calling workflow)'
47+
required: false
48+
type: string
49+
default: ''
4550

4651
jobs:
4752
docs-check:
@@ -85,10 +90,22 @@ jobs:
8590
# Phase 2: Prepare PR Information
8691
- name: Get PR info
8792
id: pr_info
88-
if: github.event.pull_request
8993
run: |
9094
set -euo pipefail
91-
PR_NUMBER=${{ github.event.pull_request.number }}
95+
96+
# First check if PR number is passed as input
97+
if [ -n "${{ inputs.pr-number }}" ]; then
98+
PR_NUMBER="${{ inputs.pr-number }}"
99+
echo "::notice::Using PR number from workflow input: #${PR_NUMBER}"
100+
# Otherwise try to get it from the event context
101+
elif [ -f "$GITHUB_EVENT_PATH" ] && [ "${{ github.event_name }}" == "pull_request" ]; then
102+
PR_NUMBER="${{ github.event.pull_request.number }}"
103+
echo "::notice::Using PR number from event context: #${PR_NUMBER}"
104+
else
105+
echo "::warning::No PR number available. Commenting will be skipped."
106+
PR_NUMBER=""
107+
fi
108+
92109
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
93110
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_OUTPUT
94111
env:
@@ -111,6 +128,7 @@ jobs:
111128
lint-vale: ${{ inputs.lint-vale }}
112129
generate-preview: ${{ inputs.generate-preview }}
113130
post-comment: ${{ inputs.post-comment }}
131+
# Pass PR number with proper prioritization
114132
pr-number: "${{ env.PR_NUMBER }}"
115133
fail-on-error: ${{ inputs.fail-on-error }}
116134

0 commit comments

Comments
 (0)