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

Testing: Fail CI build if local changes exist #10234

Merged
merged 3 commits into from Oct 15, 2018
Merged

Conversation

aduth
Copy link
Member

@aduth aduth commented Sep 28, 2018

This pull request seeks to add a failure case to our existing ci script to trigger a build failure if local changes exist after one or both of npm run install (e.g. unsynced package-lock.json changes) or npm run docs:build. This has been increasingly problematic as of late due to failures to update generated files upon changes, causing confusion for later developers who are then forced to consider how to reconcile the change.

Testing instructions:

Verify that no error is produced upon running npm run ci (or, more specifically, npm run check-local-changes) after checking out the branch.

Verify that an error code is produced when making a local change (but not committing) and re-running the script.

@aduth aduth added [Type] Enhancement A suggestion for improvement. [Type] Build Tooling Issues or PRs related to build tooling [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Sep 28, 2018
@aduth aduth requested a review from gziolo September 28, 2018 14:26
@aduth aduth requested review from ellatrix and mcsf October 3, 2018 14:42
Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and this worked (didn't error when nothing changed; error'd when changes exist).

Totally awesome, thanks a mil. 👍

package.json Outdated
@@ -161,7 +161,9 @@
"build": "npm run build:packages && cross-env NODE_ENV=production webpack",
"check-engines": "check-node-version --package",
"check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"",
"ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\"",
"precheck-local-changes": "npm run docs:build",
"check-local-changes": "git diff --exit-code > /dev/null || ( echo \"There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!\" && exit 1 );",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to add a newline \n in at the end of this message; it's just a bit busy with NPM's output in there. 🤷‍♂️

screenshot 2018-10-03 11 25 38

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, especially in Travis, it's quite difficult to parse the failing output, made worse with concurrently which doesn't display the failing command in the final result (https://github.com/kimmobrunfeldt/concurrently/issues/134).

For this case specifically, it would be nice too if we could limit the output by npm, such that the message is the only thing or at least more obvious.

@tofumatt
Copy link
Member

tofumatt commented Oct 3, 2018

Oops, @mcsf beat me to it but my GitHub tab didn't update 😅

@mcsf
Copy link
Contributor

mcsf commented Oct 3, 2018

One can never have too many thumbs.

@tofumatt
Copy link
Member

tofumatt commented Oct 3, 2018

a848a38336c2a7869308c2e4de41b754

Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for package lock.

@ellatrix
Copy link
Member

ellatrix commented Oct 3, 2018

@aduth Merged #10304 which included the package lock update.

@aduth
Copy link
Member Author

aduth commented Oct 4, 2018

Build is failing because platform in which Travis runs will introduce changes to package-lock.json after an install.

See:

@aduth
Copy link
Member Author

aduth commented Oct 12, 2018

To accommodate the issue described in #10234 (comment), I've put together a small script which processes the diff via a series of disgusting regular expressions to effectively ignore the "optional": true additions to package-lock.json, while still otherwise capturing local changes which could occur by npm install.

Would love any feedback on the revised approach, otherwise I may move forward with the merge as we're continuing to see the issue crop up (#10510 (comment), #10347 (comment)).

@aduth aduth mentioned this pull request Oct 12, 2018
Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes too; they make sense and are well-explained. 🚢

@gziolo gziolo merged commit 552913a into master Oct 15, 2018
@gziolo gziolo deleted the add/ci-fail-local-changes branch October 15, 2018 09:14
@gziolo gziolo added this to the 4.1 milestone Oct 15, 2018
@gziolo
Copy link
Member

gziolo commented Oct 15, 2018

Thanks for providing working solution despite this nasty npm bug 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Build Tooling Issues or PRs related to build tooling [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants