-
Notifications
You must be signed in to change notification settings - Fork 4
111 lines (101 loc) · 3.96 KB
/
deploy-dashboard.yml
File metadata and controls
111 lines (101 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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: Prepare SPA fallback
run: |
# Copy SPA to root so Cloudflare Pages auto-detection serves it
# for all unmatched paths (e.g., /osa/eeglab -> index.html)
cp dashboard/osa/index.html dashboard/index.html
- 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), custom domain: status.osc.earth
# - develop branch -> develop.osa-dash.pages.dev (preview)
# - PR branches -> {branch}.osa-dash.pages.dev (preview)
# Dashboard is served at /osa/ path (e.g., status.osc.earth/osa/)
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
});
}