Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 71 additions & 4 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
name: Build, Test, and Deploy to GitHub Pages
name: Build, Test, and Deploy

on:
push:
branches: [main]

pull_request:
branches: [main]
types: [opened, synchronize, reopened]

workflow_dispatch:
inputs:
preview:
description: 'Deploy as preview'
required: true
default: true
type: boolean

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
Expand All @@ -15,6 +27,10 @@ concurrency:
group: "pages"
cancel-in-progress: false

env:
# Determine if the deployment is a preview (for PRs or manual trigger with preview input) or if it is a 'production' deploy (push to main branch).
IS_PREVIEW: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.preview == 'true') }}

jobs:
# Build job
build:
Expand Down Expand Up @@ -52,12 +68,63 @@ jobs:

# Deployment job
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v4
with:
preview: ${{ env.IS_PREVIEW }}
Comment thread
heckerdj marked this conversation as resolved.

- name: Comment PR with preview link
if: ${{ env.IS_PREVIEW && github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `${{ steps.deployment.outputs.page_url }}`;

const commentBody = `## 🎨 Preview Build Ready!

✅ Tests passed successfully!

### 🌐 [Live Preview](${previewUrl})

The preview will be automatically updated with each new commit to this PR.

---
*Preview deployed from commit ${context.sha.substring(0, 7)}*`;

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Preview Build Ready')
);

if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
}
Loading