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 1ca77db
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions .github/workflows/trigger-e2e-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -101,20 +104,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.`;
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 +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:
Expand All @@ -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));
}
Expand Down

0 comments on commit 1ca77db

Please sign in to comment.