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

chore: update diff algorithms #8

Merged
merged 7 commits into from
Oct 19, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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