Skip to content

Build PR & Deploy

Build PR & Deploy #2

Workflow file for this run

name: Build PR
on:
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number'
required: true
type: string
concurrency:
group: ${{ github.ref }}
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: Comment PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.inputs.pr_number }}
COMMIT_SHA=$(git rev-parse HEAD)
BUILD_STATUS=${{ needs.build.result }}
PREVIEW_URL=${{ needs.build.outputs.url }}
BRANCH_PREVIEW_URL="https://pr-$PR_NUMBER.docs-acq.pages.dev"
if [ "$BUILD_STATUS" == "success" ]; then
STATUS_MESSAGE="✅ Deploy successful!"
else
STATUS_MESSAGE="❌ Build failed!"
fi
COMMENT_BODY="Latest commit: $COMMIT_SHA\nStatus: $STATUS_MESSAGE\nPreview URL: $PREVIEW_URL\nBranch Preview URL: $BRANCH_PREVIEW_URL"
COMMENTS_URL="https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/comments"
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-X POST \
-d "{\"body\": \"$COMMENT_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 }}