diff --git a/.github/workflows/trigger-e2e-environment.yml b/.github/workflows/trigger-e2e-environment.yml index 587857bf5e9..a855ae407c8 100644 --- a/.github/workflows/trigger-e2e-environment.yml +++ b/.github/workflows/trigger-e2e-environment.yml @@ -76,6 +76,9 @@ jobs: } }); + console.log(result); + await new Promise(resolve => setTimeout(resolve, 10000)); + const runs = await github.rest.actions.listWorkflowRunsForRepo({ owner: 'opencrvs', repo: 'e2e', @@ -101,8 +104,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.`; + let deployJobCompleted = false; + // Check if deploy job has completed while (!deployJobCompleted) { const jobs = await github.rest.actions.listJobsForWorkflowRun({ owner, @@ -110,11 +117,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 +133,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 +174,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)); }