-
Notifications
You must be signed in to change notification settings - Fork 6k
[CI] Add Report Preview URLs Workflow #75687
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 5 commits into
PaddlePaddle:develop
from
ooooo-create:ci/report_preview_urls
Oct 12, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a77291
[CI] Add Report Preview URLs Workflow
ooooo-create 8ba25f2
revert api docstring change
ooooo-create f0e3d61
revert debug code
ooooo-create d26fc9f
move note inside \details\
ooooo-create 9282515
use argparse to parse args && change error to comment_body && fix the…
ooooo-create 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: ["Doc-Preview"] | ||
| 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 | ||
| id: download | ||
| uses: actions/download-artifact@v4 | ||
| continue-on-error: true | ||
| with: | ||
| name: doc-preview-comment | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
|
|
||
| - name: Read artifacts | ||
| id: artifacts-data | ||
| if: steps.download.outcome == 'success' | ||
| run: | | ||
| PR_NUMBER=$(cat pr_number.txt) | ||
| echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT | ||
| COMMENT_BODY=$(cat comment_body.txt) | ||
| { | ||
| echo 'comment_body<<EOF' | ||
| echo "$COMMENT_BODY" | ||
| echo EOF | ||
| } >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Find existing comment | ||
| id: fc | ||
| if: steps.download.outcome == 'success' | ||
| uses: peter-evans/find-comment@v4 | ||
| with: | ||
| issue-number: ${{ steps.artifacts-data.outputs.pr_number }} | ||
| comment-author: 'github-actions[bot]' | ||
| body-includes: 'Preview documentation links for API changes in this PR' | ||
|
|
||
| - name: Create or update comment | ||
| if: steps.download.outcome == 'success' | ||
| uses: peter-evans/create-or-update-comment@v4 | ||
| with: | ||
| comment-id: ${{ steps.fc.outputs.comment-id }} | ||
| issue-number: ${{ steps.artifacts-data.outputs.pr_number }} | ||
| body: ${{ steps.artifacts-data.outputs.comment_body }} | ||
| 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import importlib | ||
| import inspect | ||
| import re | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
|
|
||
| import paddle # noqa: F401 | ||
|
|
||
|
|
||
| def load_api_by_name(path: str) -> Callable[..., Any] | None: | ||
| """ | ||
| Recursively resolves a string path to a Python object. | ||
| """ | ||
| if not path: | ||
| return None | ||
|
|
||
| # First, try to import the entire path as a module (e.g., "paddle" or "paddle.autograd"). | ||
| try: | ||
| return importlib.import_module(path) | ||
| except ImportError: | ||
| # If the import fails, it might be an object within a module. | ||
| # If there's no dot, it was a failed top-level import, so we can't proceed. | ||
| if "." not in path: | ||
| return None | ||
|
|
||
| # Split the path into its parent and the final object name. | ||
| # e.g., "paddle.Tensor" -> parent="paddle", child="Tensor" | ||
| parent_path, child_name = path.rsplit('.', 1) | ||
| parent_obj = load_api_by_name(parent_path) | ||
|
|
||
| # If the parent object could not be resolved, we can't find the child. | ||
| if parent_obj is None: | ||
| return None | ||
|
|
||
| # Use getattr with a default value to safely get the child object. | ||
| return getattr(parent_obj, child_name, None) | ||
|
|
||
|
|
||
| def generate_comment_body(doc_diff: str, pr_id: int) -> str: | ||
| if not doc_diff: | ||
| return "" | ||
|
|
||
| output_lines: list[str] = [] | ||
| base_url = f"http://preview-paddle-pr-{pr_id}.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/en/api" | ||
|
|
||
| # Extract API names like 'paddle.autograd.backward' from lines like: | ||
| # - paddle.autograd.backward (ArgSpec(...), ('document', ...)) | ||
| # + paddle.autograd.backward (ArgSpec(...), ('document', ...)) | ||
| apis: list[str] = sorted( | ||
| set(re.findall(r"^[+]\s*([a-zA-Z0-9_.]+)\s*\(", doc_diff, re.MULTILINE)) | ||
| ) | ||
| # All apis should be loaded, this seems a explicitly check. | ||
| unload_apis: list[str] = [] | ||
|
|
||
| if not apis: | ||
| return "" | ||
|
|
||
| for api in apis: | ||
| api_obj = load_api_by_name(api) | ||
|
|
||
| if api_obj is None: | ||
| unload_apis.append(api) | ||
| continue | ||
|
|
||
| api_path = api.replace('.', '/') | ||
| url = f"{base_url}/{api_path}_en.html" | ||
|
|
||
| if "." in api: | ||
| parent_path, child_name = api.rsplit('.', 1) | ||
| parent_obj = load_api_by_name(parent_path) | ||
| if inspect.isclass(parent_obj) and not inspect.isclass(api_obj): | ||
| parent_api_path = parent_path.replace('.', '/') | ||
| url = f"{base_url}/{parent_api_path}_en.html#{child_name}" | ||
|
|
||
| output_lines.append(f"- **{api}**: [Preview]({url})") | ||
| unload_error_msg = ( | ||
| f"@ooooo-create, following apis cannot be loaded, please check it: {', '.join(unload_apis)}" | ||
| if unload_apis | ||
| else "" | ||
| ) | ||
|
|
||
| if not output_lines: | ||
| return unload_error_msg | ||
|
|
||
| api_links = "\n".join(output_lines) | ||
| comment_body = f"""<details> | ||
| <summary>📚 Preview documentation links for API changes in this PR (Click to expand)</summary> | ||
|
|
||
| {unload_error_msg} | ||
|
|
||
| <table> | ||
| <tr> | ||
| <td> | ||
| ℹ️ <b>Preview Notice</b><br> | ||
| Please wait for the <code>Doc-Preview</code> workflow to complete before clicking the preview links below, otherwise you may see outdated content. | ||
| </td> | ||
| </tr> | ||
| </table> | ||
|
|
||
| The following are preview links for new or modified API documentation in this PR: | ||
|
|
||
| {api_links} | ||
|
|
||
| </details>""" | ||
|
|
||
| return comment_body | ||
|
|
||
|
|
||
| def cli(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Generate documentation comment for PR with API changes" | ||
| ) | ||
| parser.add_argument( | ||
| "doc_diff_path", help="Path to the documentation diff file", type=str | ||
| ) | ||
| parser.add_argument("pr_id", help="Pull request ID", type=int) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main(): | ||
| args = cli() | ||
|
|
||
| with open(args.doc_diff_path, 'r') as f: | ||
| doc_diff_content = f.read() | ||
|
|
||
| comment = generate_comment_body(doc_diff_content, args.pr_id) | ||
| print(comment) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
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.