AppVeyor 构建步骤的时间安排
Timing of AppVeyor build steps
我正在使用 appveyor.yml
文件驱动 AppVeyor 构建,在本例中是 Angular CLI 构建。这是我的文件的一部分:
test_script:
- npm run lint
- npm test
- npm run e2e
- npm run build
这些都是 npm
scripts
将实际工作委托给 ng
cli。
我怎样才能正确地获得每一步的时间?我的实际构建甚至更大一些,对于初学者,我想看看(最好是作为摘要)每一步花费了多长时间。
我尝试在每个步骤之间添加 - ps: Get-Date -Format "o"
,这是一种解决方法,但不是很好。
可以用更方便的方式完成吗?
使用来自this comment的建议:
详细:
test_script:
- powershell $sw = [Diagnostics.Stopwatch]::StartNew(); npm run lint; $sw.Stop(); Write-host "Time taken: " $sw.Elapsed.totalseconds
沉默:
test_script:
- powershell (Measure-Command { npm run lint } -Verbose).totalseconds
几点注意事项:
- 您可能根本不需要它,因为如果您将鼠标悬停在行上
UI 上的数字,您将看到时间戳(相对于构建开始)。
或者你可以下载日志,它有所有的时间戳。
- 详细输出需要更长的时间。
- 我从
cmd
模式(不是 ps
)调用 powershell
,因为 npm
写入
输出到 stdErr
这使得 AppVeyor 上的自定义 PowerShell 主机
不开心(我假设你 运行 Windows,而不是 Linux 构建)
另一个答案很有帮助,因为它提到控制台输出行号有一个带有计时信息的工具提示。您可以将此代码段用作小书签(或将其粘贴到您的控制台中)以快速了解概览:
for (let d of document.querySelectorAll('#job-console > div')) {
x = document.createElement('span');
x.innerHTML = d.title;
x.style.marginRight = '2.5rem';
x.style.color = 'yellow';
d.insertBefore(x, d.firstChild);
}
比起在我的步骤中创建一个 lot 样板文件,我更喜欢这个,例如问题的答案或我的解决方法(我想即使那样也行得通)。
我仍然希望有一种方法可以做到这一点,只需在 .yml
文件或 AppVeyor 本身中进行设置,但在那之前,我可能会坚持这样做。
这是一个书签功能,您至少可以在 Chrome 和 Firefox 中将其直接放入书签的 URL 中:
javascript:(function() { for (let d of document.querySelectorAll('#job-console > div')) { x = document.createElement('span'); x.innerHTML = d.title; x.style.marginRight = '2.5rem'; x.style.color = 'yellow'; d.style.whiteSpace = 'nowrap'; d.insertBefore(x, d.firstChild); } })()
既然工具提示中提供了信息,为什么不使用 CSS?这在更新构建时也有效。这是在我的 GreaseMonkey 脚本中(但我想你也可以在开发工具中使用样式编辑器,Stylus 或类似的):
((css) => {
let style = document.createElement("style");
style.textContent = css;
document.body.appendChild(style);
})(`
/* Stretch the log, do not limit its width */
body > div > div.row {
max-width: initial;
}
/* Prepend mm:ss before every line */
div#job-console > div:before {
visibility: visible;
content: attr(title);
color: gold;
margin-top: 0;
margin-left: -5rem;
margin-right: 4em;
height: auto;
display: inline;
}
`);
我使用 -5rem 以便完全隐藏小时部分(许多测试不需要一个小时 运行,因此为您提供了实际日志消息的三个字符)。
我正在使用 appveyor.yml
文件驱动 AppVeyor 构建,在本例中是 Angular CLI 构建。这是我的文件的一部分:
test_script:
- npm run lint
- npm test
- npm run e2e
- npm run build
这些都是 npm
scripts
将实际工作委托给 ng
cli。
我怎样才能正确地获得每一步的时间?我的实际构建甚至更大一些,对于初学者,我想看看(最好是作为摘要)每一步花费了多长时间。
我尝试在每个步骤之间添加 - ps: Get-Date -Format "o"
,这是一种解决方法,但不是很好。
可以用更方便的方式完成吗?
使用来自this comment的建议:
详细:
test_script:
- powershell $sw = [Diagnostics.Stopwatch]::StartNew(); npm run lint; $sw.Stop(); Write-host "Time taken: " $sw.Elapsed.totalseconds
沉默:
test_script:
- powershell (Measure-Command { npm run lint } -Verbose).totalseconds
几点注意事项:
- 您可能根本不需要它,因为如果您将鼠标悬停在行上 UI 上的数字,您将看到时间戳(相对于构建开始)。 或者你可以下载日志,它有所有的时间戳。
- 详细输出需要更长的时间。
- 我从
cmd
模式(不是ps
)调用powershell
,因为npm
写入 输出到stdErr
这使得 AppVeyor 上的自定义 PowerShell 主机 不开心(我假设你 运行 Windows,而不是 Linux 构建)
另一个答案很有帮助,因为它提到控制台输出行号有一个带有计时信息的工具提示。您可以将此代码段用作小书签(或将其粘贴到您的控制台中)以快速了解概览:
for (let d of document.querySelectorAll('#job-console > div')) {
x = document.createElement('span');
x.innerHTML = d.title;
x.style.marginRight = '2.5rem';
x.style.color = 'yellow';
d.insertBefore(x, d.firstChild);
}
比起在我的步骤中创建一个 lot 样板文件,我更喜欢这个,例如问题的答案或我的解决方法(我想即使那样也行得通)。
我仍然希望有一种方法可以做到这一点,只需在 .yml
文件或 AppVeyor 本身中进行设置,但在那之前,我可能会坚持这样做。
这是一个书签功能,您至少可以在 Chrome 和 Firefox 中将其直接放入书签的 URL 中:
javascript:(function() { for (let d of document.querySelectorAll('#job-console > div')) { x = document.createElement('span'); x.innerHTML = d.title; x.style.marginRight = '2.5rem'; x.style.color = 'yellow'; d.style.whiteSpace = 'nowrap'; d.insertBefore(x, d.firstChild); } })()
既然工具提示中提供了信息,为什么不使用 CSS?这在更新构建时也有效。这是在我的 GreaseMonkey 脚本中(但我想你也可以在开发工具中使用样式编辑器,Stylus 或类似的):
((css) => {
let style = document.createElement("style");
style.textContent = css;
document.body.appendChild(style);
})(`
/* Stretch the log, do not limit its width */
body > div > div.row {
max-width: initial;
}
/* Prepend mm:ss before every line */
div#job-console > div:before {
visibility: visible;
content: attr(title);
color: gold;
margin-top: 0;
margin-left: -5rem;
margin-right: 4em;
height: auto;
display: inline;
}
`);
我使用 -5rem 以便完全隐藏小时部分(许多测试不需要一个小时 运行,因此为您提供了实际日志消息的三个字符)。