Skip to content

Commit 3bfae15

Browse files
authored
chore: update diff algorithms (#8)
* chore: print envars * chore: update diff alogrithm * chore: kick a plugin * chore: add diff info to console output * chore: use circle sha * chore: only use compare_url base on master * chore: clean up changed package
1 parent 7b3c47f commit 3bfae15

File tree

3 files changed

+75
-11
lines changed

3 files changed

+75
-11
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"rollup": "^1.20.1",
2828
"tslib": "^1.10.0",
2929
"tslint": "^5.19.0",
30-
"typescript": "^3.4.3"
30+
"typescript": "^3.4.3",
31+
"yaml": "^1.7.2"
3132
},
3233
"ava": {
3334
"files": [

pnpm-lock.yaml

Lines changed: 34 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/run-changed.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,53 @@
22

33
/* eslint-disable import/no-extraneous-dependencies */
44

5-
const { existsSync } = require('fs');
6-
const { join } = require('path');
5+
const { existsSync, readFileSync } = require('fs');
6+
const { join, sep } = require('path');
77

88
const chalk = require('chalk');
99
const execa = require('execa');
10+
const yaml = require('yaml');
1011

1112
const [, , task] = process.argv;
1213
const { log } = console;
13-
const sha = process.env.CIRCLE_SHA1 || 'HEAD';
14+
15+
const getDiff = async () => {
16+
const {
17+
CIRCLE_BRANCH,
18+
CIRCLE_SHA1,
19+
CIRCLE_COMPARE_URL,
20+
GITHUB_SHA,
21+
GITHUB_BASE_REF
22+
} = process.env;
23+
let baseRef = 'master';
24+
let sha = 'HEAD';
25+
26+
if (CIRCLE_SHA1) {
27+
if (CIRCLE_BRANCH === 'master' && CIRCLE_COMPARE_URL) {
28+
const reCompare = /compare\/([0-9a-z]+)\.\.\.([0-9a-z]+)$/;
29+
const [, from] = CIRCLE_COMPARE_URL.match(reCompare);
30+
baseRef = from || 'master';
31+
}
32+
sha = CIRCLE_SHA1;
33+
}
34+
35+
if (GITHUB_SHA) {
36+
sha = GITHUB_SHA;
37+
baseRef = GITHUB_BASE_REF || 'master';
38+
}
39+
40+
log(chalk`{blue Comparing ${baseRef}...${sha}}`);
41+
42+
const { stdout } = await execa('git', ['diff', `${baseRef}...${sha}`, '--name-only']);
43+
return stdout;
44+
};
1445

1546
(async () => {
16-
const rePkg = /(packages\/([\w\-_]+))\/?/;
17-
const { stdout: diff } = await execa('git', ['diff', `master...${sha}`, '--name-only']);
47+
const workspace = readFileSync(join(__dirname, '..', 'pnpm-workspace.yaml'), 'utf-8');
48+
const { packages } = yaml.parse(workspace);
49+
const roots = packages.map((item) => item.split(sep)[0]).join('|');
50+
const rePkg = new RegExp(`(${roots}/([\\w\\-_]+))/?`);
51+
const diff = await getDiff();
1852
const filters = diff
1953
.split('\n')
2054
.filter((line) => rePkg.test(line) && existsSync(join(__dirname, '..', line)))

0 commit comments

Comments
 (0)