Skip to content

Commit

Permalink
Merge pull request #182 from screwdriver-cd/workflow
Browse files Browse the repository at this point in the history
feat(723): allows requires keyword for jobs
  • Loading branch information
d2lam authored Oct 3, 2017
2 parents e9b2d5c + 3edb0ad commit cf2561f
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const SCHEMA_JOB_PERMUTATION = Joi.object()
environment: Job.environment,
image: Job.image,
secrets: Job.secrets,
settings: Job.settings
settings: Job.settings,
requires: Job.requires
}).label('Job permutation');

const SCHEMA_JOB_PERMUTATIONS = Joi.array().items(SCHEMA_JOB_PERMUTATION)
Expand Down
10 changes: 9 additions & 1 deletion config/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ const SCHEMA_SETTINGS = Joi.object().optional();
const SCHEMA_STEP = Joi.alternatives().try(SCHEMA_STEP_STRING, SCHEMA_STEP_OBJECT);
const SCHEMA_STEPS = Joi.array().items(SCHEMA_STEP).min(1);
const SCHEMA_TEMPLATE = Joi.string().regex(Regex.FULL_TEMPLATE_NAME);

const SCHEMA_JOBNAME = Joi.string().regex(Regex.JOB_NAME);
const SCHEMA_TRIGGER = Joi.string().regex(Regex.TRIGGER); // ~commit, ~pr, etc.
const SCHEMA_REQUIRES_VALUE = Joi.alternatives().try(SCHEMA_JOBNAME, SCHEMA_TRIGGER);
const SCHEMA_REQUIRES = Joi.alternatives().try(
Joi.array().items(SCHEMA_REQUIRES_VALUE),
SCHEMA_REQUIRES_VALUE
);
const SCHEMA_JOB = Joi.object()
.keys({
requires: SCHEMA_REQUIRES,
annotations: Annotations.annotations,
description: SCHEMA_DESCRIPTION,
environment: SCHEMA_ENVIRONMENT,
Expand All @@ -91,6 +98,7 @@ module.exports = {
image: SCHEMA_IMAGE,
job: SCHEMA_JOB,
matrix: SCHEMA_MATRIX,
requires: SCHEMA_REQUIRES,
secret: SCHEMA_SECRET,
secrets: SCHEMA_SECRETS,
settings: SCHEMA_SETTINGS,
Expand Down
2 changes: 2 additions & 0 deletions config/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
STEP_NAME: /^[\w-]+$/,
// Jobs can only be named with A-Z,a-z,0-9,-,_
JOB_NAME: /^[\w-]+$/,
// Can be ~pr, ~commit, or ~commit:branchName
TRIGGER: /^~(pr|commit(:.+)?)$/,
// IEEE Std 1003.1-2001
// Environment names contain uppercase letters, digits, and underscore
// They cannot start with digits
Expand Down
10 changes: 10 additions & 0 deletions test/api/validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ describe('api validator', () => {
it('accepts basic input', () => {
assert.isNull(validate('validator.input.yaml', api.validator.input).error);
});

it('accepts input with requires keyword', () => {
assert.isNull(
validate('validator-with-requires.input.yaml', api.validator.input).error);
});
});

describe('output', () => {
it('validates basic output', () => {
assert.isNull(validate('validator.output.yaml', api.validator.output).error);
});

it('validates output with requires keyword', () => {
assert.isNull(
validate('validator-with-requires.output.yaml', api.validator.output).error);
});

it('validates basic output with errors', () => {
assert.isNull(validate('validator.erroroutput.yaml', api.validator.output).error);
});
Expand Down
8 changes: 8 additions & 0 deletions test/config/job.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ describe('config job', () => {
assert.isNull(validate('config.job.job.yaml', config.job.job).error);
});

it('validates a job with requires', () => {
assert.isNull(validate('config.job.jobv2.yaml', config.job.job).error);
});

it('returns error for bad requires format', () => {
assert.isNotNull(validate('config.job.jobv2.bad.yaml', config.job.job).error);
});

it('validates a description', () => {
assert.isNull(validate('config.job.description.yaml', config.job.job).error);
});
Expand Down
13 changes: 13 additions & 0 deletions test/data/config.job.jobv2.bad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
environment:
NODE_ENV: production
matrix:
NODE_VERSION:
- 4
- 5
- 6
image: node:{{NODE_VERSION}}
steps:
- init: npm install
- test: npm test
- publish: npm publish
requires: ~notsupportingthis
13 changes: 13 additions & 0 deletions test/data/config.job.jobv2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
environment:
NODE_ENV: production
matrix:
NODE_VERSION:
- 4
- 5
- 6
image: node:{{NODE_VERSION}}
steps:
- init: npm install
- test: npm test
- publish: npm publish
requires: ~commit
23 changes: 23 additions & 0 deletions test/data/validator-with-requires.input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
yaml: |
jobs:
main:
annotations:
beta.screwdriver.cd/auto_pr_builds: fork-only
description: "This is a description"
image: node:{{NODE_VERSION}}
matrix:
NODE_VERSION: [4,5,6]
steps:
install: npm install
test: npm test
build: npm run build
settings:
email: foo@bar.com
requires: ~commit
publish:
image: node:4
steps:
install: npm publish
requires:
- main
62 changes: 62 additions & 0 deletions test/data/validator-with-requires.output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
jobs:
main:
- image: node:4
commands:
- name: install
command: npm install
- name: test
command: npm test
- name: build
command: npm run build
annotations:
beta.screwdriver.cd/auto_pr_builds: fork-only
description: "This is a description"
environment:
NODE_VERSION: 4
settings:
email: foo@bar.com
- image: node:5
commands:
- name: install
command: npm install
- name: test
command: npm test
- name: build
command: npm run build
annotations:
beta.screwdriver.cd/auto_pr_builds: fork-only
description: "This is a description"
environment:
NODE_VERSION: 5
settings:
email: foo@bar.com
- image: node:6
commands:
- name: install
command: npm install
- name: test
command: npm test
- name: build
command: npm run build
annotations:
beta.screwdriver.cd/auto_pr_builds: fork-only
description: "This is a description"
environment:
NODE_VERSION: 6
settings:
email: foo@bar.com
secrets:
- ANOTHER_SECRET

publish:
- image: node:4
requires: main
commands:
- name: install
command: npm publish
environment: {}
secrets:
- NPM_TOKEN

workflow:
- publish

0 comments on commit cf2561f

Please sign in to comment.