如何在 Github 操作上执行 MSI 文件(windows-最新的跑步者)

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

上下文

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

工作流实现如下

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"

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


问题

问题出现在Install msi步,运行ner只记录returns:

Start Msiexec
End Msiexec

...不显示任何日志,或创建目录和文件,因为安装应该在 $HOME 目录上进行。


我试过的

对windows-最新的运行ner(即cmdlet)使用默认的shell,我尝试运行工作流程中的那些命令没有成功,使用 "file.msi""path/to/file.msi":

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

我对windows操作系统不是很熟悉,不过网上搜索了一下,这个msiexec命令应该可以。

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


问题

➡️ 如何在 windows-latest 运行ner 上通过命令行从 .msi 文件安装此应用程序?

Github Community forum, I got the following answer from @Simran-B(Github 咨询委员会成员)询问同样的事情后:

msiexec doesn’t seem to log anything to a terminal. If your MSI does (even if in a separate window), then it must be something that is specific to that MSI…

What msiexec supports is to log to a file. 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):

$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!, because the forced flush for every log line makes things slow and the verbose output with additional debugging information can produce thousands of lines. 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).

If I remember correctly, GitHub-hosted runners use elevated permissions by default. 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. 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. 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. 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.

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