diff --git a/.github/scripts/trigger-regression.js b/.github/scripts/trigger-regression.js index 386900fbbf..1066f63e8f 100644 --- a/.github/scripts/trigger-regression.js +++ b/.github/scripts/trigger-regression.js @@ -4,17 +4,16 @@ // Access the environment input from environment variables const { ENVIRONMENT } = process.env; -// const inputs = { - // environment: ENVIRONMENT, - // branch: 'master', -// }; +const inputs = { + environment: ENVIRONMENT, +}; const triggerAndWait = async ({ github, context, core }) => { const owner = 'department-of-veterans-affairs'; // user of private repo const repo = 'notification-api-qa'; // private repo to contact - const workflow_id = 'build.yml'; // Replace with your workflow file name or ID - const ref = 'master'; // Usually main or master. THIS IS THE REF of the REGRESSION repo! - // const jobName = 'Test in ${ENVIRONMENT}'; // Replace with the name of the job you want + const workflow_id = 'regression.yml'; // Replace with your workflow file name or ID + const ref = '1526-test-branch'; // Usually main or master. THIS IS THE REF of the REGRESSION repo! + const jobName = 'Test in ${ENVIRONMENT}'; // Replace with the name of the job you want // Create a timestamp for workflow run tracking const triggerTimestamp = new Date().toISOString(); @@ -24,7 +23,7 @@ const triggerAndWait = async ({ github, context, core }) => { repo, workflow_id, ref, - // inputs, + inputs, }); // Wait a moment for the workflow run to be initialized @@ -71,38 +70,38 @@ const triggerAndWait = async ({ github, context, core }) => { console.log(`Workflow run URL: ${workflow_url}`); // Fetch the job within the workflow run - // const jobs = await github.rest.actions.listJobsForWorkflowRun({ - // owner, - // repo, - // run_id, - // }); - - // const job = jobs.data.jobs.find(j => j.name === jobName); - // if (!job) { - // console.log(`Job '${jobName}' not found in workflow run.`); - // return; - // } - - // let job_id = job.id; - - // // Fetch and handle the job logs - // github.rest.actions.downloadJobLogsForWorkflowRun({ - // owner, - // repo, - // job_id, - // }).then(response => { - // console.log(`Job logs: ${response.data}`); - // }).catch(error => { - // console.log('Error fetching job logs:', error); - // }); - - // // Set the output for the job summary - // const resultText = conclusion === 'success' ? 'passed' : 'failed'; - // core.setOutput('regression_result', `QA Regression result is ${resultText}; link to this run is ${workflow_url}`); - - // // Append to GITHUB_STEP_SUMMARY - // const summaryContent = `### Workflow Result\nResult: ${resultText}\n[Link to Workflow Run](${workflow_url})`; - // require('fs').appendFileSync(process.env.GITHUB_STEP_SUMMARY, summaryContent); + const jobs = await github.rest.actions.listJobsForWorkflowRun({ + owner, + repo, + run_id, + }); + + const job = jobs.data.jobs.find(j => j.name === jobName); + if (!job) { + console.log(`Job '${jobName}' not found in workflow run.`); + return; + } + + let job_id = job.id; + + // Fetch and handle the job logs + github.rest.actions.downloadJobLogsForWorkflowRun({ + owner, + repo, + job_id, + }).then(response => { + console.log(`Job logs: ${response.data}`); + }).catch(error => { + console.log('Error fetching job logs:', error); + }); + + // Set the output for the job summary + const resultText = conclusion === 'success' ? 'passed' : 'failed'; + core.setOutput('regression_result', `QA Regression result is ${resultText}; link to this run is ${workflow_url}`); + + // Append to GITHUB_STEP_SUMMARY + const summaryContent = `### Workflow Result\nResult: ${resultText}\n[Link to Workflow Run](${workflow_url})`; + require('fs').appendFileSync(process.env.GITHUB_STEP_SUMMARY, summaryContent); // Check if the workflow failed and set an appropriate error message if (conclusion !== 'success') {