From 9fa1debd9fb2b873f53a54bd2703b18cf53811f1 Mon Sep 17 00:00:00 2001 From: klu909 Date: Fri, 18 Nov 2022 10:21:15 -0800 Subject: [PATCH 1/3] feat(2683): nodejs upgrade BREAKING CHANGE: Node 18 upgrade && eslint upgrade --- index.js | 15 +++-- lib/phase/functional.js | 4 +- package.json | 30 +++++----- screwdriver.yaml | 2 +- .../data/bad-notification-email-settings.json | 4 +- .../bad-notification-shared-settings.json | 4 +- ...ication-slack-email-settings-warnings.json | 2 +- ...bad-notification-slack-email-settings.json | 4 +- .../data/bad-notification-slack-settings.json | 4 +- test/data/notification-settings.json | 55 +++++++++++++++++++ test/data/notification-settings.yaml | 19 +++++++ test/index.test.js | 11 ++++ 12 files changed, 122 insertions(+), 32 deletions(-) create mode 100644 test/data/notification-settings.json create mode 100644 test/data/notification-settings.yaml diff --git a/index.js b/index.js index 5363e51..ca034c8 100644 --- a/index.js +++ b/index.js @@ -29,11 +29,13 @@ function parseYaml(yaml) { } return new Promise(resolve => { - const documents = YamlParser.safeLoadAll(yaml); + const documents = YamlParser.loadAll(yaml); // If only one document, return it if (documents.length === 1) { - return resolve(documents[0]); + resolve(documents[0]); + + return; } // If more than one document, look for "version: 4" @@ -45,7 +47,7 @@ function parseYaml(yaml) { ); } - return resolve(doc); + resolve(doc); }); } @@ -150,7 +152,12 @@ function verifyStages(stages, jobs) { }); // 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( + ( + s => v => + s.has(v) || !s.add(v) + )(new Set()) + ); if (duplicateJobsInStage.length > 0) { throw new YamlParser.YAMLException(`Cannot have duplicate job in multiple stages: ${duplicateJobsInStage}`); diff --git a/lib/phase/functional.js b/lib/phase/functional.js index d361830..5c4d323 100644 --- a/lib/phase/functional.js +++ b/lib/phase/functional.js @@ -158,9 +158,7 @@ function validateJobSchema(doc) { // Jobs const SCHEMA_JOB = Joi.object() .keys({ - commands: Joi.array() - .min(1) - .required(), + commands: Joi.array().min(1).required(), image: Joi.string().required(), environment: Joi.object().default({}) }) diff --git a/package.json b/package.json index 7816976..3fd6730 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "screwdriver-config-parser", - "version": "7.0.0", + "version": "8.0.0", "description": "Node module for parsing screwdriver.yaml configurations", "main": "index.js", "scripts": { @@ -41,25 +41,25 @@ }, "engine-strict": true, "devDependencies": { - "chai": "^4.2.0", - "eslint": "^7.32.0", - "eslint-config-screwdriver": "^5.0.1", - "mocha": "^8.3.0", + "chai": "^4.3.7", + "eslint": "^8.27.0", + "eslint-config-screwdriver": "^7.0.0", + "mocha": "^10.1.0", "mocha-multi-reporters": "^1.5.1", "mocha-sonarqube-reporter": "^1.0.2", - "nyc": "^15.0.0", - "sinon": "^9.0.0" + "nyc": "^15.1.0", + "sinon": "^14.0.2" }, "dependencies": { - "@hapi/hoek": "^9.2.1", + "@hapi/hoek": "^10.0.1", "clone": "^2.1.2", - "joi": "^17.6.2", - "js-yaml": "^3.14.1", - "keymbinatorial": "^1.2.0", - "screwdriver-data-schema": "^21.28.3", - "screwdriver-notifications-email": "^2.3.1", - "screwdriver-notifications-slack": "^3.3.0", - "screwdriver-workflow-parser": "^3.2.1", + "joi": "^17.7.0", + "js-yaml": "^4.1.0", + "keymbinatorial": "^2.0.0", + "screwdriver-data-schema": "^22.0.0", + "screwdriver-notifications-email": "^3.0.0", + "screwdriver-notifications-slack": "^4.0.0", + "screwdriver-workflow-parser": "^4.0.0", "shell-escape": "^0.2.0", "tinytim": "^0.1.1" } diff --git a/screwdriver.yaml b/screwdriver.yaml index 21b9557..439de20 100644 --- a/screwdriver.yaml +++ b/screwdriver.yaml @@ -1,5 +1,5 @@ shared: - image: node:12 + image: node:18 jobs: main: diff --git a/test/data/bad-notification-email-settings.json b/test/data/bad-notification-email-settings.json index 6e62b0c..512ce9f 100644 --- a/test/data/bad-notification-email-settings.json +++ b/test/data/bad-notification-email-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" + "command": "echo 'Error: main \"email\" does not match any of the allowed types'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" + "Error: main \"email\" does not match any of the allowed types" ] } \ No newline at end of file diff --git a/test/data/bad-notification-shared-settings.json b/test/data/bad-notification-shared-settings.json index afda8bc..ebef1de 100644 --- a/test/data/bad-notification-shared-settings.json +++ b/test/data/bad-notification-shared-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" + "command": "echo 'Error: main \"slack\" does not match any of the allowed types\nmain \"email\" does not match any of the allowed types'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" + "Error: main \"slack\" does not match any of the allowed types\nmain \"email\" does not match any of the allowed types" ] } \ No newline at end of file diff --git a/test/data/bad-notification-slack-email-settings-warnings.json b/test/data/bad-notification-slack-email-settings-warnings.json index c172f9d..b901cdd 100644 --- a/test/data/bad-notification-slack-email-settings-warnings.json +++ b/test/data/bad-notification-slack-email-settings-warnings.json @@ -25,7 +25,7 @@ "subscribe": {}, "warnMessages": [ "main \"slack.channnels\" is not allowed; skipping", - "main \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]; skipping" + "main \"email\" does not match any of the allowed types; skipping" ], "workflowGraph": { "nodes": [ diff --git a/test/data/bad-notification-slack-email-settings.json b/test/data/bad-notification-slack-email-settings.json index 54c57b2..6dd59fc 100644 --- a/test/data/bad-notification-slack-email-settings.json +++ b/test/data/bad-notification-slack-email-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"slack.channnels\" is not allowed\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" + "command": "echo 'Error: main \"slack.channnels\" is not allowed\nmain \"email\" does not match any of the allowed types'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"slack.channnels\" is not allowed\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" + "Error: main \"slack.channnels\" is not allowed\nmain \"email\" does not match any of the allowed types" ] } \ No newline at end of file diff --git a/test/data/bad-notification-slack-settings.json b/test/data/bad-notification-slack-settings.json index c1862a9..a2c858e 100644 --- a/test/data/bad-notification-slack-settings.json +++ b/test/data/bad-notification-slack-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" + "command": "echo 'Error: main \"slack\" does not match any of the allowed types'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" + "Error: main \"slack\" does not match any of the allowed types" ] } diff --git a/test/data/notification-settings.json b/test/data/notification-settings.json new file mode 100644 index 0000000..3e97c50 --- /dev/null +++ b/test/data/notification-settings.json @@ -0,0 +1,55 @@ +{ + "annotations": {}, + "parameters": {}, + "jobs": { + "main": [ + { + "annotations": {}, + "image": "node:12", + "commands": [ + { + "name": "install", + "command": "npm install" + } + ], + "environment": { + }, + "secrets": [], + "settings": { + "email": { + "addresses": [ + "bar@foo.com" + ], + "statuses": [ + "SUCCESS" + ] + }, + "slack": { + "channels": [ + "test" + ], + "statuses": [ + "SUCCESS" + ] + } + }, + "requires": [ + "~pr", + "~commit" + ] + } + ] + }, + "workflowGraph": { + "nodes": [ + { "name": "~pr" }, + { "name": "~commit" }, + { "name": "main" } + ], + "edges": [ + { "src": "~pr", "dest": "main" }, + { "src": "~commit", "dest": "main" } + ] + }, + "subscribe": {} +} diff --git a/test/data/notification-settings.yaml b/test/data/notification-settings.yaml new file mode 100644 index 0000000..26bd225 --- /dev/null +++ b/test/data/notification-settings.yaml @@ -0,0 +1,19 @@ +jobs: + main: + image: node:12 + steps: + - install: npm install + requires: + - ~pr + - ~commit + settings: + slack: + channels: + - test + statuses: + - SUCCESS + email: + addresses: + - bar@foo.com + statuses: + - SUCCESS \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 5c16a8e..2fdc90d 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -723,6 +723,17 @@ describe('config parser', () => { ); })); + it('reads notification annotations', () => + parser({ + yaml: loadData('notification-settings.yaml'), + templateFactory: templateFactoryMock, + buildClusterFactory: buildClusterFactoryMock, + triggerFactory, + pipelineId + }).then(data => { + assert.deepEqual(data, JSON.parse(loadData('notification-settings.json'))); + })); + it('returns an error if wrong notification slack setting', () => parser({ yaml: loadData('bad-notification-slack-settings.yaml'), From 983153b2bd23e26158d71b5c58bae76a842070a4 Mon Sep 17 00:00:00 2001 From: klu909 Date: Mon, 21 Nov 2022 10:43:55 -0800 Subject: [PATCH 2/3] revert error message --- test/data/bad-notification-email-settings.json | 4 ++-- test/data/bad-notification-shared-settings.json | 4 ++-- test/data/bad-notification-slack-email-settings-warnings.json | 2 +- test/data/bad-notification-slack-email-settings.json | 4 ++-- test/data/bad-notification-slack-settings.json | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/data/bad-notification-email-settings.json b/test/data/bad-notification-email-settings.json index 512ce9f..c2d7203 100644 --- a/test/data/bad-notification-email-settings.json +++ b/test/data/bad-notification-email-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"email\" does not match any of the allowed types'; exit 1" + "command": "echo 'Error: main \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"email\" does not match any of the allowed types" + "Error: main \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" ] } \ No newline at end of file diff --git a/test/data/bad-notification-shared-settings.json b/test/data/bad-notification-shared-settings.json index ebef1de..b9007e2 100644 --- a/test/data/bad-notification-shared-settings.json +++ b/test/data/bad-notification-shared-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"slack\" does not match any of the allowed types\nmain \"email\" does not match any of the allowed types'; exit 1" + "command": "echo 'Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"slack\" does not match any of the allowed types\nmain \"email\" does not match any of the allowed types" + "Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" ] } \ No newline at end of file diff --git a/test/data/bad-notification-slack-email-settings-warnings.json b/test/data/bad-notification-slack-email-settings-warnings.json index b901cdd..c172f9d 100644 --- a/test/data/bad-notification-slack-email-settings-warnings.json +++ b/test/data/bad-notification-slack-email-settings-warnings.json @@ -25,7 +25,7 @@ "subscribe": {}, "warnMessages": [ "main \"slack.channnels\" is not allowed; skipping", - "main \"email\" does not match any of the allowed types; skipping" + "main \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]; skipping" ], "workflowGraph": { "nodes": [ diff --git a/test/data/bad-notification-slack-email-settings.json b/test/data/bad-notification-slack-email-settings.json index 6dd59fc..7406745 100644 --- a/test/data/bad-notification-slack-email-settings.json +++ b/test/data/bad-notification-slack-email-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"slack.channnels\" is not allowed\nmain \"email\" does not match any of the allowed types'; exit 1" + "command": "echo 'Error: main \"slack.channnels\" is not allowed\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"slack.channnels\" is not allowed\nmain \"email\" does not match any of the allowed types" + "Error: main \"slack.channnels\" is not allowed\nmain \"email.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" ] } \ No newline at end of file diff --git a/test/data/bad-notification-slack-settings.json b/test/data/bad-notification-slack-settings.json index a2c858e..05dcbbd 100644 --- a/test/data/bad-notification-slack-settings.json +++ b/test/data/bad-notification-slack-settings.json @@ -7,7 +7,7 @@ "commands": [ { "name": "config-parse-error", - "command": "echo 'Error: main \"slack\" does not match any of the allowed types'; exit 1" + "command": "echo 'Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]'; exit 1" } ], "secrets": [], @@ -46,6 +46,6 @@ ] }, "errors": [ - "Error: main \"slack\" does not match any of the allowed types" + "Error: main \"slack.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]" ] } From 1c024bec05e11f4362bb4289587d300f13ca9e4c Mon Sep 17 00:00:00 2001 From: klu909 Date: Mon, 21 Nov 2022 10:45:02 -0800 Subject: [PATCH 3/3] update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3fd6730..d847acd 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "debug": false }, "engines": { - "node": ">=12.0.0" + "node": ">=18.0.0" }, "engine-strict": true, "devDependencies": {