Skip to content

Commit

Permalink
Feat: PR Preview Workflow via GitHub Pages (p4lang#4848)
Browse files Browse the repository at this point in the history
* Feat : Add PR preview functionality

Signed-off-by: Adarsh <[email protected]>

* Fix: Double comment on Broken Build PR

Signed-off-by: Adarsh <[email protected]>

* Remove: Rocket reaction from comments

Signed-off-by: Adarsh <[email protected]>

---------

Signed-off-by: Adarsh <[email protected]>
  • Loading branch information
AdarshRawat1 authored Aug 5, 2024
1 parent fd23e56 commit ab33c0a
Showing 1 changed file with 163 additions and 52 deletions.
215 changes: 163 additions & 52 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<img src="https://github.com/user-attachments/assets/f94fada5-45ca-4271-9106-180728235ad2" alt="Rocket" width="25"/>'
CELEBRATION: '<img src="https://github.com/user-attachments/assets/86eb8470-c597-4f8b-a77d-a54036075271" alt="githubloading" width="25"/>'
FAILURE_ICON: '<img src="https://github.com/user-attachments/assets/af921ba9-953d-465e-b597-64ed0a2dc921" alt="failed" width="25"/>'
COMMENT_IDENTIFIER: '<!-- preview-comment -->'

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

0 comments on commit ab33c0a

Please sign in to comment.