Repository navigation
Add a pipeline for Docs PR Preview #1413
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
Merged
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
1e67208
use script to sparse clone the changed project
alexxu-amd a1c794e
change how PR number is extracted
alexxu-amd 01df27a
add steps to build docs and render on github pages
alexxu-amd a5e4d82
remove condition for triggering the pipeline
alexxu-amd 8126382
fix indentation
alexxu-amd c7660b5
change job name to build
alexxu-amd f3869ae
update path
alexxu-amd abff301
install doxygen
alexxu-amd 6343b9d
add permission to pass OIDC
alexxu-amd bd5d0ea
add more comments
alexxu-amd 9a61e6c
fix typo
alexxu-amd 154762d
add suggested newline
alexxu-amd 071c430
add a test branch
alexxu-amd 98c5e96
change trigger condition to let workflow be run by draft PR
alexxu-amd e9ea94f
Merge branch 'develop' into users/alexxu12/docs-pr-preview
alexxu-amd 6be6ad2
remove path requirement as pull_request_target cannot check path
alexxu-amd fd772d9
correct event_type
alexxu-amd 9905886
switch to feature branch
alexxu-amd d1cb074
update workflow trigger condition & action version
alexxu-amd 0915c60
change workflow behavior to target one project when multiple projects…
alexxu-amd 29c7738
seperate extract project step from detect
alexxu-amd 21b9b58
add comments for special case
alexxu-amd 101f5e9
switch deploy tool from github-pages to netlify
alexxu-amd 24e298d
workflow trigger by comment
alexxu-amd 4e64aad
modify docs to test the workflow
alexxu-amd 8f2dd1d
revert trigger change for testing
alexxu-amd 9c30730
fix whitespace
alexxu-amd 09f3dbe
Remove whitespace
alexxu-amd d181f24
remove whitespace
alexxu-amd e22d019
revert trigger changes
alexxu-amd 2b55b51
change workflow trigger condition
alexxu-amd e000154
revert test changes for production
alexxu-amd 471d4f4
Refine comments
alexxu-amd c8885f5
remove trailing whitespace
alexxu-amd fb97381
add missing brackets
alexxu-amd 171b1b5
remove collaborator from the trigger condition
alexxu-amd b9e8f03
makes preview private
alexxu-amd 721a1a6
update preview url
alexxu-amd 9694806
change project_slug to alias in url
alexxu-amd c4a5508
add a pipeline for cleaning the preview once PR is closed
alexxu-amd 1dfbc22
Merge branch 'develop' into users/alexxu12/docs-pr-preview
alexxu-amd cf70fa4
Update .github/workflows/docs-pr-preview-cleanup.yml
alexxu-amd 4927dbb
add comments for grep and --jq cmds
alexxu-amd 3bc2a0e
converting curl flag from short form to long form for enhanced readab…
alexxu-amd eda181e
remove trailing space
alexxu-amd 797595b
add a note to clarify only the first project will be built for preview
alexxu-amd 614e3d1
add more comments about --jq
alexxu-amd 5815e67
add more comments regarding the parsing code
alexxu-amd 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,57 @@ | ||
| # Clean up documentation preview versions from Read the Docs | ||
| # --------------------------------------------------------- | ||
| # This workflow triggers when a PR is closed (merged or abandoned). | ||
| # It checks if a docs preview was created by parsing PR comments posted | ||
| # by the bot, then deactivates the corresponding version on Read the Docs. | ||
|
|
||
| name: Docs Preview Cleanup | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| cleanup: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Generate a token | ||
| id: generate-token | ||
| uses: actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b # v2.1.1 | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
| owner: ${{ github.repository_owner }} | ||
|
|
||
| - name: Get project slug from preview comment | ||
| id: rtd | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| run: | | ||
| comment=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \ | ||
| --jq '[.[] | select(.user.login == "assistant-librarian[bot]" and (.body | contains("rocm.docs.amd.com/projects/")))] | last | .body') | ||
|
|
||
| if [ -z "$comment" ] || [ "$comment" = "null" ]; then | ||
| echo "No preview comment found, skipping cleanup." | ||
| exit 0 | ||
| fi | ||
|
|
||
| project_alias=$(echo "$comment" | grep -oP 'projects/\K[^/]+') | ||
|
alexxu-amd marked this conversation as resolved.
Resolved
alexxu-amd marked this conversation as resolved.
Resolved
|
||
| echo "project_slug=advanced-micro-devices-${project_alias}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Deactivate RTD preview version | ||
| if: steps.rtd.outputs.project_slug | ||
| env: | ||
| RTD_TOKEN: ${{ secrets.RTD_TOKEN }} | ||
| run: | | ||
| branch_name="${{ github.head_ref }}" | ||
| version_slug="${branch_name//\//-}" | ||
|
alexxu-amd marked this conversation as resolved.
Resolved
|
||
|
|
||
| response=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH \ | ||
| -H "Authorization: Token $RTD_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"active": false}' \ | ||
| "https://app.readthedocs.com/api/v3/projects/${{ steps.rtd.outputs.project_slug }}/versions/${version_slug}/") | ||
|
dsclear-amd marked this conversation as resolved.
Resolved
|
||
| echo "RTD PATCH responded with HTTP $response" | ||
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,145 @@ | ||
| # Create a documentation preview in the pull request | ||
| # -------------------------------------------------- | ||
| # This GitHub Actions workflow triggers by commenting '/docs-preview' on a PR. | ||
| # It creates a new Read the Docs version for the PR branch and triggers a build. | ||
| # | ||
| # Key Steps: | ||
| # 1. Use the script (.github/scripts/pr_detect_changed_subtrees.py) to detect changed project | ||
| # 2. Get the PR branch name and derive the RTD version slug | ||
| # 3. Activate the branch as a new version on Read the Docs (key difference from update-docs.yml) | ||
| # 4. Trigger a build for that version | ||
| # 5. Comment the preview URL back on the PR | ||
| # | ||
| # Note: if multiple projects are changed in one PR, only the first detected project is previewed. | ||
|
|
||
| name: Docs Preview | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created, edited] | ||
|
dsclear-amd marked this conversation as resolved.
Resolved
|
||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| # Only run when '/docs-preview' is commented on a PR by a member or owner | ||
| if: >- | ||
| github.event.issue.pull_request != null && | ||
| contains(github.event.comment.body, '/docs-preview') && | ||
| (github.event.comment.author_association == 'MEMBER' || | ||
| github.event.comment.author_association == 'OWNER') | ||
| steps: | ||
| - name: Generate a token | ||
| id: generate-token | ||
| uses: actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b # v2.1.1 | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
|
geomin12 marked this conversation as resolved.
Resolved
|
||
| owner: ${{ github.repository_owner }} | ||
|
|
||
| - name: Checkout config files only | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
| with: | ||
| sparse-checkout: .github | ||
| sparse-checkout-cone-mode: true | ||
| token: ${{ steps.generate-token.outputs.token }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: Install python dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install pydantic requests | ||
|
|
||
| - name: Set up Git user | ||
| run: | | ||
| git config user.name "assistant-librarian[bot]" | ||
| git config user.email "assistant-librarian[bot]@users.noreply.github.com" | ||
|
dsclear-amd marked this conversation as resolved.
Resolved
|
||
|
|
||
| - name: Detect changed subtrees from PR | ||
| id: detect | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| run: | | ||
| python .github/scripts/pr_detect_changed_subtrees.py \ | ||
| --repo "${{ github.repository }}" \ | ||
| --pr "${{ github.event.issue.number }}" \ | ||
| --config ".github/repos-config.json" \ | ||
| --require-auto-push | ||
|
|
||
| - name: Extract first project | ||
| id: extract | ||
| run: | | ||
| project=$(echo "${{ steps.detect.outputs.subtrees }}" | head -n1) | ||
| echo "project=$project" >> $GITHUB_OUTPUT | ||
| echo "project_name=$(echo "$project" | cut -d'/' -f2)" >> $GITHUB_OUTPUT | ||
|
alexxu-amd marked this conversation as resolved.
Resolved
|
||
|
|
||
| - name: Get PR branch | ||
| if: steps.extract.outputs.project | ||
| id: pr | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| run: | | ||
| PR_DATA=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}) | ||
| echo "branch=$(echo $PR_DATA | jq -r .head.ref)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Derive RTD slugs and verify project exists | ||
| if: steps.extract.outputs.project | ||
| id: rtd | ||
| env: | ||
| RTD_TOKEN: ${{ secrets.RTD_TOKEN }} | ||
| run: | | ||
| branch_name="${{ steps.pr.outputs.branch }}" | ||
| version_slug="${branch_name//\//-}" | ||
| project_slug="advanced-micro-devices-${{ steps.extract.outputs.project_name }}" | ||
|
|
||
| echo "version_slug=$version_slug" >> $GITHUB_OUTPUT | ||
| echo "project_slug=$project_slug" >> $GITHUB_OUTPUT | ||
|
|
||
| project_list=$(curl \ | ||
| -H "Authorization: Token $RTD_TOKEN" \ | ||
| "https://app.readthedocs.com/api/v3/projects/?expand=advanced-micro-devices&limit=300" \ | ||
|
dsclear-amd marked this conversation as resolved.
Resolved
|
||
| | jq -r '.results[].slug') | ||
|
alexxu-amd marked this conversation as resolved.
Resolved
|
||
|
|
||
| if echo "$project_list" | grep -Fxq "$project_slug"; then | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "${{ steps.extract.outputs.project_name }} does not exist on Read the Docs, skipping." | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
alexxu-amd marked this conversation as resolved.
Resolved
|
||
|
|
||
| - name: Activate PR branch as a new RTD version | ||
| if: steps.rtd.outputs.exists == 'true' | ||
| env: | ||
| RTD_TOKEN: ${{ secrets.RTD_TOKEN }} | ||
| run: | | ||
| curl -f -X PATCH \ | ||
| -H "Authorization: Token $RTD_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"active": true, "hidden": true, "privacy_level": "private"}' \ | ||
| "https://app.readthedocs.com/api/v3/projects/${{ steps.rtd.outputs.project_slug }}/versions/${{ steps.rtd.outputs.version_slug }}/" | ||
|
|
||
| - name: Trigger RTD build for PR branch | ||
| if: steps.rtd.outputs.exists == 'true' | ||
| env: | ||
| RTD_TOKEN: ${{ secrets.RTD_TOKEN }} | ||
| run: | | ||
| curl -f -s -X POST \ | ||
| -H "Authorization: Token $RTD_TOKEN" \ | ||
| "https://app.readthedocs.com/api/v3/projects/${{ steps.rtd.outputs.project_slug }}/versions/${{ steps.rtd.outputs.version_slug }}/builds/" | ||
|
|
||
| - name: Comment RTD preview URL on PR | ||
| if: steps.rtd.outputs.exists == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| run: | | ||
| preview_url="https://rocm.docs.amd.com/projects/${{ steps.extract.outputs.project_name }}/en/${{ steps.rtd.outputs.version_slug }}/" | ||
| gh pr comment ${{ github.event.issue.number }} \ | ||
| --repo ${{ github.repository }} \ | ||
| --body "Docs preview for **${{ steps.extract.outputs.project_name }}** is building on Read the Docs: $preview_url" | ||
|
alexxu-amd marked this conversation as resolved.
Resolved
|
||
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.