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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions bin/process-git-diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// npm will introduce changes to a `package-lock.json` file for optional
// dependencies varying on environment. If the only changes are the
// addition of an "optional" flag in `package-lock.json` file from
// `git diff`: we ignore the results.
//
// See: https://github.com/npm/npm/issues/17722

// Example usage:
//
// git diff -U0 | xargs -0 node bin/process-git-diff

// Example input:
//
// diff --git a/package-lock.json b/package-lock.json
// index e8c8a25dc..251af8689 100644
// --- a/package-lock.json
// +++ b/package-lock.json
// @@ -14373 +14373,2 @@
// - "dev": true
// + "dev": true,
// + "optional": true
// @@ -14648 +14649,2 @@
// - "dev": true
// + "dev": true,
// + "optional": true

const hasNonOptionalDiff = !! ( process.argv[ 2 ] || '' )
// Strip individual diffs of optional-only.
.replace( /@@ .+ @@\n(-.+\n\+.+,\n)?\+.+\"optional\": true,?\n/gm, '' )
// If no more line diffs remain after above, remove diff heading for file.
.replace( /diff --git a\/package-lock.json b\/package-lock.json\nindex \w+..\w+ \d+\n--- a\/package-lock.json\n\+\+\+ b\/package-lock.json\n(?!@@)/, '' );

// Exit with error code if, after replace, changes still exist.
process.exit( hasNonOptionalDiff ? 1 : 0 );
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,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 -U0 | xargs -0 node bin/process-git-diff ) || ( echo \"There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!\" && exit 1 );",
"ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\" \"npm run check-local-changes\"",
"predev": "npm run check-engines",
"dev": "npm run build:packages && concurrently \"cross-env webpack --watch\" \"npm run dev:packages\"",
"dev:packages": "node ./bin/packages/watch.js",
Expand Down