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

Use xcpretty by default in Xcode task #6859

Merged
merged 8 commits into from
Apr 3, 2018

Conversation

madhurig
Copy link
Contributor

@madhurig madhurig commented Apr 2, 2018

The detailed xcodebuild log will be uploaded along with the other logs

},
"preview": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New major versions should generally start in "preview" for a sprint

@@ -19,8 +19,12 @@ async function run() {

if (publishResults) {
if (!useXcpretty) {
tl.warning(tl.loc('UseXcprettyForTestPublishing'));
} else {
throw tl.loc('UseXcprettyForTestPublishing');
Copy link
Contributor

@brcrista brcrista Apr 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we throw we should use Error and setResult with err.message below. When JavaScript built-ins throw, they will throw Error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, for some reason all places in this file didn't use it. I will update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually in the async/await pattern used in the tests, it does not matter. If we update the throw to use Error, we have to update setResult to use err.message. So we will have to update everywhere or keep what we have.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's fine. Error will get toString'ed to show its message anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should throw an Error. As @brcrista noted, anyone console.log(err) will get toString'd I believe

@@ -187,6 +187,25 @@ export function pathExistsAsFile(path: string) {
}
}

export function pipeOutputToFile(firstTool: ToolRunner, secondTool: ToolRunner, logPrefix: string) : string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function's name is a little confusing, since we are piping both to secondTool and some file created from logPrefix. I think this is because we are trying to do two things at once: create the unique log file name and pipe output. If something is too hard to name, I find it's usually a smell that it should be more modular.

So I think this is the function we want to export:

/** Find an unused file name of the form $(Agent.TempDirectory) + logPrefix + <number> + .log. */
export function createUniqueLogFileName(logPrefix: string): string {
    let filePath: string = tl.resolve(tl.getVariable('Agent.TempDirectory'), logPrefix + '.log');
    let index = 1;
    while (tl.exist(filePath)) {
        filePath = tl.resolve(tl.getVariable('Agent.TempDirectory'), logPrefix + index.toString() + '.log');
        index++;
    }
}

Then the call site looks like:

const logFile: string = utils.createUniqueLogFileName('xcodebuild_archive');
xcodeArchive.pipeExecOutputToTool(xcPrettyTool, logFile);
utils.setTaskState('XCODEBUILD_ARCHIVE_LOG', logFile);

It's an extra LOC but I find it easier to understand the logic.

@@ -439,7 +442,7 @@ async function run() {
tl.setResult(tl.TaskResult.Succeeded, tl.loc('XcodeSuccess'));
}
catch (err) {
tl.setResult(tl.TaskResult.Failed, err);
tl.setResult(tl.TaskResult.Failed, err.message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just log want to log err here. Existing code that is not throwing Error will still work, and Error will get converted to string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changed the error message (added Error: )but looks good otherwise. I updated the impacted test as well.

@madhurig madhurig force-pushed the users/madhurig/xcprettydefault branch from d1109ed to 826943e Compare April 3, 2018 17:02
@madhurig madhurig merged commit 427f7ac into master Apr 3, 2018
@madhurig madhurig deleted the users/madhurig/xcprettydefault branch April 3, 2018 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants