简体   繁体   English

如何在 Github 操作上执行 MSI 文件(Windows 最新运行程序)

[英]How to execute MSI file on Github Actions (windows-latest runner)

Context语境

I created a Github Actions workflow that generates a .msi file that I wan't to execute afterwards to test if the application is working as expected.我创建了一个 Github Actions 工作流,该工作流生成一个我不想在之后执行的.msi文件来测试应用程序是否按预期工作。

The workflow implementation is as below工作流实现如下

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

Basically this workflow creates the .exe file ( Create binary from branch step), then use a script in powershell that generates the .msi file ( Generate msi step), and finally try to install the .msi file ( Install msi step).基本上,这个工作流会创建.exe文件( Create binary from branch文件步骤),然后使用 powershell 中的脚本生成.msi文件( Generate msi步骤),最后尝试安装.msi文件( Install msi步骤)。


Issue问题

The problem occurs on the Install msi step, the runner logs only returns:问题出现在Install msi步骤,运行器日志仅返回:

Start Msiexec
End Msiexec

... without showing any log, or creating the directories and files as the installation should do on the $HOME directory. ...不显示任何日志,或创建目录和文件,就像安装应该在$HOME目录上做的那样。


What I tried我试过的

Using the default shell for windows-latest runner (which is cmdlet ), I tried to run those commands in the workflow without success, using "file.msi" or "path/to/file.msi" :使用默认 shell for windows-latest runner(即cmdlet ),我尝试在工作流中运行这些命令,但没有成功,使用"file.msi""path/to/file.msi"

msiexec /i "file.msi"
msiexec /qn /i "file.msi"
msiexec /qn /i "file.msi" /L*vx!

I'm not very familiar with the windows operating system, but for what I searched online, this msiexec command should work.我对 windows 操作系统不是很熟悉,但是对于我在网上搜索的内容,这个 msiexec 命令应该可以工作。

I also tried to install the .msi file generated manually on a windows 10 computer using those commands with success (so the generated .msi file is valid and working locally).我还尝试使用这些命令成功地在 windows 10 计算机上安装手动生成的.msi文件(因此生成的.msi文件有效并且在本地工作)。 However, it opens another prompt window automatically showing the installation and setup logs (it's not in the same terminal window) and I imagine this may not happen on Github Actions.但是,它会打开另一个提示 window自动显示安装和设置日志(它不在同一个终端窗口中),我想这可能不会发生在 Github 操作上。


Question问题

➡️ How can I install this application from the .msi file through a command line on the windows-latest runner? ➡️如何通过 windows-latest 运行器上的命令行从.msi文件安装此应用程序?

After asking the same thing on the Github Community forum , I got the following answer from @Simran-B (Github Advisory Council Member):Github 社区论坛上问了同样的问题后,我从@Simran-B (Github 咨询委员会成员)那里得到了以下答案:

msiexec doesn't seem to log anything to a terminal. msiexec 似乎没有向终端记录任何内容。 If your MSI does (even if in a separate window), then it must be something that is specific to that MSI…如果您的 MSI 有(即使在单独的窗口中),那么它必须是特定于该 MSI 的东西……

What msiexec supports is to log to a file. msiexec 支持的是记录到文件。 Based on Is there anyway to get msiexec to echo to stdout instead of logging to a file - Server Fault , I successfully ran the following PowerShell script (using a Blender MSI as a test):基于Is there Anyway to get msiexec to echo to stdout instead of logging to a file - Server Fault ,我成功运行了以下 PowerShell 脚本(使用 Blender MSI 作为测试):

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

I can't recommend /l*vx!我不能推荐/l*vx! , because the forced flush for every log line makes things slow and the verbose output with additional debugging information can produce thousands of lines. ,因为每个日志行的强制刷新会使事情变慢,而带有附加调试信息的冗长 output 会产生数千行。 Alternatively, you could log everything to a file without flushing, wait for msiexec to exit, and then print the file contents to the console in one go, which should be significantly faster (but you lose live logging).或者,您可以在不刷新的情况下将所有内容记录到文件中,等待msiexec退出,然后在 go 中将文件内容打印到控制台,这应该会更快(但您会丢失实时日志记录)。

If I remember correctly, GitHub-hosted runners use elevated permissions by default.如果我没记错的话,GitHub 托管的运行器默认使用提升的权限。 In my local test, I had to run the above script from an elevated PowerShell because the MSI tried to install to C:\Program Files\ , which is not writable unless you have elevated permissions, and that made the installation fail without obvious log entry.在我的本地测试中,我必须从提升的 PowerShell 运行上述脚本,因为 MSI 试图安装到C:\Program Files\ . If there's something wrong with the .msi path, you may get an exit code of 1619 ( $procMain.ExitCode ), which is also not very intuitive.如果.msi路径有问题,您可能会得到 1619 ( $procMain.ExitCode ) 的退出代码,这也不是很直观。 Another possible reason for nothing getting installed (at least apparently) can be that you don't actually wait for msiexec to finish - the command immediately returns and the installation process runs in the background.没有安装的另一个可能原因(至少很明显)可能是您实际上并没有等待msiexec完成 - 命令立即返回并且安装过程在后台运行。 You can use Start-Process with the -Wait option or get the handle with -PassThru and call .WaitForExit() on it to wait until it is done.您可以使用带有-Wait选项的 Start-Process 或使用 -PassThru 获取句柄并在其上调用.WaitForExit()以等待它完成。

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!它对我有用,使用这些命令,我可以执行.msi文件来安装软件,然后在我的 github 操作工作流程中使用它来执行我的测试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM