Search code examples
githubpathimagemagickgithub-actionschocolatey

Unable to use ImageMagick after installed via Chocolatey under a GitHub action for a Windows image


I hope, someone could help me to figure out how to use Chocolatey to install various software in the GitHub Actions pipeline. The issue is obviously with the PATH environment variable. Here is the part of a YAML file where I install ImageMagick, then make a simple call to display its version as a proof of concept, but the executable is not found although the respective folder is in PATH already:

- name: Install ImageMagick on Windows
  if: runner.os == 'Windows'
  run: |
    choco install -y imagemagick.app --no-progress
    Get-ChildItem -Path "${env:ProgramFiles}" | % { $_.FullName } | Select-String -Pattern "[\/\\]ImageMagick[^\/\\]*$" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8

- name: Test ImageMagick on Windows
  if: runner.os == 'Windows'
  run: |
    cmd /c "echo %PATH%"
    magick -version

Please note that refreshenv has no effect.

The second last command shows that PATH contains ImageMagick's installation directory.

The last command produces the following error:

The term 'magick' is not recognized as a name of a cmdlet, function, script file, or executable program...

Running the last command under cmd /c or the installer explicitly under PowerShell does not improve the outcome.

I also previously checked that magick.exe is in that directory, and when called using full path explicitly, everything works.

When I tried GraphicsMagick, I encountered the same problem. I'm pretty sure there is a solution, as I can't believe Chocolatey is unusable in GitHub Actions for Windows images. Please advise how to fix this particular issue with Chocolatey or suggest another package manager for Windows builds to install ImageMagick.


Solution

  • It's hard to believe, but I accidentally fixed the issue. The problem was in the line which was retrieving the actual version- and image-quality-specific installation folder (see Get-ChildItem...).

    Originally, I was filtering the right installation folder with

    Get-ChildItem -Path "${env:ProgramFiles}" | % { $_.FullName } | Select-String -Pattern "[\/\\]ImageMagick[^\/\\]*$"
    

    And today, I tried a simplified version:

    Get-ChildItem -Path "${env:ProgramFiles}" | Where-Object {($_.Name -Like 'ImageMagick*')} | % { $_.FullName }
    

    I'd never been able to guess that the former approach yields an extra empty line. Therefore, another PATH element was added, the empty one. It is still unclear why it broke things, but the latter approach works like a charm.