From a3b5e02bf365efebbc1230f60d691ae778227ca3 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Fri, 13 Sep 2024 15:26:27 +0300 Subject: [PATCH] fix deploy job finish detection --- .github/workflows/trigger-e2e-environment.yml | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/trigger-e2e-environment.yml b/.github/workflows/trigger-e2e-environment.yml index 587857bf5e9..e31dd629698 100644 --- a/.github/workflows/trigger-e2e-environment.yml +++ b/.github/workflows/trigger-e2e-environment.yml @@ -101,8 +101,12 @@ jobs: const owner = 'opencrvs'; const repo = 'e2e'; const runId = ${{ steps.dispatch_e2e.outputs.runId }}; + const prNumber = ${{ github.event.pull_request.number }}; + const deployMessage = `Your environment is deployed to https://${{ env.BRANCH_NAME }}.opencrvs.dev.`; + await new Promise(resolve => setTimeout(resolve, 10000)); let deployJobCompleted = false; + // Check if deploy job has completed while (!deployJobCompleted) { const jobs = await github.rest.actions.listJobsForWorkflowRun({ owner, @@ -110,11 +114,11 @@ jobs: run_id: runId }); - const deployJob = jobs.data.jobs.find(job => job.name === 'deploy'); + const deployJob = jobs.data.jobs.find(job => job.name === 'deploy / deploy'); if (deployJob && deployJob.status === 'completed') { deployJobCompleted = true; - if(deployJob.conclusion !== 'success') { + if (deployJob.conclusion !== 'success') { throw new Error('Deploy job failed'); } @@ -126,14 +130,27 @@ jobs: } } - // Add PR comment once the deploy is completed - await github.rest.issues.createComment({ + // Check if the comment already exists + const comments = await github.rest.issues.listComments({ owner: 'opencrvs', repo: 'opencrvs-core', - issue_number: ${{ github.event.pull_request.number }}, - body: `Your environment is deployed to https://${{ env.BRANCH_NAME }}.opencrvs.dev.` + issue_number: prNumber }); + const existingComment = comments.data.find(comment => comment.body.includes(deployMessage)); + if (!existingComment) { + // Add PR comment if it doesn't exist + await github.rest.issues.createComment({ + owner: 'opencrvs', + repo: 'opencrvs-core', + issue_number: prNumber, + body: deployMessage + }); + console.log('PR comment added'); + } else { + console.log('PR comment already exists, skipping...'); + } + - name: Wait for E2E Workflow Completion uses: actions/github-script@v7 with: @@ -154,7 +171,6 @@ jobs: status = run.data.status; console.log(`Current status: ${status}`); - // Wait for 30 seconds before polling again if (status === 'in_progress') { await new Promise(resolve => setTimeout(resolve, 10000)); }