Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable triggering azure pipelines #1274

Draft
wants to merge 6 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions server/migrations/20241121003538-addAutomationServiceColumn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('TestPlanRun', 'automationService', {
type: Sequelize.STRING,
allowNull: true,
defaultValue: null
});
},

async down(queryInterface) {
await queryInterface.removeColumn('TestPlanRun', 'automationService');
}
};
10 changes: 10 additions & 0 deletions server/models/TestPlanRun.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { AUTOMATION_SERVICE } = require('../util/enums');

const MODEL_NAME = 'TestPlanRun';

module.exports = function (sequelize, DataTypes) {
Expand All @@ -18,6 +20,11 @@ module.exports = function (sequelize, DataTypes) {
allowNull: false,
defaultValue: false
},
automationService: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null
},
isPrimary: {
type: DataTypes.BOOLEAN,
allowNull: true,
Expand All @@ -30,6 +37,9 @@ module.exports = function (sequelize, DataTypes) {
}
);

Model.GITHUB_ACTIONS = AUTOMATION_SERVICE.GITHUB_ACTIONS;
Model.AZURE_PIPELINES = AUTOMATION_SERVICE.AZURE_PIPELINES;

Model.TEST_RESULT_ASSOCIATION = { as: 'testResults' };

Model.TEST_PLAN_REPORT_ASSOCIATION = { foreignKey: 'testPlanReportId' };
Expand Down
61 changes: 50 additions & 11 deletions server/models/services/CollectionJobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const {
USER_ATTRIBUTES,
COLLECTION_JOB_TEST_STATUS_ATTRIBUTES
} = require('./helpers');
const { COLLECTION_JOB_STATUS } = require('../../util/enums');
const {
COLLECTION_JOB_STATUS,
AUTOMATION_SERVICE
} = require('../../util/enums');
const { Op } = require('sequelize');
const {
createTestPlanRun,
Expand All @@ -24,7 +27,10 @@ const {
default: createGithubWorkflow,
isEnabled: isGithubWorkflowEnabled
} = require('../../services/GithubWorkflowService');

const {
default: triggerAzurePipeline,
isEnabled: isAzurePipelinesEnabled
} = require('../../services/AzurePipelinesService');
const {
startCollectionJobSimulation
} = require('../../tests/util/mock-automation-scheduler-server');
Expand Down Expand Up @@ -125,6 +131,7 @@ const nestedTestPlanRunAssociation = (

/**
* @param {string[]} testPlanVersionAttributes - TestPlanVersion attributes to be returned in the result
* @param {string[]} testPlanAttributes - TestPlan attributes to be returned in the result
* @returns {{association: string, attributes: string[]}}
*/
const testPlanVersionAssociation = (
Expand All @@ -137,7 +144,7 @@ const testPlanVersionAssociation = (
});

/**
* @param {string[]} testPlanVersionAttributes - TestPlanVersion attributes to be returned in the result
* @param {string[]} testPlanAttributes - TestPlan attributes to be returned in the result
* @returns {{association: string, attributes: string[]}}
*/
const testPlanAssociation = testPlanAttributes => ({
Expand All @@ -146,7 +153,7 @@ const testPlanAssociation = testPlanAttributes => ({
});

/**
* @param browserAttributes - Browser attributes to be returned in the result
* @param {string[]} browserAttributes - Browser attributes to be returned in the result
* @returns {{association: string, attributes: string[]}}
*/
const browserAssociation = browserAttributes => ({
Expand All @@ -155,7 +162,7 @@ const browserAssociation = browserAttributes => ({
});

/**
* @param atAttributes - At attributes to be returned in the result
* @param {string[]} atAttributes - At attributes to be returned in the result
* @returns {{association: string, attributes: string[]}}
*/
const atAssociation = atAttributes => ({
Expand Down Expand Up @@ -381,18 +388,41 @@ const getCollectionJobs = async ({
* @param {object} job - CollectionJob to trigger workflow for.
* @param {number[]} testIds - Array of testIds
* @param {object} atVersion - AtVersion to use for the workflow
* @param {string} workflowService - Use GitHub Actions or Azure Pipelines
* @param {object} options
* @param {*} options.transaction - Sequelize transaction
* @returns Promise<CollectionJob>
*/
const triggerWorkflow = async (job, testIds, atVersion, { transaction }) => {
const triggerWorkflow = async (
job,
testIds,
atVersion,
workflowService,
{ transaction }
) => {
const { testPlanVersion } = job.testPlanRun.testPlanReport;
const { gitSha, directory } = testPlanVersion;

try {
if (isGithubWorkflowEnabled()) {
// TODO: pass the reduced list of testIds along / deal with them somehow
await createGithubWorkflow({ job, directory, gitSha, atVersion });
if (workflowService === AUTOMATION_SERVICE.GITHUB_ACTIONS) {
if (isGithubWorkflowEnabled()) {
// TODO: pass the reduced list of testIds along / deal with them somehow
await createGithubWorkflow({ job, directory, gitSha, atVersion });
} else {
console.error(
'GitHub Workflow Service is not enabled. Starting simulation job.'
);
await startCollectionJobSimulation(job, atVersion, transaction);
}
} else if (workflowService === AUTOMATION_SERVICE.AZURE_PIPELINES) {
if (isAzurePipelinesEnabled()) {
await triggerAzurePipeline({ job, directory, gitSha, atVersion });
} else {
console.error(
'Azure Pipelines Service is not enabled. Starting simulation job.'
);
await startCollectionJobSimulation(job, atVersion, transaction);
}
} else {
await startCollectionJobSimulation(job, testIds, atVersion, transaction);
}
Expand Down Expand Up @@ -515,20 +545,25 @@ const retryCanceledCollections = async ({ collectionJob }, { transaction }) => {
transaction
});

return triggerWorkflow(job, testIds, atVersion, { transaction });
const { automationService } = collectionJob.testPlanRun;

return triggerWorkflow(job, testIds, atVersion, automationService, {
transaction
});
};

/**
* Schedule a collection job with Response Scheduler
* @param {object} input object for request to schedule job
* @param {string} input.testPlanReportId id of test plan report to use for scheduling
* @param {string} input.workflowService
* @param {Array<string>} input.testIds optional: ids of tests to run
* @param {object} options
* @param {*} options.transaction - Sequelize transaction
* @returns {Promise<*>}
*/
const scheduleCollectionJob = async (
{ testPlanReportId, testIds = null },
{ testPlanReportId, workflowService, testIds = null },
{ transaction }
) => {
const context = getGraphQLContext({ req: { transaction } });
Expand Down Expand Up @@ -596,6 +631,7 @@ const scheduleCollectionJob = async (
job,
testIds ?? tests.map(test => test.id),
atVersion,
workflowService,
{
transaction
}
Expand Down Expand Up @@ -693,10 +729,13 @@ const restartCollectionJob = async ({ id }, { transaction }) => {
transaction
});

const { automationService } = job.testPlanRun;

return triggerWorkflow(
job,
tests.map(test => test.id),
atVersion,
automationService,
{ transaction }
);
};
Expand Down
7 changes: 5 additions & 2 deletions server/models/services/TestPlanRunService.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const getTestPlanRuns = async ({
/**
* @param {object} options
* @param {object} options.values - values to be used to create the TestPlanRun
* @param {string} options.values.automationService
* @param {string[]} options.testPlanRunAttributes - TestPlanRun attributes to be returned in the result
* @param {string[]} options.nestedTestPlanRunAttributes - TestPlanRun attributes associated to the TestPlanReport model to be returned
* @param {string[]} options.testPlanReportAttributes - TestPlanReport attributes to be returned in the result
Expand All @@ -233,7 +234,8 @@ const createTestPlanRun = async ({
testerUserId,
testPlanReportId,
testResults = [],
isAutomated = false
isAutomated = false,
automationService = null
},
testPlanRunAttributes = TEST_PLAN_RUN_ATTRIBUTES,
nestedTestPlanRunAttributes = TEST_PLAN_RUN_ATTRIBUTES,
Expand Down Expand Up @@ -270,7 +272,8 @@ const createTestPlanRun = async ({
testerUserId,
testPlanReportId,
testResults,
initiatedByAutomation: isAutomated
initiatedByAutomation: isAutomated,
automationService
},
transaction
});
Expand Down
31 changes: 31 additions & 0 deletions server/seeders/20241121004144-populateAutomationServiceColumn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
/**
* Add seed commands here.
*
* Example:
* await queryInterface.bulkInsert('People', [{
* name: 'John Doe',
* isBetaMember: false
* }], {});
*/
await queryInterface.bulkUpdate('TestPlanRun', {
automationService: 'GITHUB_ACTIONS'
});
},

async down(queryInterface) {
/**
* Add commands to revert seed here.
*
* Example:
* await queryInterface.bulkDelete('People', null, {});
*/
await queryInterface.bulkUpdate('TestPlanRun', {
automationService: null
});
}
};
Loading
Loading