-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
}, | ||
"preview": true, |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Tasks/Xcode/xcodeutils.ts
Outdated
@@ -187,6 +187,25 @@ export function pathExistsAsFile(path: string) { | |||
} | |||
} | |||
|
|||
export function pipeOutputToFile(firstTool: ToolRunner, secondTool: ToolRunner, logPrefix: string) : string { |
There was a problem hiding this comment.
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.
Tasks/Xcode/xcode.ts
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d1109ed
to
826943e
Compare
The detailed xcodebuild log will be uploaded along with the other logs