From ab33c0ae2b7c0a916bc011122223aa84b368ff3a Mon Sep 17 00:00:00 2001 From: Adarsh Rawat Date: Tue, 6 Aug 2024 01:08:03 +0530 Subject: [PATCH] Feat: PR Preview Workflow via GitHub Pages (#4848) * Feat : Add PR preview functionality Signed-off-by: Adarsh * Fix: Double comment on Broken Build PR Signed-off-by: Adarsh * Remove: Rocket reaction from comments Signed-off-by: Adarsh --------- Signed-off-by: Adarsh --- .github/workflows/deploy-docs.yml | 215 ++++++++++++++++++++++-------- 1 file changed, 163 insertions(+), 52 deletions(-) diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 813418b5ff4..60517c10c70 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -3,62 +3,173 @@ permissions: actions: read contents: write pages: write + issues: write + pull-requests: write on: push: branches: - main + pull_request_target: + types: [opened, synchronize, reopened, ready_for_review, labeled] -env: - DOXYGEN_VERSION: 1.11.0 - DOXYGEN_AWESOME_VERSION: 2.3.3 - jobs: - build-and-deploy: - runs-on: ubuntu-latest - concurrency: ci-${{github. ref}} - steps: - - name : Checkout - uses: actions/checkout@v4 - - - name: Install Clang - run: | - sudo apt-get update - sudo apt-get install -y clang - - - name: Install Doxygen - shell: bash - run: | - wget https://github.com/doxygen/doxygen/releases/download/Release_${DOXYGEN_VERSION//./_}/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz - tar xzvf doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz - cd doxygen-${DOXYGEN_VERSION} - sudo make install - cd .. - rm -rf doxygen-${DOXYGEN_VERSION}* - - - name: Install graphviz - run: sudo apt-get install graphviz -y - - - name: Clone Doxygen Awesome CSS Themes - working-directory: ./docs/doxygen - run: | - git clone --depth 1 -b v${{ env.DOXYGEN_AWESOME_VERSION }} https://github.com/jothepro/doxygen-awesome-css awesome_css - - - name: Generate Doxygen Documentation - run: | - cd docs/doxygen - doxygen doxygen.cfg - shell: bash - - - name: Create .nojekyll - run: | - cd docs/doxygen/build - touch html/.nojekyll - shell: bash - - - name: Deploy to GitHub Pages - uses: JamesIves/github-pages-deploy-action@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: gh-pages - folder: docs/doxygen/build/html + build-and-deploy: + runs-on: ubuntu-latest + env: + DOXYGEN_VERSION: 1.11.0 + DOXYGEN_AWESOME_VERSION: 2.3.3 + PR_PATH: pr-preview/${{ github.event.number }} + DOMAIN: ${{ github.actor }}.github.io + DEPLOYMENT: 'Rocket' + CELEBRATION: 'githubloading' + FAILURE_ICON: 'failed' + COMMENT_IDENTIFIER: '' + + concurrency: ci-${{ github.ref }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Check PR Label + id: check-label + if: ${{ github.event_name == 'pull_request_target' }} + uses: actions/github-script@v6 + with: + script: | + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + const hasDocumentationLabel = labels.some(label => label.name === 'documentation'); + return hasDocumentationLabel; + + - name: Find Existing Comment + if: ${{ github.event_name == 'pull_request_target' && steps.check-label.outputs.result == 'true' }} + id: find-comment + uses: peter-evans/find-comment@v3 + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: ${{ env.COMMENT_IDENTIFIER }} + + - name: Post Initial Comment + if: ${{ github.event_name == 'pull_request_target' && steps.check-label.outputs.result == 'true' && steps.find-comment.outputs.comment-id == '' }} + id: post-initial-comment + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + **Deployment of preview started...** ${{ env.DEPLOYMENT }} + ${{ env.COMMENT_IDENTIFIER }} + + - name: Update Comment to In-Progress + if: ${{ github.event_name == 'pull_request_target' && steps.check-label.outputs.result == 'true' && steps.find-comment.outputs.comment-id != '' }} + id: update-in-progress-comment + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.find-comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + **Deployment in progress...** ${{ env.DEPLOYMENT }} + ${{ env.COMMENT_IDENTIFIER }} + edit-mode: replace + + - name: Track intial Comment + if: ${{ github.event_name == 'pull_request_target' && steps.check-label.outputs.result == 'true' }} + id: find-comment2 + uses: peter-evans/find-comment@v3 + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: ${{ env.COMMENT_IDENTIFIER }} + + - name: Install Clang + if: ${{ github.event_name == 'push' || steps.check-label.outputs.result == 'true' }} + run: | + sudo apt-get update + sudo apt-get install -y clang + + - name: Install Doxygen + if: ${{ github.event_name == 'push' || steps.check-label.outputs.result == 'true'}} + run: | + wget https://github.com/doxygen/doxygen/releases/download/Release_${DOXYGEN_VERSION//./_}/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz + tar xzvf doxygen-${{ env.DOXYGEN_VERSION }}.linux.bin.tar.gz + cd doxygen-${{ env.DOXYGEN_VERSION }} + sudo make install + cd .. + rm -rf doxygen-${{ env.DOXYGEN_VERSION }}* + + - name: Install Graphviz + if: ${{ github.event_name == 'push' || steps.check-label.outputs.result == 'true' }} + run: sudo apt-get install graphviz -y + + - name: Clone Doxygen Awesome CSS Themes + if: ${{ github.event_name == 'push' || steps.check-label.outputs.result == 'true'}} + working-directory: ./docs/doxygen + run: | + git clone --depth 1 -b v${{ env.DOXYGEN_AWESOME_VERSION }} https://github.com/jothepro/doxygen-awesome-css awesome_css + + - name: Generate Doxygen Documentation + if: ${{ github.event_name == 'push' || steps.check-label.outputs.result == 'true'}} + run: | + cd docs/doxygen + doxygen doxygen.cfg + + - name: Create .nojekyll + if: ${{ github.event_name == 'push' || steps.check-label.outputs.result == 'true'}} + run: | + cd docs/doxygen/build/html + touch .nojekyll + + - name: Deploy to GitHub Pages (Main Branch) + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + uses: JamesIves/github-pages-deploy-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: gh-pages + folder: docs/doxygen/build/html + clean: true + clean-exclude: | + pr-preview/ + + - name: Deploy to PR preview + if: ${{ github.event_name == 'pull_request_target' && steps.check-label.outputs.result == 'true' }} + uses: JamesIves/github-pages-deploy-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: gh-pages + folder: docs/doxygen/build/html + target-folder: ${{ env.PR_PATH }} + clean: false + + - name: Update Comment with Preview Link + if: ${{ github.event_name == 'pull_request_target' && steps.check-label.outputs.result == 'true' }} + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.find-comment2.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + | ${{ env.CELEBRATION }} **A preview of this PR is available at:** | [Preview Link](https://${{ env.DOMAIN }}/${{ github.event.repository.name }}/${{ env.PR_PATH }}/) | + | -- | -- | + | 📂 **View the source code here:** | [View Source Code](https://github.com/${{ github.repository }}/tree/gh-pages/pr-preview/${{ github.event.pull_request.number }}) | + | 🔧 **Commit used for deployment:** | [${{ github.event.pull_request.head.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}) | + + **Note:** Changes may take a few seconds to appear on GitHub Pages. Please refresh the page if you do not see the updates immediately. + ${{ env.COMMENT_IDENTIFIER }} + edit-mode: replace + + - name: Update Comment with Failure Message + if: ${{ github.event_name == 'pull_request_target' && steps.check-label.outputs.result == 'true' && failure() }} + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.find-comment2.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ${{ env.FAILURE_ICON }} **Deployment of this PR failed.** Please check the [Actions logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details. + ${{ env.COMMENT_IDENTIFIER }} + edit-mode: replace