diff --git a/.github/workflows/cf-sync.yml b/.github/workflows/cf-sync.yml index aefd01d4..e8df27e3 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 }; @@ -30,16 +30,15 @@ jobs: id: parse-comment uses: actions/github-script@v6 with: - result-encoding: json 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) { @@ -48,26 +47,31 @@ jobs: } else { status = 'unknown'; } - + console.log(`Detected deployment status: ${status}`); - return { status, deployUrl }; - - # log the result of parse-comment - - name: Log parse-comment result - run: echo "${{ toJSON(steps.parse-comment.outputs) }}" + // Set outputs directly + core.setOutput('status', status); + core.setOutput('deployUrl', deployUrl || ''); - name: Create deployment id: deployment - if: steps.parse-comment.outputs.result.status == 'starting' || steps.parse-comment.outputs.result.status == 'finished' + # Use outputs directly, not nested in result + if: steps.parse-comment.outputs.status == 'starting' || steps.parse-comment.outputs.status == 'finished' uses: actions/github-script@v6 with: script: | const { owner, repo } = context.repo; const prNumber = context.issue.number; - const sha = steps.get-pr.outputs.result.sha; - const branch = steps.get-pr.outputs.result.branch; - const status = steps.parse-comment.outputs.result.status; - + + // 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, @@ -75,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, @@ -91,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({ @@ -109,21 +113,22 @@ jobs: deploymentId = existingDeployments.data[0].id; console.log(`Using existing deployment ID: ${deploymentId}`); } - - return { id: deploymentId }; + + // Set deployment ID as output + core.setOutput('deploymentId', deploymentId.toString()); - name: Update deployment status (finished) - if: steps.parse-comment.outputs.result.status == 'finished' + if: steps.parse-comment.outputs.status == 'finished' uses: actions/github-script@v6 with: script: | const { owner, repo } = context.repo; const prNumber = context.issue.number; - const deployUrl = steps.parse-comment.outputs.result.deployUrl; - const deploymentId = steps.deployment.outputs.result.id; - + 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, @@ -133,5 +138,5 @@ jobs: log_url: deployUrl, description: 'Cloudflare Pages deployment successful' }); - + console.log(`Updated deployment ${deploymentId} status to success with URL ${deployUrl}`);