From c7e406b1faf54b8e756f6fdc6ffe0bf5d708d815 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 7 Mar 2025 21:20:28 +0000 Subject: [PATCH] ci: handle failed deployments too --- .github/workflows/cf-sync.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cf-sync.yml b/.github/workflows/cf-sync.yml index 30c72bc9..252198f5 100644 --- a/.github/workflows/cf-sync.yml +++ b/.github/workflows/cf-sync.yml @@ -41,6 +41,7 @@ jobs: const isDeployStarting = commentBody.includes('Build in progress'); const isDeployFinished = commentBody.includes('Deploy successful'); + const isDeployFailed = commentBody.includes('Build failed'); let status = ''; let deployUrl = ''; @@ -50,6 +51,8 @@ jobs: } else if (isDeployFinished) { status = 'finished'; deployUrl = commentBody.match(/Preview URL:[\S\s]+?/)[1]; + } else if (isDeployFailed) { + status = 'failed'; } else { status = 'unknown'; } @@ -62,7 +65,7 @@ jobs: - name: Create deployment id: deployment # Use outputs directly, not nested in result - if: steps.parse-comment.outputs.status == 'starting' || steps.parse-comment.outputs.status == 'finished' + if: steps.parse-comment.outputs.status == 'starting' || steps.parse-comment.outputs.status == 'finished' || steps.parse-comment.outputs.status == 'failed' uses: actions/github-script@v6 with: github-token: ${{ secrets.WORKFLOW_PAT || secrets.GITHUB_TOKEN }} @@ -148,3 +151,26 @@ jobs: }); console.log(`Updated deployment ${deploymentId} status to success with URL ${deployUrl}`); + + - name: Update deployment status (failed) + if: steps.parse-comment.outputs.status == 'failed' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.WORKFLOW_PAT || secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const prNumber = context.issue.number; + const deploymentId = parseInt('${{ steps.deployment.outputs.deploymentId }}'); + + console.log(`Updating deployment ${deploymentId} for PR #${prNumber} as failed`); + + // Mark the deployment as failed + await github.rest.repos.createDeploymentStatus({ + owner, + repo, + deployment_id: deploymentId, + state: 'failure', + description: 'Cloudflare Pages deployment failed' + }); + + console.log(`Updated deployment ${deploymentId} status to failure`); -- knotmirror 0.0.1