forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v6] Check git tree on CI (Azure#637)
* initial tree check * add npm script and check tree on ci * Add missing changes from last commit
- Loading branch information
Showing
5 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { spawn, ChildProcess } from "child_process"; | ||
|
||
const onExit = (childProcess: ChildProcess): Promise<string[]> => { | ||
let messages: string[] = []; | ||
return new Promise((resolve, reject) => { | ||
if (childProcess.stdout) { | ||
childProcess.stdout.on("data", message => messages.push(message)); | ||
} | ||
childProcess.once("exit", (code: number, signal: string) => { | ||
if (code === 0) { | ||
resolve(messages); | ||
} | ||
reject(new Error(`Exit with code: ${code}`)); | ||
}); | ||
|
||
childProcess.once("error", (error: Error) => { | ||
reject(error); | ||
}); | ||
}); | ||
}; | ||
|
||
async function check_tree() { | ||
await onExit( | ||
spawn("git", ["add", "-A"], { | ||
stdio: [process.stdin, process.stdout, process.stderr] | ||
}) | ||
); | ||
|
||
// If there is any output from this command it means that | ||
// there are non committed changes so we need to handle | ||
// stout | ||
const messages = await onExit( | ||
spawn("git", ["diff", "--staged", "--compact-summary"]) | ||
); | ||
|
||
if (messages.length !== 0) { | ||
// Once we have verified that there are non committed changes | ||
// run git diff again, this time forwarding the stout to present | ||
// a readable hint to the user | ||
await onExit( | ||
spawn("git", ["diff", "--staged", "--compact-summary"], { | ||
stdio: [process.stdin, process.stdout, process.stderr] | ||
}) | ||
); | ||
|
||
throw new Error( | ||
"Git tree is dirty, regenerate all test swaggers and make sure that there are no un-intended changes" | ||
); | ||
} | ||
} | ||
|
||
check_tree().catch(error => { | ||
console.error(error); | ||
process.exit(-1); | ||
}); |