From 7813ce376f4ca19d03dc8f5a9257d408d8b0b009 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 7 Mar 2025 20:18:29 +0000 Subject: [PATCH] ci: use commit deployment url --- .github/workflows/cf-sync.yml | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cf-sync.yml b/.github/workflows/cf-sync.yml index e8df27e3..0c3bd260 100644 --- a/.github/workflows/cf-sync.yml +++ b/.github/workflows/cf-sync.yml @@ -21,7 +21,7 @@ jobs: repo, pull_number: number }); - return { + return { branch: pr.data.head.ref, sha: pr.data.head.sha }; @@ -32,22 +32,22 @@ jobs: with: script: | const commentBody = context.payload.comment.body; - + const isDeployStarting = commentBody.includes('Build in progress'); const isDeployFinished = commentBody.includes('Deploy successful'); - + let status = ''; let deployUrl = ''; - + if (isDeployStarting) { status = 'starting'; } else if (isDeployFinished) { status = 'finished'; - deployUrl = commentBody.match(/Branch Preview URL:[\S\s]+/)[1]; + deployUrl = commentBody.match(/Preview URL:[\S\s]+/)[1]; } else { status = 'unknown'; } - + console.log(`Detected deployment status: ${status}`); // Set outputs directly core.setOutput('status', status); @@ -62,16 +62,16 @@ jobs: script: | const { owner, repo } = context.repo; const prNumber = context.issue.number; - + // Parse the JSON result string from get-pr step const prData = JSON.parse('${{ steps.get-pr.outputs.result }}'); const sha = prData.sha; const branch = prData.branch; - + const status = '${{ steps.parse-comment.outputs.status }}'; - + console.log(`Creating/updating deployment for PR #${prNumber}, branch ${branch}, SHA ${sha}, status: ${status}`); - + // Get existing deployments for this environment and PR const existingDeployments = await github.rest.repos.listDeployments({ owner, @@ -79,13 +79,13 @@ jobs: environment: 'cloudflare-preview', ref: sha }); - + let deploymentId; - + // If there's no existing deployment or we're starting a new one if (existingDeployments.data.length === 0 || status === 'starting') { console.log(`Creating new deployment for PR #${prNumber}, branch ${branch}, SHA ${sha}`); - + const deployment = await github.rest.repos.createDeployment({ owner, repo, @@ -95,10 +95,10 @@ jobs: auto_merge: false, required_contexts: [] }); - + deploymentId = deployment.data.id; console.log(`Created new deployment with ID: ${deploymentId}`); - + // If we're starting, set status to in_progress if (status === 'starting') { await github.rest.repos.createDeploymentStatus({ @@ -113,7 +113,7 @@ jobs: deploymentId = existingDeployments.data[0].id; console.log(`Using existing deployment ID: ${deploymentId}`); } - + // Set deployment ID as output core.setOutput('deploymentId', deploymentId.toString()); @@ -126,9 +126,9 @@ jobs: const prNumber = context.issue.number; const deployUrl = '${{ steps.parse-comment.outputs.deployUrl }}'; const deploymentId = parseInt('${{ steps.deployment.outputs.deploymentId }}'); - + console.log(`Updating deployment ${deploymentId} for PR #${prNumber} with URL ${deployUrl}`); - + await github.rest.repos.createDeploymentStatus({ owner, repo, @@ -138,5 +138,5 @@ jobs: log_url: deployUrl, description: 'Cloudflare Pages deployment successful' }); - + console.log(`Updated deployment ${deploymentId} status to success with URL ${deployUrl}`); -- knotmirror 0.0.1