screwdriver-config-parser
Advanced tools
Comparing version 8.0.4 to 8.1.0
@@ -5,2 +5,3 @@ 'use strict'; | ||
const clone = require('clone'); | ||
const { STAGE_TRIGGER } = require('screwdriver-data-schema/config/regex'); | ||
@@ -546,5 +547,5 @@ const STAGE_PREFIX = 'stage@'; | ||
* @param {String} type Type of stage job (setup or teardown) | ||
* @return {String} Full stage name (e.g. stage@deploy:setup) | ||
* @return {String} Full stage job name (e.g. stage@deploy:setup) | ||
*/ | ||
function getFullStageName({ stageName, type }) { | ||
function getFullStageJobName({ stageName, type }) { | ||
return `${STAGE_PREFIX}${stageName}:${type}`; | ||
@@ -583,2 +584,29 @@ } | ||
/** | ||
* Expands stage triggers specified in 'job.requires' to stage teardown job triggers | ||
* Examples: | ||
* [stage@canary, ~stage:performance, A, B, ~C] -> [stage@canary:teardown, ~stage:performance:teardown, A, B, ~C] | ||
* stage@canary -> stage@canary:teardown | ||
* [] -> [] | ||
* | ||
* @param {Object} job Job | ||
*/ | ||
function convertStageTriggerToTeardownTrigger(job) { | ||
const converterFn = trigger => { | ||
const result = trigger.match(STAGE_TRIGGER); | ||
if (result && !result[2]) { | ||
return `${trigger}:teardown`; | ||
} | ||
return trigger; | ||
}; | ||
if (Array.isArray(job.requires)) { | ||
job.requires = job.requires.map(converterFn); | ||
} else { | ||
job.requires = converterFn(job.requires); | ||
} | ||
} | ||
/** | ||
* Flatten stage setup and teardown into jobs object | ||
@@ -593,14 +621,20 @@ * @param {Object} doc Document that went through structural parsing | ||
Object.keys(stages).forEach(stageName => { | ||
const { setup, teardown, jobs: stageJobs } = stages[stageName]; | ||
const { setup, teardown, jobs: stageJobNames } = stages[stageName]; | ||
let stageSetup = setup; | ||
let stageTeardown = teardown; | ||
stageJobs.forEach(jobName => { | ||
if (newJobs[jobName]) { | ||
newJobs[jobName].stage = { name: stageName }; | ||
Object.entries(newJobs).forEach(([jobName, job]) => { | ||
if (stageJobNames.includes(jobName)) { | ||
job.stage = { name: stageName }; | ||
if (!job.requires || job.requires.length === 0) { | ||
job.requires = `~${getFullStageJobName({ stageName, type: 'setup' })}`; | ||
} | ||
} else if (job.requires) { | ||
convertStageTriggerToTeardownTrigger(job); | ||
} | ||
}); | ||
const setupStageName = getFullStageName({ stageName, type: 'setup' }); | ||
const teardownStageName = getFullStageName({ stageName, type: 'teardown' }); | ||
const setupStageName = getFullStageJobName({ stageName, type: 'setup' }); | ||
const teardownStageName = getFullStageJobName({ stageName, type: 'teardown' }); | ||
@@ -607,0 +641,0 @@ // Implicitly create setup/teardown |
{ | ||
"name": "screwdriver-config-parser", | ||
"version": "8.0.4", | ||
"version": "8.1.0", | ||
"description": "Node module for parsing screwdriver.yaml configurations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57345
1248