Skip to content

Commit

Permalink
bug/JENKINS 44303 js lint or js test failures don't fail the build (#…
Browse files Browse the repository at this point in the history
…1059)

* intentionally fail the build

* @jenkins-cd/js-builder@0.0.53 should succeed despite a failing test

* @jenkins-cd/js-builder@0.0.52 should fail properly with a failing test

* test failures, but build should succeed w/ 0.0.57

* test failures, and build should fail w/ 0.0.58

* Revert "intentionally fail the build"

This reverts commit dcf181e.

* update js-builder in blueocean-config

* [JENKINS-44303] fixing lint errors currently in master

* [JENKINS-44303] fix tests currently broken in master

* [JENKINS-44303] use new js-builder which reliably reports failures in eslint

* [JENKINS-44303] delint

* [JENKINS-44303] upgrade other js-builder references

* reverse shrinkwrap changes

* Revert "[JENKINS-44303] use new js-builder which reliably reports failures in eslint"

This reverts commit b89545d.

* try to force al package.json and shrinkwrap back to its state before js-builder upgrades

* [JENKINS-44303] upgrade to fixed js-builder but discard updates to transitive deps in shrinkwrap

* [JENKINS-44303] align js-builder versions

* [JENKINS-44303] add special validation to shrinkwrap to ensure that create-hmac > 1.1.4 doesn't get pulled in and break the app

* try to intentionally fail build w/ lint error

* try to intentionally fail build w/ test failure

* make the build succeed again
  • Loading branch information
cliffmeyers committed May 24, 2017
1 parent 507be94 commit 29f89f2
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 29 deletions.
45 changes: 42 additions & 3 deletions bin/checkshrinkwrap.js
Expand Up @@ -51,6 +51,7 @@ function checkProject(pathToProject) {
const shrinkwrap = require(shrinkwrapJsonPath);
validateDepsAgainstShrinkwrap(allDeps, shrinkwrap);
validateShrinkwrapResolve(shrinkwrap);
validateExplicitDependencies(shrinkwrap);
console.log('success!');
}

Expand All @@ -64,7 +65,7 @@ function buildPath(path) {
}

function checkImpreciseDependencies(dependencies) {
const badDeps = [];
const badDeps = [];
Object.keys(dependencies).forEach(name => {
const version = dependencies[name];

Expand All @@ -75,7 +76,7 @@ function checkImpreciseDependencies(dependencies) {

if (badDeps.length) {
badDeps.forEach(dep => console.error(`${dep} must use precise version`));
console.error(`did you use 'npm install dep --save/-dev -E' ?`)
console.error(`did you use 'npm install dep --save/-dev -E' ?`);
process.exit(1);
}
}
Expand All @@ -92,7 +93,7 @@ function checkDuplicateDependencies(depList1, depList2) {
}

function validateShrinkwrapResolve(shrinkwrap) {

Object.keys(shrinkwrap.dependencies).forEach(name => {
if (shrinkwrap.dependencies[name].from.startsWith("..") || shrinkwrap.dependencies[name].resolved.startsWith("file:")) {
console.error(`Bad shrinkwrap resolution: 'from' or 'resolved' refer to a project relative path not absolute URI from:${shrinkwrap.dependencies[name].from} resolved:${shrinkwrap.dependencies[name].resolved} in ${name}`);
Expand Down Expand Up @@ -121,3 +122,41 @@ function validateDepsAgainstShrinkwrap(allDeps, shrinkwrap) {
process.exit(1);
}
}

function validateExplicitDependencies(shrinkwrap) {
const depRules = {
'create-hmac': {
version: '1.1.4',
message: 'create-hmac cannot exceed 1.1.4 due to an incompatibility with safe-buffer and buffer. the version may have changed if you recently upgraded js-builder. discard the updates in npm-shrinkwrap.json manually. see https://github.com/crypto-browserify/createHmac/issues/20'
},
};

function transformDeps(dependencies) {
// transform an dependency object keyed by name to an array of child dependency objects with a 'name' property.
return Object.keys(dependencies).map(depName => {
const dependency = dependencies[depName];
dependency.name = depName;
return dependency;
});
}

const depsToCheck = transformDeps(shrinkwrap.dependencies);
const failedDeps = [];

while (depsToCheck.length) {
const currentDep = depsToCheck.shift();
if (depRules[currentDep.name] && depRules[currentDep.name].version !== currentDep.version) {
const rule = depRules[currentDep.name];
failedDeps.push(`${currentDep.name}:${rule.version}: ${rule.message}`);
}
if (currentDep.dependencies) {
depsToCheck.push(...transformDeps(currentDep.dependencies));
}
}

if (failedDeps.length) {
console.error('explicit version checks in shrinkwrap failed');
failedDeps.forEach(message => console.error(message));
process.exit(1);
}
}
6 changes: 3 additions & 3 deletions blueocean-config/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blueocean-config/package.json
Expand Up @@ -14,7 +14,7 @@
"rollbar-browser": "1.9.2"
},
"devDependencies": {
"@jenkins-cd/js-builder": "0.0.57",
"@jenkins-cd/js-builder": "0.0.59",
"babel-eslint": "6.1.2",
"eslint-plugin-react": "4.3.0",
"gulp": "3.9.1"
Expand Down
6 changes: 3 additions & 3 deletions blueocean-dashboard/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blueocean-dashboard/package.json
Expand Up @@ -17,7 +17,7 @@
},
"devDependencies": {
"@jenkins-cd/eslint-config-jenkins": "0.0.2",
"@jenkins-cd/js-builder": "0.0.57",
"@jenkins-cd/js-builder": "0.0.59",
"@kadira/storybook": "2.20.1",
"babel": "6.5.2",
"babel-core": "6.17.0",
Expand Down
2 changes: 1 addition & 1 deletion blueocean-dashboard/src/main/js/components/Activity.jsx
Expand Up @@ -12,7 +12,7 @@ import { NoBranchesPlaceholder } from './placeholder/NoBranchesPlaceholder';
import {
NoRunsDefaultPlaceholder,
NoRunsForBranchPlaceholder,
NoRunsMultibranchPlaceholder
NoRunsMultibranchPlaceholder,
} from './placeholder/NoRunsPlaceholder';


Expand Down
14 changes: 9 additions & 5 deletions blueocean-dashboard/src/main/js/components/RunMessageCell.jsx
Expand Up @@ -29,14 +29,18 @@ export default class RunMessageCell extends Component {
} else if (showCommitMessage) {
const commitMsg = run.changeSet[run.changeSet.length - 1].msg;
if (run.changeSet.length > 1) {
return (<span className="RunMessageCell" title={commitMsg}><span className="RunMessageCellInner">{commitMsg}</span> <Lozenge title={t('lozenge.commit', {0: run.changeSet.length})}/></span>);
} else {
return (<span className="RunMessageCell" title={commitMsg}><span className="RunMessageCellInner">{commitMsg}</span></span>);
return (
<span className="RunMessageCell" title={commitMsg}>
<span className="RunMessageCellInner">{commitMsg}</span>
<Lozenge title={t('lozenge.commit', { 0: run.changeSet.length })} />
</span>
);
}
return (<span className="RunMessageCell" title={commitMsg}><span className="RunMessageCellInner">{commitMsg}</span></span>);
} else if (showCauses) {
// Last cause is always more significant than the first
const cause = run.causes[run.causes.length-1].shortDescription;
return (<span className="RunMessageCell" title={cause}><span className="RunMessageCellInner">{cause}</span></span>)
const cause = run.causes[run.causes.length - 1].shortDescription;
return (<span className="RunMessageCell" title={cause}><span className="RunMessageCellInner">{cause}</span></span>);
} else {
message = (<span className="RunMessageCell"><span className="RunMessageCellInner"></span></span>);
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ export default class TestCaseResultRow extends Component {
}

render() {
const { testCase: t, translation, locale = 'en', testService } = this.props;
const { testCase: t, translation, locale = 'en' } = this.props;
moment.locale(locale);
const duration = moment.duration(Number(t.duration), 'milliseconds').humanize();
const showTestCase = (t.errorStackTrace || t.errorDetails || this.stdout || this.stderr);
Expand Down
2 changes: 1 addition & 1 deletion blueocean-dashboard/src/test/js/branches-spec.js
Expand Up @@ -29,7 +29,7 @@ describe('Branches should render', () => {

const message = wrapper.find('.RunMessageCell');
expect(message).to.have.length(1);
assert.equal(message.text(), 'Update Jenkinsfile ');
assert.equal(message.text(), 'Update Jenkinsfile');
});
});

Expand Down
2 changes: 1 addition & 1 deletion blueocean-dashboard/src/test/js/run-message-cell-spec.js
Expand Up @@ -24,7 +24,7 @@ describe('RunMessageCell', () => {
causes: [],
};
const cell = render(<RunMessageCell run={run} t={t} />);
expect(cell.text()).to.equal('fix bug lozenge.commit');
expect(cell.text()).to.equal('fix buglozenge.commit');
});

it('displays with single commit', () => {
Expand Down
6 changes: 3 additions & 3 deletions blueocean-personalization/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blueocean-personalization/package.json
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@jenkins-cd/eslint-config-jenkins": "0.0.2",
"@jenkins-cd/js-builder": "0.0.57",
"@jenkins-cd/js-builder": "0.0.59",
"@kadira/storybook": "2.20.1",
"babel": "6.5.2",
"babel-core": "6.17.0",
Expand Down
6 changes: 3 additions & 3 deletions blueocean-web/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blueocean-web/package.json
Expand Up @@ -13,7 +13,7 @@
"mvntest": "gulp test lint"
},
"devDependencies": {
"@jenkins-cd/js-builder": "0.0.57",
"@jenkins-cd/js-builder": "0.0.59",
"babel-eslint": "7.0.0",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-polyfill": "6.16.0",
Expand Down
2 changes: 1 addition & 1 deletion js-extensions/package.json
Expand Up @@ -20,7 +20,7 @@
"license": "MIT",
"devDependencies": {
"@jenkins-cd/eslint-config-jenkins": "0.0.2",
"@jenkins-cd/js-builder": "0.0.57",
"@jenkins-cd/js-builder": "0.0.59",
"@jenkins-cd/js-modules": "0.0.8",
"@jenkins-cd/js-test": "1.2.3",
"@jenkins-cd/logging": "0.0.6",
Expand Down

0 comments on commit 29f89f2

Please sign in to comment.