Skip to content

Commit

Permalink
chore: update diff algorithms (#8)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
shellscape authored Oct 19, 2019
1 parent 7b3c47f commit 3bfae15
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 11 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"rollup": "^1.20.1",
"tslib": "^1.10.0",
"tslint": "^5.19.0",
"typescript": "^3.4.3"
"typescript": "^3.4.3",
"yaml": "^1.7.2"
},
"ava": {
"files": [
Expand Down
39 changes: 34 additions & 5 deletions pnpm-lock.yaml

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

44 changes: 39 additions & 5 deletions scripts/run-changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,53 @@

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

const { existsSync } = require('fs');
const { join } = require('path');
const { existsSync, readFileSync } = require('fs');
const { join, sep } = require('path');

const chalk = require('chalk');
const execa = require('execa');
const yaml = require('yaml');

const [, , task] = process.argv;
const { log } = console;
const sha = process.env.CIRCLE_SHA1 || 'HEAD';

const getDiff = async () => {
const {
CIRCLE_BRANCH,
CIRCLE_SHA1,
CIRCLE_COMPARE_URL,
GITHUB_SHA,
GITHUB_BASE_REF
} = process.env;
let baseRef = 'master';
let sha = 'HEAD';

if (CIRCLE_SHA1) {
if (CIRCLE_BRANCH === 'master' && CIRCLE_COMPARE_URL) {
const reCompare = /compare\/([0-9a-z]+)\.\.\.([0-9a-z]+)$/;
const [, from] = CIRCLE_COMPARE_URL.match(reCompare);
baseRef = from || 'master';
}
sha = CIRCLE_SHA1;
}

if (GITHUB_SHA) {
sha = GITHUB_SHA;
baseRef = GITHUB_BASE_REF || 'master';
}

log(chalk`{blue Comparing ${baseRef}...${sha}}`);

const { stdout } = await execa('git', ['diff', `${baseRef}...${sha}`, '--name-only']);
return stdout;
};

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

0 comments on commit 3bfae15

Please sign in to comment.