如何在 Github Actions 上执行 MSI 文件(windows-latest runner)

Gui*_*urd 5 windows windows-installer github-actions powershell-cmdlet

语境

\n

我创建了一个 Github Actions 工作流程,生成.msi我不想稍后执行的文件,以测试应用程序是否按预期工作。

\n

工作流程实现如下

\n
build-windows:\n    runs-on: windows-latest\n    steps:\n      - uses: actions/checkout@v2.3.4\n      - name: Create binary from branch\n        run: |\n          choco install make\n          make build-windows\n      - name: Generate msi\n        shell: powershell\n        run: .\\.github\\scripts\\windows\\gen-win.ps1\n      - name: Install msi\n        run: |\n          echo "Start Msiexec"\n          msiexec /qn /i "file.msi" /L*vx!\n          echo "End Msiexec"\n
Run Code Online (Sandbox Code Playgroud)\n

基本上,此工作流程创建.exe文件(Create binary from branch步骤),然后使用 powershell 中的脚本生成.msi文件(Generate msi步骤),最后尝试安装.msi文件(Install msi步骤)。

\n
\n

问题

\n

问题发生在Install msi步骤上,运行程序日志仅返回:

\n
Start Msiexec\nEnd Msiexec\n
Run Code Online (Sandbox Code Playgroud)\n

...不显示任何日志,也不创建目录和文件,就像安装应该在$HOME

\n
\n

我尝试过的

\n

使用 Windows-latest 运行程序的默认 shell(即cmdlet),我尝试在工作流程中运行这些命令,但没有成功,使用"file.msi""path/to/file.msi"在工作流程中运行这些命令,但没有成功:

\n
msiexec /i "file.msi"\nmsiexec /qn /i "file.msi"\nmsiexec /qn /i "file.msi" /L*vx!\n
Run Code Online (Sandbox Code Playgroud)\n

我对 Windows 操作系统不是很熟悉,但是根据我在网上搜索的内容,这个 msiexec 命令应该可以工作。

\n

我还尝试.msi使用这些命令在 Windows 10 计算机上成功安装手动生成的文件(因此生成的.msi文件是有效的并且可以在本地工作)。但是,它会打开另一个提示窗口,自动显示安装和设置日志(它不在同一个终端窗口中),我想这可能不会在 Github Actions 上发生。

\n
\n

问题

\n

\xe2\x9e\xa1\xef\xb8\x8f如何从.msi通过 Windows 最新运行程序上的命令行从文件安装此应用程序?

\n

Gui*_*urd 1

在Github 社区论坛上询问了同样的问题后,我从@Simran-B(Github 咨询委员会成员)得到了以下答案:

\n
\n

msiexec 似乎不会将任何内容记录到终端。如果您的 MSI 是\n(即使在单独的窗口中),则它必须是\n特定于该 MSI\xe2\x80\xa6 的内容

\n

msiexec 支持的是记录到文件。基于Is There Anywhere\nto get msiexec to echo to stdout而不是记录到文件 - Server\nFault,\n我成功运行了以下 PowerShell 脚本(使用 Blender\nMSI 作为测试):

\n
\n
$file = "file.msi" \n$log = "install.log" \n$procMain = Start-Process "msiexec" "/i `"$file`" /qn /l*! `"$log`"" -NoNewWindow -PassThru\n$procLog = Start-Process "powershell" "Get-Content -Path `"$log`" -Wait" -NoNewWindow -PassThru \n$procMain.WaitForExit() \n$procLog.Kill()\n
Run Code Online (Sandbox Code Playgroud)\n
\n

我可以\xe2\x80\x99t 推荐/l*vx!,因为每个日志行的强制刷新会使速度变慢,并且带有附加\n调试信息的详细输出可能会产生数千行。或者,\n您可以将所有内容记录到文件中而不刷新,等待\nmsiexec退出,然后将文件内容打印到控制台,这应该会更快(但您会丢失实时日志记录)。

\n

如果我没记错的话,GitHub 托管的运行器默认使用提升的\n权限。在我的本地测试中,我必须从提升的 PowerShell 运行上述脚本,因为 MSI 尝试安装到C:\\Program Files\\,除非您具有提升的权限,否则该脚本不可写,这会导致安装失败而没有明显的日志条目。如果路径有问题.msi,您可能会得到\n退出代码 1619 ( $procMain.ExitCode),这也不是很直观。没有安装任何内容的另一个可能原因(至少显然)可能是您实际上没有等待msiexec完成 - 命令立即返回并且安装过程在后台运行。您可以使用带有-Wait\n选项的 Start-Process 或使用 -PassThru 获取句柄并调用.WaitForExit()on\n 来等待它完成。

\n
\n

It worked for me! With those commands, I could execute the .msi file to install the software, then use it afterwards in my github actions workflow to perform my tests!

\n