Skip to content

Commit

Permalink
back to a should-be working state
Browse files Browse the repository at this point in the history
  • Loading branch information
ldraney committed Jan 11, 2024
1 parent dfe031c commit fb26ba2
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions .github/scripts/trigger-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit fb26ba2

Please sign in to comment.