Skip to content

Commit 4e977c9

Browse files
devongovettdannify
andauthored
Add release diffing script (#2790)
Co-authored-by: Danni <[email protected]>
1 parent e33ef26 commit 4e977c9

File tree

2 files changed

+69
-16
lines changed

2 files changed

+69
-16
lines changed

scripts/bumpVersions.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
const exec = require('child_process').execSync;
14+
const spawn = require('child_process').spawnSync;
1415
const fs = require('fs');
1516
const fetch = require('node-fetch');
1617
const semver = require('semver');
@@ -134,22 +135,19 @@ class VersionManager {
134135
return;
135136
}
136137

137-
let sinceIndex = process.argv.findIndex(arg => arg === '--since');
138-
let since = sinceIndex >= 0 ? process.argv[sinceIndex + 1] : '$(git describe --tags --abbrev=0)';
139-
let res = exec(`git diff ${since}..HEAD --name-only packages ':!**/dev/**' ':!**/docs/**' ':!**/test/**' ':!**/stories/**' ':!**/chromatic/**'`, {encoding: 'utf8'});
140-
141-
for (let line of res.trim().split('\n')) {
142-
let parts = line.split('/').slice(1, 3);
143-
if (!parts[0].startsWith('@')) {
144-
parts.pop();
145-
}
146-
147-
let name = parts.join('/');
148-
try {
149-
let pkg = JSON.parse(fs.readFileSync(`packages/${name}/package.json`, 'utf8'));
150-
this.changedPackages.add(name);
151-
} catch (err) {
152-
console.log(err);
138+
// Diff each package individually. Some packages might have been skipped during last release,
139+
// so we cannot simply look at the last tag on the whole repo.
140+
for (let name in this.workspacePackages) {
141+
let filePath = this.workspacePackages[name].location + '/package.json';
142+
let pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
143+
if (!pkg.private) {
144+
// Diff this package since the last published version, according to the package.json.
145+
// We create a git tag for each package version.
146+
let tag = `${pkg.name}@${pkg.version}`;
147+
let res = spawn('git', ['diff', '--exit-code', tag + '..HEAD', this.workspacePackages[name].location, ':!**/docs/**', ':!**/test/**', ':!**/stories/**', ':!**/chromatic/**']);
148+
if (res.status !== 0) {
149+
this.changedPackages.add(name);
150+
}
153151
}
154152
}
155153

scripts/diff.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const exec = require('child_process').execSync;
2+
const spawn = require('child_process').spawnSync;
3+
const fs = require('fs');
4+
5+
let packages = JSON.parse(exec('yarn workspaces info --json').toString().split('\n').slice(1, -2).join('\n'));
6+
let uuid = require('uuid')();
7+
8+
let ksdiff = process.argv.includes('--ksdiff');
9+
let codeOnly = process.argv.includes('--code-only');
10+
let help = process.argv.includes('--help');
11+
12+
if (help) {
13+
console.log('');
14+
console.log('This script performs a diff of changed packages since their last released version.');
15+
console.log('The following options are supported:');
16+
console.log('');
17+
console.log('--ksdiff – View the diff using Kaleidoscope rather than in the terminal');
18+
console.log('--code-only – Exclude changes to docs, tests, stories, and chromatic');
19+
console.log('');
20+
return;
21+
}
22+
23+
// Diff each package individually. Some packages might have been skipped during last release,
24+
// so we cannot simply look at the last tag on the whole repo.
25+
for (let name in packages) {
26+
let filePath = packages[name].location + '/package.json';
27+
let pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
28+
if (!pkg.private) {
29+
// Diff this package since the last published version, according to the package.json.
30+
// The release script creates a tag for each package version.
31+
let tag = `${pkg.name}@${pkg.version}`;
32+
let args = [];
33+
if (ksdiff) {
34+
// Override Kaleidoscope difftool command to use UUID, so that we can group all changes across packages together.
35+
args.push('-c', `difftool.Kaleidoscope.cmd=ksdiff --partial-changeset --UUID ${uuid} --relative-path "$MERGED" -- "$LOCAL" "$REMOTE"`);
36+
args.push('difftool');
37+
} else {
38+
args.push('diff');
39+
}
40+
41+
args.push('--exit-code', tag + '..HEAD', packages[name].location);
42+
43+
if (codeOnly) {
44+
args.push(':!**/docs/**', ':!**/test/**', ':!**/stories/**', ':!**/chromatic/**');
45+
}
46+
47+
spawn('git', args, {
48+
stdio: 'inherit'
49+
});
50+
}
51+
}
52+
53+
if (ksdiff) {
54+
exec(`ksdiff --mark-changeset-as-closed ${uuid}`);
55+
}

0 commit comments

Comments
 (0)