Skip to content
Merged
Show file tree
Hide file tree
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
104 changes: 104 additions & 0 deletions .github/workflows/deploy-dashboard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Deploy Dashboard to Cloudflare Pages

on:
push:
branches:
- main
- develop
paths:
- 'dashboard/**'
- '.github/workflows/deploy-dashboard.yml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'dashboard/**'
- '.github/workflows/deploy-dashboard.yml'
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get branch name
id: branch
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BRANCH_NAME="${{ github.head_ref }}"
else
BRANCH_NAME="${{ github.ref_name }}"
fi
# Sanitize branch name for URL (replace / with -, lowercase)
SANITIZED=$(echo "$BRANCH_NAME" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
# Cloudflare Pages truncates branch names to ~28 chars for preview URLs
TRUNCATED=$(echo "$SANITIZED" | cut -c1-28)
echo "name=$TRUNCATED" >> $GITHUB_OUTPUT
echo "original=$BRANCH_NAME" >> $GITHUB_OUTPUT

- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# Deploy with branch name so Cloudflare Pages routes correctly:
# - main branch -> osa-dash.pages.dev (production)
# - develop branch -> develop.osa-dash.pages.dev (preview)
# - PR branches -> {branch}.osa-dash.pages.dev (preview)
command: pages deploy dashboard --project-name=osa-dash --branch=${{ steps.branch.outputs.name }}

- name: Comment on PR with preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const branch = '${{ steps.branch.outputs.name }}';
const previewUrl = `https://${branch}.osa-dash.pages.dev`;

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

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('<!-- cloudflare-dashboard-preview -->')
);

const sha = '${{ github.sha }}'.substring(0, 7);
const body = [
'<!-- cloudflare-dashboard-preview -->',
'## Dashboard Preview',
'',
'| Name | Link |',
'|------|------|',
`| **Preview URL** | ${previewUrl} |`,
'| **Branch** | \`${{ steps.branch.outputs.original }}\` |',
`| **Commit** | \`${sha}\` |`,
'',
'This preview will be updated automatically when you push new commits.'
].join('\n');

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
1 change: 1 addition & 0 deletions dashboard/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
Loading