Installing ImageMagick on Windows-based GitHub-hosted runner
2022-03-12T08:56:42.000Z.
This article describes the steps of installing ImageMagick on Windows-based GitHub-hosted runner using pre-installed Chocolatey package manager.
Install ImageMagick
While ImageMagick can be installed Chocolatey easily, the
PATH
environment variable is not updated automatically.
Furthermore, before using the refreshenv
tool to update the
PATH
environment variables, the Chocolatey PowerShell profile
has to be installed first. Add the following steps to the workflow file:
- name: Install dependencies
run: |
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
choco install imagemagick
refreshenv
Write-Output "$env:PATH" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Check dependencies
run: magick -version
Note that Write-Output
, instead of Write-Host
,
should be used to to pipe the content of $env:PATH
to
Out-File
. Write-Host
writes the content directly
to the host for display purpose and nothing can be piped from the cmdlet.
References
- https://docs.chocolatey.org/en-us/troubleshooting#my-path-is-not-getting-updated
- https://docs.chocolatey.org/en-us/troubleshooting#refreshenv-has-no-effect
- https://docs.chocolatey.org/en-us/troubleshooting#why-does-choco-intab-not-work-for-me
- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-output?view=powershell-7.2
- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-host?view=powershell-7.2