Skip to content

Commit

Permalink
[v6] Check git tree on CI (Azure#637)
Browse files Browse the repository at this point in the history
* initial tree check

* add npm script and check tree on ci

* Add missing changes from last commit
  • Loading branch information
joheredi authored May 5, 2020
1 parent 89aa70c commit 1caeea8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .scripts/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ steps:

- script: |
npm run test
npm run check:tree
displayName: 'Run Tests'

- script: |
npm run smoke-test
npm run check:tree
displayName: 'Run Smoke Tests'

- script: |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"build": "tsc -p .",
"check:tree": "ts-node ./test/utils/check-clean-tree.ts",
"start": "node ./dist/src/main.js",
"test": "npm-run-all unit-test integration-test",
"unit-test": "mocha -r ts-node/register './test/unit/**/*spec.ts'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const send$binaryOperationSpec: coreHttp.OperationSpec = {
httpMethod: "POST",
responses: { 204: {}, 400: {} },
requestBody: Parameters.data,
queryParameters: [Parameters.excluded1],
queryParameters: [Parameters.excluded],
urlParameters: [Parameters.$host, Parameters.thing],
headerParameters: [Parameters.contentType],
serializer
Expand All @@ -234,7 +234,7 @@ const send$textOperationSpec: coreHttp.OperationSpec = {
httpMethod: "POST",
responses: { 204: {}, 400: {} },
requestBody: Parameters.data1,
queryParameters: [Parameters.excluded1],
queryParameters: [Parameters.excluded],
urlParameters: [Parameters.$host, Parameters.thing],
headerParameters: [Parameters.contentType1],
serializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,3 @@ export const thing: coreHttp.OperationURLParameter = {
}
}
};

export const excluded1: coreHttp.OperationQueryParameter = {
parameterPath: ["options", "excluded"],
mapper: {
serializedName: "excluded",
type: {
name: "Sequence",
element: { type: { name: "String" } }
}
}
};
55 changes: 55 additions & 0 deletions test/utils/check-clean-tree.ts
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);
});

0 comments on commit 1caeea8

Please sign in to comment.