[510] Document listener configuration #175
Workflow file for this run
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: Preview Deployment | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| concurrency: | |
| group: preview-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| deploy-preview: | |
| name: Deploy preview (PR #${{ github.event.pull_request.number }}) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| deployments: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| cache-dependency-path: dashboard/package-lock.json | |
| - name: Install dependencies | |
| working-directory: dashboard | |
| run: npm ci | |
| - name: Build dashboard | |
| working-directory: dashboard | |
| env: | |
| VITE_EVENTS_API_URL: ${{ secrets.PREVIEW_EVENTS_API_URL }} | |
| VITE_STELLAR_NETWORK: TESTNET | |
| run: npm run build | |
| # Fork PRs cannot access org secrets (CLOUDFLARE_API_TOKEN), so skip deploy | |
| # for forks. Same-repo PRs still get Cloudflare preview deployments. | |
| - name: Deploy to Cloudflare Pages | |
| id: deploy | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| command: pages deploy dashboard/dist --project-name=notify-chain-dashboard --branch=pr-${{ github.event.pull_request.number }} | |
| - name: Post preview URL comment | |
| if: github.event.pull_request.head.repo.full_name == github.repository && steps.deploy.outcome == 'success' | |
| uses: actions/github-script@v7 | |
| env: | |
| DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| COMMIT_SHA: ${{ github.event.pull_request.head.sha }} | |
| with: | |
| script: | | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: Number(process.env.PR_NUMBER), | |
| }); | |
| const marker = '<!-- notify-chain-preview-bot -->'; | |
| const existing = comments.find(c => c.body.includes(marker)); | |
| const short = process.env.COMMIT_SHA.slice(0, 7); | |
| const body = [ | |
| marker, | |
| '## 🚀 Preview Deployment', | |
| '', | |
| `| | |`, | |
| `|---|---|`, | |
| `| **URL** | ${process.env.DEPLOYMENT_URL} |`, | |
| `| **Commit** | \`${short}\` |`, | |
| `| **Status** | ✅ Ready |`, | |
| '', | |
| '_This comment is updated automatically on every push to the PR._', | |
| ].join('\n'); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: Number(process.env.PR_NUMBER), | |
| body, | |
| }); | |
| } |