Documentation Preview #93
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
| name: Documentation Preview | |
| on: | |
| workflow_run: | |
| workflows: ["Build Documentation"] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| pull-requests: write | |
| actions: read | |
| # Allow only one deployment at a time | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-24.04 | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4 | |
| - name: Download site state from deploy | |
| id: download-deploy | |
| uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6 | |
| with: | |
| workflow: docpreview.yml | |
| name: site-state | |
| path: ${{ runner.temp }}/existing_pages | |
| workflow_conclusion: success | |
| search_artifacts: true | |
| if_no_artifact_found: warn | |
| continue-on-error: false | |
| - name: Remove symlinks from downloaded artifacts | |
| run: | | |
| if [ -d "${{ runner.temp }}/existing_pages" ]; then | |
| find "${{ runner.temp }}/existing_pages" -type l -delete 2>/dev/null || true | |
| rm -rf _existing_pages | |
| mkdir -p _existing_pages | |
| cp -a "${{ runner.temp }}/existing_pages/." _existing_pages/ || true | |
| fi | |
| - name: Download build artifacts | |
| uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6 | |
| with: | |
| workflow: docbuild.yml | |
| run_id: ${{ github.event.workflow_run.id }} | |
| path: ${{ runner.temp }} | |
| - name: Move doc-preview from temp | |
| run: | | |
| if [ -d "doc-preview" ]; then | |
| rm -rf doc-preview | |
| fi | |
| if [ -d "${{ runner.temp }}/doc-preview" ]; then | |
| mv "${{ runner.temp }}/doc-preview" ./doc-preview | |
| else | |
| echo "Expected doc-preview directory not found in runner.temp" >&2 | |
| exit 1 | |
| fi | |
| - name: Cleanup site state | |
| id: download-site-state | |
| uses: ./.github/actions/cleanup-site | |
| with: | |
| site_dir: _existing_pages | |
| - name: Extract version and unzip docs | |
| working-directory: doc-preview | |
| run: | | |
| # Extract version/output directory from monitor file | |
| OUTDIR=$(awk 'NR==1 { if ($3 ~ /^(latest|PR-[0-9]+|[0-9]+\.[0-9a-zA-Z\.\-]+)$/) print $3 }' monitor_*.txt) | |
| echo "OUTDIR=$OUTDIR" >> "$GITHUB_ENV" | |
| echo "Output directory: $OUTDIR" | |
| # Unzip the documentation archive | |
| unzip legacy-ncs-zigbee*.zip -d "$OUTDIR" | |
| find "$OUTDIR" -type l -delete | |
| # Determine target path based on version | |
| if [[ "$OUTDIR" == PR-* ]]; then | |
| PR_NUM="${OUTDIR#PR-}" | |
| TARGET_PATH="pr-preview/pr-${PR_NUM}" | |
| elif [[ "$OUTDIR" == "latest" ]]; then | |
| TARGET_PATH="latest" | |
| else | |
| TARGET_PATH="${OUTDIR}" | |
| fi | |
| echo "TARGET_PATH=$TARGET_PATH" >> "$GITHUB_ENV" | |
| - name: Prepare deployment content | |
| uses: ./.github/actions/deploy-docs-preview | |
| with: | |
| docs_dir: doc-preview/${{ env.OUTDIR }} | |
| target_path: ${{ env.TARGET_PATH }} | |
| existing_pages_dir: _existing_pages | |
| output_dir: _site | |
| - name: Obtain PR number | |
| working-directory: doc-preview | |
| run: | | |
| if [ -f pr.txt ]; then | |
| PR=$(head -n 1 pr.txt | tr -cd '0-9') | |
| fi | |
| printf 'PR=%s\n' "$PR" >> "$GITHUB_ENV" | |
| echo "PR number: $PR" | |
| - name: Setup Pages | |
| uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5 | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@0252fc4ba7626f0298f0cf00902a25c6afc77fa8 # v3 | |
| with: | |
| path: '_site' | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@f33f41b675f0ab2dc5a6863c9a170fe83af3571e # v4 | |
| - name: Save site state artifact | |
| uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4 | |
| with: | |
| name: site-state | |
| path: _site | |
| retention-days: 30 # 1 month, recall Build Documentation workflow to re-generate preview | |
| overwrite: true | |
| - name: Find existing comment | |
| if: env.PR != '' | |
| uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3 | |
| id: fc | |
| with: | |
| issue-number: ${{ env.PR }} | |
| comment-author: 'github-actions[bot]' | |
| body-includes: Documentation Preview | |
| - name: Create or update PR comment | |
| if: env.PR != '' | |
| uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4 | |
| with: | |
| comment-id: ${{ steps.fc.outputs.comment-id }} | |
| issue-number: ${{ env.PR }} | |
| body-path: doc-preview/comment.txt | |
| edit-mode: replace |