name: Publish Dashboard to Cloudflare Pages on: push: paths: - .github/workflows/publish-dashboard.yaml - packages/dashboard/** - package.json - pnpm-lock.yaml pull_request_target: types: [opened, synchronize, reopened] paths: - .github/workflows/publish-dashboard.yaml - packages/dashboard/** - package.json - pnpm-lock.yaml env: PUBLIC_APEX_DOMAIN: ${{ vars.PUBLIC_APEX_DOMAIN }} MAIN_BRANCH: main BRANCH_NAME: ${{ github.event.pull_request.head.ref || github.ref_name }} GITHUB_LINK: ${{ github.event_name == 'pull_request_target' && format('https://github.com/{0}/pull/{1}', github.repository, github.event.pull_request.number) || format('https://github.com/{0}/tree/{1}', github.repository, github.event.pull_request.head.ref || github.ref_name) }} COMMIT_URL: ${{ github.event_name == 'pull_request_target' && format('https://github.com/{0}/pull/{1}/commits/{2}', github.repository, github.event.pull_request.number, github.sha) || format('https://github.com/{0}/commit/{1}', github.repository, github.sha) }} jobs: publish: runs-on: ubuntu-latest permissions: contents: read deployments: write pull-requests: write name: Publish to Cloudflare Pages steps: - name: Checkout uses: actions/checkout@v4.1.1 with: ref: ${{ github.event.pull_request.head.sha || github.sha }} repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} persist-credentials: false - name: pnpm uses: pnpm/action-setup@v3.0.0 with: version: 10.12.4 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: 20.x cache: 'pnpm' - name: Prepare build run: | pnpm i cd packages/dashboard pnpm build - name: Expose git commit data uses: rlespinasse/git-commit-data-action@v1.5.0 - name: Publish to Cloudflare Pages uses: cloudflare/wrangler-action@v3 id: deployment with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} gitHubToken: ${{ secrets.GITHUB_TOKEN }} command: pages deploy ./packages/dashboard/build --project-name=pockethost --branch=${{ github.event_name == 'pull_request_target' && format('pr-{0}', github.event.pull_request.number) || github.ref_name }} - name: Comment preview URL on PR if: github.event_name == 'pull_request_target' uses: actions/github-script@v7 with: script: | await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `✅ HEAD: ${{ steps.deployment.outputs.deployment-alias-url }} ✅ Permalink: ${{ steps.deployment.outputs.deployment-url }}` }) - name: Discord feature branch notification if: github.event_name == 'pull_request_target' || (github.event_name == 'push' && github.ref_name != env.MAIN_BRANCH) env: DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} uses: Ilshidur/action-discord@master with: args: '**DASHBOARD PREVIEW** ${{ steps.deployment.outputs.pages-deployment-alias-url }} was generated by ${{ github.actor }} in [${{ env.GIT_COMMIT_SHORT_SHA }}](${{ env.COMMIT_URL }}) on [${{ github.repository}}@${{ env.BRANCH_NAME }}](${{ env.GITHUB_LINK }}) with memo `${{ env.GIT_COMMIT_MESSAGE_SUBJECT }}`' - name: Discord live branch notification if: github.event_name == 'push' && github.ref_name == env.MAIN_BRANCH env: DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} uses: Ilshidur/action-discord@master with: args: '**DASHBOARD LIVE** https://pockethost.io ([permalink](${{ steps.deployment.outputs.deployment-url }})) was updated by ${{ github.actor }} in [${{ env.GIT_COMMIT_SHORT_SHA }}](${{ env.COMMIT_URL }}) on [${{ github.repository}}@${{ env.BRANCH_NAME }}](${{ env.GITHUB_LINK }}): `${{ env.GIT_COMMIT_MESSAGE_SUBJECT }}`'