Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
save
  • Loading branch information
Nikhil Thorat committed Sep 6, 2019
commit 8786a39051372e774ae608b8c68d8b7cf5de43ef
35 changes: 12 additions & 23 deletions scripts/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const filesWhitelistToTriggerBuild = [
'scripts/diff.js', 'scripts/run-build.sh'
];

const CLONE_MASTER_PATH = 'clone-master';
const CLONE_CURRENT_PATH = 'clone-current';
const CLONE_PATH = 'clone';

const dirs = readdirSync('.').filter(f => {
return f !== 'node_modules' && f !== '.git' && statSync(f).isDirectory();
Expand All @@ -46,32 +45,21 @@ if (branchName == null) {
console.log('commitSha: ', commitSha);
console.log('branchName: ', branchName);

// We cannot do --depth=1 or --single-branch here because we need multiple
// branches at older commits.
exec(`git clone https://github.com/tensorflow/tfjs ${CLONE_CURRENT_PATH}`);

// Get the merge base from the current commit and master.
shell.cd(CLONE_CURRENT_PATH);
exec(`git checkout ${branchName}`);
const mergeBase = exec(`git merge-base master ${branchName}`).stdout.trim();
const res = shell.exec(`git checkout ${commitSha}`);
if (res.code !== 0) {
console.log(`${commitSha} does not exist. PR coming from a fork.`)
}
shell.cd('..');

console.log('mergeBase: ', mergeBase);

// We cannot do --depth=1 here because we need to check out an old merge base.
// We cannot do --single-branch here because we need multiple branches.
exec(
`git clone --single-branch ` +
`https://github.com/tensorflow/tfjs ${CLONE_MASTER_PATH}`);
`git clone ` +
`https://github.com/tensorflow/tfjs ${CLONE_PATH}`);

shell.cd(CLONE_MASTER_PATH);
shell.cd(CLONE_PATH);
exec(`git checkout ${branchName}`);
const mergeBase = exec(`git merge-base master ${branchName}`).stdout.trim();
exec(`git fetch origin ${mergeBase}`);
exec(`git checkout ${mergeBase}`);
shell.cd('..');

console.log('mergeBase: ', mergeBase);

let triggerAllBuilds = false;
let whitelistDiffOutput = [];
filesWhitelistToTriggerBuild.forEach(fileToTriggerBuild => {
Expand All @@ -88,6 +76,7 @@ console.log();

let triggeredBuilds = [];
dirs.forEach(dir => {
shell.rm('-f', `${dir}/diff`);
const diffOutput = diff(`${dir}/`);
if (diffOutput !== '') {
console.log(`${dir} has modified files.`);
Expand All @@ -114,7 +103,7 @@ console.log('Triggering builds for ', triggeredBuilds.join(', '));

function diff(fileOrDirName) {
const diffCmd = `diff -rq ` +
`${CLONE_MASTER_PATH}/${fileOrDirName} ` +
`${CLONE_CURRENT_PATH}/${fileOrDirName}`;
`${CLONE_PATH}/${fileOrDirName} ` +
`${fileOrDirName}`;
return exec(diffCmd, {silent: true}, true).stdout.trim();
}