Skip to content

Commit

Permalink
fix deploy job finish detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rikukissa committed Sep 13, 2024
1 parent 060df44 commit a3b5e02
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions .github/workflows/trigger-e2e-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,24 @@ 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,
repo,
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');
}
Expand All @@ -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:
Expand All @@ -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));
}
Expand Down

0 comments on commit a3b5e02

Please sign in to comment.