Build PR & Deploy #17
This file contains 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: Build PR | |
on: | |
workflow_dispatch: | |
inputs: | |
pr_number: | |
description: 'Pull Request Number' | |
required: true | |
type: string | |
concurrency: | |
group: pr-${{ github.event.inputs.pr_number }} | |
cancel-in-progress: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
url: ${{ steps.cloudflare.outputs.url }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
ref: refs/pull/${{ github.event.inputs.pr_number }}/merge | |
- name: Setup Python 3 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install wheel | |
run: pip install wheel | |
- name: Install mkdocs material insiders | |
run: pip install git+https://${{ secrets.GH_TOKEN }}@github.com/chazlarson/automaticSpoon.git | |
- name: Install requirements.txt | |
run: pip install -r requirements.txt | |
- name: Build mkdocs | |
run: mkdocs build | |
- name: Publish to Cloudflare Pages | |
id: cloudflare | |
uses: cloudflare/pages-action@v1.5.0 | |
with: | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
accountId: 86b9f680e99b6d172395cc7309a9d8a8 | |
projectName: docs | |
directory: site | |
gitHubToken: ${{ secrets.GH_TOKEN }} | |
branch: pr-${{ github.event.inputs.pr_number }} | |
comment: | |
needs: build | |
runs-on: ubuntu-latest | |
if: always() | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Get PR last commit SHA | |
run: | | |
PR_DATA=$(curl -H "Authorization: token ${{ secrets.GH_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr_number }}") | |
LAST_COMMIT_SHA=$(echo "$PR_DATA" | jq -r .head.sha) | |
echo "LAST_COMMIT_SHA=$LAST_COMMIT_SHA" >> $GITHUB_ENV | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
- name: Comment PR | |
run: | | |
PREVIEW_URL=${{ needs.build.outputs.url }} | |
BRANCH_PREVIEW_URL="https://pr-${{ github.event.inputs.pr_number }}.docs-acq.pages.dev" | |
BUILD_STATUS=${{ needs.build.result }} | |
if [ "$BUILD_STATUS" == "success" ]; then | |
STATUS_EMOJI="✅" | |
STATUS_MESSAGE="Deploy successful!" | |
else | |
STATUS_EMOJI="❌" | |
STATUS_MESSAGE="Build failed!" | |
fi | |
COMMENT_BODY="Deploying with ⚡ Cloudflare Pages<br><table><tr><td><strong>Latest commit:</strong></td><td><code>$LAST_COMMIT_SHA</code></td></tr><tr><td><strong>Status:</strong></td><td> $STATUS_EMOJI $STATUS_MESSAGE</td></tr><tr><td><strong>Preview URL:</strong></td><td><a href='$PREVIEW_URL'>$PREVIEW_URL</a></td></tr><tr><td><strong>Branch Preview URL:</strong></td><td><a href='$BRANCH_PREVIEW_URL'>$BRANCH_PREVIEW_URL</a></td></tr></table>" | |
ESCAPED_BODY=$(echo "$COMMENT_BODY" | jq -aRs .) | |
COMMENTS_URL="https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.inputs.pr_number }}/comments" | |
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github+json" \ | |
-X POST \ | |
-d "{\"body\": $ESCAPED_BODY }" \ | |
$COMMENTS_URL | |
webhook: | |
name: 'webhook' | |
runs-on: self-hosted | |
needs: build | |
if: always() | |
steps: | |
- uses: technote-space/workflow-conclusion-action@v3 | |
- name: Send Discord Notification | |
uses: sarisia/actions-status-discord@v1 | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
description: "URL: ${{ needs.build.outputs.url }}" | |
status: ${{ env.WORKFLOW_CONCLUSION }} |