screwdriver-config-parser
Advanced tools
Comparing version 8.0.1 to 8.0.2
@@ -155,8 +155,3 @@ 'use strict'; | ||
// If job name is repeated in stages, throw error | ||
const duplicateJobsInStage = stageJobNames.filter( | ||
( | ||
s => v => | ||
s.has(v) || !s.add(v) | ||
)(new Set()) | ||
); | ||
const duplicateJobsInStage = stageJobNames.filter((item, index) => stageJobNames.indexOf(item) !== index); | ||
@@ -163,0 +158,0 @@ if (duplicateJobsInStage.length > 0) { |
@@ -6,2 +6,5 @@ 'use strict'; | ||
const STAGE_PREFIX = 'stage@'; | ||
const DEFAULT_JOB = { image: 'node:18', steps: [{ noop: 'echo noop' }] }; | ||
/** | ||
@@ -109,2 +112,6 @@ * Check if a job has duplicate steps | ||
if (oldJob.stage) { | ||
newJob.stage = oldJob.stage || {}; | ||
} | ||
// Merge secrets | ||
@@ -311,3 +318,3 @@ const newSecrets = newJob.secrets || []; | ||
*/ | ||
function mergeTemplateIntoJob(jobName, jobConfig, newJobs, templateFactory, sharedConfig, pipelineParameters) { | ||
function mergeTemplateIntoJob({ jobName, jobConfig, newJobs, templateFactory, sharedConfig, pipelineParameters }) { | ||
const oldJob = jobConfig; | ||
@@ -433,3 +440,12 @@ | ||
if (templateConfig) { | ||
templates.push(mergeTemplateIntoJob(jobName, jobConfig, newJobs, templateFactory, shared, parameters)); | ||
templates.push( | ||
mergeTemplateIntoJob({ | ||
jobName, | ||
jobConfig, | ||
newJobs, | ||
templateFactory, | ||
sharedConfig: shared, | ||
pipelineParameters: parameters | ||
}) | ||
); | ||
} else { | ||
@@ -530,2 +546,90 @@ newJobs[jobName] = jobConfig; // Otherwise just use jobConfig | ||
/** | ||
* Get full stage name | ||
* @param {String} stageName Stage name | ||
* @param {String} type Type of stage job (setup or teardown) | ||
* @return {String} Full stage name (e.g. stage@deploy:setup) | ||
*/ | ||
function getFullStageName({ stageName, type }) { | ||
return `${STAGE_PREFIX}${stageName}:${type}`; | ||
} | ||
/** | ||
* Get stage teardown requires nodes | ||
* @param {Object} jobs Jobs | ||
* @param {String} stageName Stage name | ||
* @return {Array} Teardown requires | ||
*/ | ||
function getTeardownRequires(jobs, stageName) { | ||
const stageJobsRequires = []; | ||
const stageJobNames = []; | ||
// Find jobs that belong to the stage | ||
// Get requires for jobs that belong to the stage | ||
Object.keys(jobs).forEach(jobName => { | ||
if (jobs[jobName].stage && jobs[jobName].stage.name === stageName) { | ||
if (Array.isArray(jobs[jobName].requires)) { | ||
stageJobsRequires.concat(jobs[jobName].requires); | ||
} else { | ||
stageJobsRequires.push(jobs[jobName].requires); | ||
} | ||
stageJobNames.push(jobName); | ||
} | ||
}); | ||
// Get terminal nodes | ||
const teardownRequires = stageJobNames.filter( | ||
jobName => !stageJobsRequires.includes(jobName) && !stageJobsRequires.includes(`~${jobName}`) | ||
); | ||
return teardownRequires; | ||
} | ||
/** | ||
* Flatten stage setup and teardown into jobs object | ||
* @param {Object} doc Document that went through structural parsing | ||
*/ | ||
function flattenStageSetupAndTeardownJobs(doc) { | ||
const newJobs = clone(doc.jobs); | ||
const stages = clone(doc.stages); | ||
if (stages) { | ||
Object.keys(stages).forEach(stageName => { | ||
const { setup, teardown, jobs: stageJobs } = stages[stageName]; | ||
let stageSetup = setup; | ||
let stageTeardown = teardown; | ||
stageJobs.forEach(jobName => { | ||
if (newJobs[jobName]) { | ||
newJobs[jobName].stage = { name: stageName }; | ||
} | ||
}); | ||
const setupStageName = getFullStageName({ stageName, type: 'setup' }); | ||
const teardownStageName = getFullStageName({ stageName, type: 'teardown' }); | ||
// Implicitly create setup/teardown | ||
if (Hoek.deepEqual(stageSetup, {})) { | ||
stageSetup = DEFAULT_JOB; | ||
} | ||
if (Hoek.deepEqual(stageTeardown, {})) { | ||
stageTeardown = DEFAULT_JOB; | ||
} | ||
newJobs[setupStageName] = { | ||
...stageSetup, | ||
...{ requires: stages[stageName].requires || [], stage: { name: stageName } } | ||
}; | ||
newJobs[teardownStageName] = { | ||
...stageTeardown, | ||
...{ requires: getTeardownRequires(newJobs, stageName), stage: { name: stageName } } | ||
}; | ||
delete stages[stageName].teardown; | ||
delete stages[stageName].setup; | ||
}); | ||
} | ||
return { jobs: newJobs, stages }; | ||
} | ||
/** | ||
* Flatten Phase | ||
@@ -545,2 +649,11 @@ * | ||
// Flatten stage setup and teardown into jobs | ||
const { jobs, stages } = flattenStageSetupAndTeardownJobs(parsedDoc); | ||
doc.jobs = jobs; | ||
if (stages) { | ||
doc.stages = stages; | ||
} | ||
// Flatten shared into jobs | ||
@@ -547,0 +660,0 @@ doc.jobs = flattenSharedIntoJobs(parsedDoc.shared, parsedDoc.jobs); |
@@ -35,3 +35,3 @@ 'use strict'; | ||
if ('slack' in settings) { | ||
if (settings && 'slack' in settings) { | ||
error = SlackValidation.validateConfig(settings); | ||
@@ -45,3 +45,3 @@ if (error.error && notificationsValidationErr) { | ||
} | ||
if ('email' in settings) { | ||
if (settings && 'email' in settings) { | ||
error = EmailValidation.validateConfig(settings); | ||
@@ -48,0 +48,0 @@ if (error.error && notificationsValidationErr) { |
@@ -67,2 +67,6 @@ 'use strict'; | ||
if (doc.jobs[jobName].stage !== undefined) { | ||
job.stage = doc.jobs[jobName].stage; | ||
} | ||
// If doesn't have sourcePaths, then don't set it | ||
@@ -69,0 +73,0 @@ if (doc.jobs[jobName].sourcePaths.length > 0) { |
@@ -13,7 +13,9 @@ 'use strict'; | ||
function checkAdditionalRules(data) { | ||
const { jobs } = data; | ||
const errors = []; | ||
Object.keys(data.jobs).forEach(job => { | ||
Object.keys(jobs).forEach(job => { | ||
let firstUserTeardownStep = -1; | ||
const { steps } = data.jobs[job]; | ||
const { steps } = jobs[job]; | ||
@@ -38,3 +40,3 @@ if (steps) { | ||
Object.keys(data.cache.job).forEach(jobname => { | ||
if (!(jobname in data.jobs)) { | ||
if (!(jobname in jobs)) { | ||
errors.push(new Error(`Cache is set for non-existing job: ${jobname}`)); | ||
@@ -41,0 +43,0 @@ } |
{ | ||
"name": "screwdriver-config-parser", | ||
"version": "8.0.1", | ||
"version": "8.0.2", | ||
"description": "Node module for parsing screwdriver.yaml configurations", | ||
@@ -16,3 +16,3 @@ "main": "index.js", | ||
"homepage": "https://github.com/screwdriver-cd/config-parser", | ||
"bugs": "https://github.com/screwdriver-cd/config-parser/issues", | ||
"bugs": "https://github.com/screwdriver-cd/screwdriver/issues", | ||
"keywords": [ | ||
@@ -61,4 +61,4 @@ "screwdriver", | ||
"screwdriver-data-schema": "^22.0.0", | ||
"screwdriver-notifications-email": "^3.0.0", | ||
"screwdriver-notifications-slack": "^4.0.0", | ||
"screwdriver-notifications-email": "^3.0.1", | ||
"screwdriver-notifications-slack": "^5.0.0", | ||
"screwdriver-workflow-parser": "^4.0.0", | ||
@@ -65,0 +65,0 @@ "shell-escape": "^0.2.0", |
@@ -25,3 +25,3 @@ # Screwdriver.yaml Configuration Parser | ||
main: | ||
image: node:6 | ||
image: node:18 | ||
steps: | ||
@@ -28,0 +28,0 @@ - init: npm install |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
56215
1220
+ Addedscrewdriver-notifications-slack@5.0.1(transitive)
- Removedscrewdriver-notifications-slack@4.0.1(transitive)