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(2683): nodejs upgrade #141

Merged
merged 3 commits into from
Nov 21, 2022
Merged
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
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -45,7 +47,7 @@ function parseYaml(yaml) {
);
}

return resolve(doc);
resolve(doc);
});
}

Expand Down Expand Up @@ -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}`);
Expand Down
4 changes: 1 addition & 3 deletions lib/phase/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
})
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -37,29 +37,29 @@
"debug": false
},
"engines": {
"node": ">=12.0.0"
"node": ">=18.0.0"
},
"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"
}
Expand Down
2 changes: 1 addition & 1 deletion screwdriver.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shared:
image: node:12
image: node:18

jobs:
main:
Expand Down
2 changes: 1 addition & 1 deletion test/data/bad-notification-email-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]"
]
}
2 changes: 1 addition & 1 deletion test/data/bad-notification-shared-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.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]"
]
}
2 changes: 1 addition & 1 deletion test/data/bad-notification-slack-email-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]"
]
}
2 changes: 1 addition & 1 deletion test/data/bad-notification-slack-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.statuses[0]\" must be one of [ABORTED, CREATED, FAILURE, QUEUED, RUNNING, SUCCESS, BLOCKED, UNSTABLE, COLLAPSED, FROZEN]"
]
}
55 changes: 55 additions & 0 deletions test/data/notification-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"annotations": {},
"parameters": {},
"jobs": {
"main": [
{
"annotations": {},
"image": "node:12",
"commands": [
{
"name": "install",
"command": "npm install"
}
],
"environment": {
},
"secrets": [],
"settings": {
"email": {
"addresses": [
"[email protected]"
],
"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": {}
}
19 changes: 19 additions & 0 deletions test/data/notification-settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
jobs:
main:
image: node:12
steps:
- install: npm install
requires:
- ~pr
- ~commit
settings:
slack:
channels:
- test
statuses:
- SUCCESS
email:
addresses:
- [email protected]
statuses:
- SUCCESS
11 changes: 11 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down