-
Notifications
You must be signed in to change notification settings - Fork 860
[CI] Add Report Preview URLs Workflow #7524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SigureMo
merged 2 commits into
PaddlePaddle:develop
from
ooooo-create:ci/report_preview_url
Oct 7, 2025
+152
−0
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Comment Preview URLs | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Generate Preview URLs"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
comment: | ||
name: Post Preview URLs Comment | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
permissions: | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
run-id: ${{ github.event.workflow_run.id }} | ||
|
||
- name: Read PR metadata | ||
id: pr-metadata | ||
run: | | ||
PR_NUMBER=$(find . -name "pr_number.txt" -exec cat {} \;) | ||
PR_SHA=$(find . -name "pr_sha.txt" -exec cat {} \;) | ||
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT | ||
echo "pr_sha=$PR_SHA" >> $GITHUB_OUTPUT | ||
|
||
- name: Read preview URLs | ||
id: preview-urls | ||
run: | | ||
PREVIEW_CONTENT=$(find . -name "preview_urls.txt" -exec cat {} \;) | ||
{ | ||
echo 'content<<EOF' | ||
echo "$PREVIEW_CONTENT" | ||
echo EOF | ||
} >> $GITHUB_OUTPUT | ||
|
||
- name: Find existing comment | ||
uses: peter-evans/find-comment@v4 | ||
id: fc | ||
with: | ||
issue-number: ${{ steps.pr-metadata.outputs.pr_number }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: '本次 PR 文档预览链接' | ||
|
||
- name: Create or update comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ steps.pr-metadata.outputs.pr_number }} | ||
body: ${{ steps.preview-urls.outputs.content }} | ||
edit-mode: replace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Generate Preview URLs | ||
|
||
on: | ||
pull_request: | ||
branches: ["develop"] | ||
paths: | ||
- 'docs/**.rst' | ||
- 'docs/**.md' | ||
|
||
jobs: | ||
generate-urls: | ||
name: Generate Preview URLs | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout PR branch | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Fetch base branch | ||
run: | | ||
git fetch origin develop:develop | ||
|
||
- name: Generate preview URLs | ||
id: generate | ||
run: | | ||
chmod +x ci_scripts/report_preview_url.sh | ||
./ci_scripts/report_preview_url.sh ${{ github.event.pull_request.number }} > preview_urls.txt | ||
|
||
- name: Upload preview URLs as artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: preview-urls-${{ github.event.pull_request.number }} | ||
path: preview_urls.txt | ||
retention-days: 1 | ||
|
||
- name: Save PR metadata | ||
run: | | ||
echo "${{ github.event.pull_request.number }}" > pr_number.txt | ||
echo "${{ github.event.pull_request.head.sha }}" > pr_sha.txt | ||
|
||
- name: Upload PR metadata | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: pr-metadata-${{ github.event.pull_request.number }} | ||
path: | | ||
pr_number.txt | ||
pr_sha.txt | ||
retention-days: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
pr_id="$1" | ||
|
||
if [ -z "$pr_id" ]; then | ||
echo "Error: Pull Request ID is not provided." | ||
exit 1 | ||
fi | ||
|
||
generate_preview_url() { | ||
local file_path="$1" | ||
local pr_id="$2" | ||
local path_no_ext="${file_path%.*}" | ||
local base_url="http://preview-pr-${pr_id}.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/" | ||
local final_url="${base_url}${path_no_ext}.html" | ||
echo "$final_url" | ||
} | ||
|
||
mapfile -t all_git_files < <(git diff --name-only --diff-filter=ACMR develop | sed 's#^docs/##') | ||
|
||
output_lines=() | ||
|
||
for file in "${all_git_files[@]}"; do | ||
if [[ "$file" == *.rst || "$file" == *.md ]]; then | ||
url=$(generate_preview_url "$file" "$pr_id") | ||
output_lines+=("- \`docs/${file}\`: [点击预览](${url})") | ||
fi | ||
done | ||
|
||
|
||
if [ ${#output_lines[@]} -gt 0 ]; then | ||
cat <<-EOF | ||
<details> | ||
<summary>📚 本次 PR 文档预览链接 (点击展开)</summary> | ||
|
||
以下是本次 PR 中变更文档的预览链接: | ||
|
||
$(printf '%s\n' "${output_lines[@]}") | ||
|
||
</details> | ||
EOF | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.