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 11 commits into
base: development
Choose a base branch
from
95 changes: 55 additions & 40 deletions deploy/files/config-sandbox.env
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
$ANSIBLE_VAULT;1.1;AES256
30663031343864653133313365303935306566663531306138343464353631343730653964376239
3363306662346534646433333130343264346631623035650a356564633964366262623631633138
38666339633665636466363962366633623634333839623833636537646366373566626163633265
6337626339343937330a636438653362366166643538343834646162383563343163663666636237
31666330303834393032626264643064343864353566653763356338343135363633323364386139
38323163623265316333316538333339656533373935376366616135386338303930356335313530
31396434666337306164353637386662633037613435383136646330333137653362376437653937
39663433653837363762666637643364356131636130636163313232613336343565653133353263
37663331643633383739366164663830646339336562366338633463306335666237653335336530
66393261363066346261383865316237636361323738356364336665323063373864656237326430
38343532373463633738623032343730646533316263656232373937653439306263643938643336
37326235663163653339366266633965363239616339393833346665393731363138326530663164
32633035333636656333623536353937656530626664626164343037633965366330623538326230
39616635363039333063333637386531636434613333363733343135663538353639323839396566
38646130633630353138326532393235326438373336383434616565353231613834633563633066
30343965366430613263633038326437643461336539663266316666646132626137356163393034
61346537353937313862353637366666366137356538396535353236333639363362643139616662
63323932306264306162313765666164663265313264313963303334383330316331336261393735
64366463646563306132396564636630393736646136613465343934326166303134336138366264
33383130323334616566393765333239333138343235363935653237366237306266333032303365
65646561396661323938396461623030663566646638343038633230633263393938396165616265
30643839653133306236613061376264633263663463303531363761663262633865653066383864
39323765393535613865326531383262666564396436656131333562303863353138613339373936
66393237613562623039653930616635333261613833323932313265616138323866356633346661
63353538333731626435363334336330303266343135613432363738306365346239636264393635
30336165303634353463363831646361623538303535366465323536626239626231643837346137
39313235316164353365396335306238623936366561633533343230616533613664316233663062
61363538373965346364373837323864643138333832656466643737626363313836616637326566
38613331343238333231316436353366366331346663333536653138303561613962636132363438
39396164363838393935316635643435306336323531626336363162666165386538663561666339
31396261363163356664653961353630383432323735383633626231356637326265333938323433
66633263626330356564376435376364653263303136646536303134383232653163643664373830
34383436363862353962396234333137643866663336326563323234313463363032326165363066
31666230656564346663313732666635643864316461303837386464336162306538313165313566
38633939356631383334313162633462633163336130656663613164393864326635613662366564
31356533373137333466303439383637633239663165303438326265323363643361326261643461
33663762366266326161313364643764303563383936323938313738623566613634343933623736
38386138396538326365363834623436363861316632353031663865636336343365323439363366
38333037323632663265306137663232633731313539333930616133333735626638623931643233
63626136333030616562
62663262386433653263393533386361366339383161656464653134653566333830376339346365
3264656462353935626138353433643363656436653136620a316361356331646531623866663532
62323337303335346332346565343734626437666461626664663266353538346237646336663939
3366646137653833660a326331623562333930616539616137383735623162393332386238356134
36323036333065666436653437343064626238653361393063613762343738653730396135316337
30373133313237653131663931363130376536626161373638326661343663643936656335336138
32613933313366646165313837616431376337613762303966306530393632653861626532343363
31396435313937396635636163353666396162343764643532373339346565666431626361303364
30393337366561336338623362646364626631636137346430316430636238343762363131613535
32636235333234653266363162623366646434323961303233623633353435663934343166303136
32396230313039316166393839346161373265386565393630386335333735303264346162656334
32616433623631366438616335393331386532663537313864303739323535623830396361623962
37386636376261666461366164613230376530326437366663666463613365373965353331306366
34626661623031633263343437613732613764373530326234613530383230323933376237336466
30666430353738363137343930326439623661643464366537643230343363643463336437323130
37323637336131666364623136623665396234393830376330383265653461366436303834643635
37386436353039396664393066393237666461376465363830633661323235653139336661653039
62336536363432356164313034376333353037613639343537386138346166636430613035646535
34626333303035396266323938316430356634636361616437663639333032623236376364666535
31363462646135613737666436646563616639616637313830613336303234643736633663336263
39383037306530613061643435326631623132636565653534306362373934633761363661653364
38323666653031383933343036633730613261303334393039623264373863396137633662666138
63623964656534373964336630346536303030323065333161616433306562646438366332383431
33663530643531646235366431303637366233316536313537383162336637343666643563346338
66653530646331646532393439613661636464323866373466333535303763333462623161343936
61623234356535393531393462313761316236323339366562386334393034333761343039626133
38393337373937623233383130646239323164646131353431336539393666646165363430353831
33613433363061643438626437393333626163316166323436343033313332363765336235663233
30373666633735376237636561346134363363356534336433666636323662663131326139636633
33376135663962396634316566393538646264313339356439326336343335616564366534383435
33323936613264636437623238346261336639623330373532373064366135343563353463313166
30393333616162646161623030333162633166343039363336336561653265653632383739653939
37336131633764316135316332346437393264303662313666306134333362616365663264353938
32373531656635353836663137373963373431323032303533353334313864366534373465313036
37346330303137383966313361333038656430653739373738666233303635343962633534393333
32656439356334356263326366343065663864353066656461383438356331333866326635343135
38336431336438333262666433353030663337653432613232386636316163316335643561666263
64326562343134643362356431343666353161386563393439393363363461313064373230306262
32386638313932656436643938656562613839646366386339616634663935363336363730383837
66326232363763343564333433393836373135653233643538393662383434623837653531386663
38636161613664613035636163663366633666336431356362313130393033623764623064626638
36646234613264393635323663383166636465343866393534393935613064323531346132393535
64373030646336646263666436666266316132626637616461313831343939663666643336653832
35326134373033376131643331383738626232343039643861626639383236396563663132393138
36363033376661396564623837626637353561313532643230633332353563343762386536653161
33303731643566393761343035646539303939616638613539663563616131373033643937323939
34386434306134303064336365373938393365336332636337393438333937393531336133643833
34383162313966303966653932383561666631306166383238653261356234623265633339306236
30343332393265313238336563316534623235613437393537393038383434316437376265326665
65626534343133653437353733353134386665613230316636656463386632356430306166363738
65356533353639626532303334333635656666633761643432343961343765653361333533323364
61393535613366663966303461643834343738373032613931353963333764363663336233613139
38613038613935616465333632346638356361323061636336663966373534363237626661666336
66366237303936363130346234636566656337356233306134656365343438343162653334363535
303965633932386663666561623162346537
4 changes: 3 additions & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ listener.route('/aria-at/:branch*').get(
proxyMiddleware.proxyPath(baseUrl)
);

// Conditionally initialize github workflow service, or mock automation scheduler
// Conditionally initialize github workflow and azure pipelines services,
// or mock automation scheduler
if (
process.env.ENVIRONMENT === 'production' ||
process.env.ENVIRONMENT === 'staging' ||
process.env.ENVIRONMENT === 'sandbox' ||
process.env.AUTOMATION_CALLBACK_FQDN
) {
require('./services/GithubWorkflowService').setup();
require('./services/AzurePipelinesService').setup();
} else {
setupMockAutomationSchedulerServer().catch(error => {
console.error('Failed to initialize mock automation server:', error);
Expand Down
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
Loading
Loading