release: 0.8.4 #60
This file contains hidden or 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: 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 | |
| }); | |
| } |