After struggling to get PHP working correctly for CI on AppVeyor (in a sensible way), I have a new respect for how easy and seamless TravisCI made their setup. My situation seems pretty common among projects looking for a way to do automated testing/specs on Windows:

  1. Target a few supported major versions (ie. PHP 5.6, 7.0, 7.1, etc).
  2. Run my specs.

Easy...right? Or so you would think. Problem one: there is no builtin language support on AppVeyor like there is on Travis. You can't just enter a base programming language in the config and let it handle the setup. Nope. You install it yourself. Ok...I suppose I can handle that. By default Chocolatey is available. So installing the different needed PHP versions should be a breeze!

Enter problem number two: there is no way to select a package to install via Chocolatey in a semver type fashion. So I can't just enter cinst php -y --version "7.0.*". To get around this you can search for all PHP packages in Chocolatey and use some Powershell-Fu to select the most recent minor build:

 [string](choco search php --exact --all-versions -r `
     | Select-String -Pattern $Env:PHP_VERSION `
     | % { New-Object System.Version(($_ -split '\|')[1]) } `
     | Sort -Descending 
     | Select-Object -First 1)

And we're done...right? Nope, that leads us to problem three: some PHP prerequisites fail to install on certain builds. Yep, not all builds. Just some. After digging around it turns out that the reason is that the Windows Update service needs to be started for the prerequisite to install properly. My initial instinct was to add the needed service like so to the AppVeyor file:

  - wuauserv

...and that instinct was wrong. Apparently the service is set to startup type "disabled" which renders that service definition above useless. To get the service to start it's back to our old buddy Powershell. So add this to your growing AppVeyor file at the start of the install section:

    -ps: Set-Service wuauserv -StartupType "Automatic"; Start-Service wuauserv

Now we move on to problem four: broken Chocolatey downloads for PHP. So even after all of this I realized that there seems to be some issue with certain PHP versions in Chocolately that refuse to download. It seems to be an active/known issue with selecting PHP ZIP files from the archives location of the site. But it doesn't affect all PHP versions available on Chocolatey.

So at that point I abandoned the idea of selecting the most recent minor build of each major PHP release and just hardcoded a couple that actually work so as to avoid random build failures. On the bright side, I can now say I have specs tested against Windows finally.

It would be nice to see AppVeyor support a base set of languages that they take care of the install work on. Even if it was just a couple like Python, PHP, Ruby, Perl, etc. It's still great that they offer the service free to open-source projects, but I'd be willing to chip in a few dollars if it meant more seamless support.

Next Post Previous Post