From 374d403790c9d871a33355f003a8ee3f7ad2c1f1 Mon Sep 17 00:00:00 2001 From: taga3s Date: Mon, 4 Nov 2024 09:19:23 +0900 Subject: [PATCH] feat: add preview environment and display its url --- .github/workflows/build-and-deploy.yaml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy.yaml b/.github/workflows/build-and-deploy.yaml index 9af2f9a..c2c7afb 100644 --- a/.github/workflows/build-and-deploy.yaml +++ b/.github/workflows/build-and-deploy.yaml @@ -2,12 +2,11 @@ name: deploy on: push: - branches: - - main permissions: contents: read deployments: write + statuses: write jobs: deploy: @@ -33,8 +32,24 @@ jobs: run: pnpm build - name: Publish to Cloudflare Pages + id: cloudflare-pages-deploy uses: cloudflare/wrangler-action@v3 with: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: pages deploy ./dist --project-name=taga3s-dev-website + + - name: Add publish URL as commit status + uses: actions/github-script@v6 + with: + script: | + const sha = context.payload.pull_request?.head.sha ?? context.sha; + await github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + context: 'Cloudflare Pages', + description: 'Cloudflare Pages deployment', + state: 'success', + sha, + target_url: "${{ steps.cloudflare-pages-deploy.outputs.deployment-url }}", + });