A few months ago, Travis CI announced early access for a Windows build environment. In the last couple weeks, I spent some time to figure out how to test Perl projects there by installing Strawberry Perl from Chocolatey.
The result is the the sample project winperl-travis. It demonstrates three
.travis.yml configurations to test Perl projects on Windows:
- Use Windows instead of Linux to test multiple versions of Perl. This is the simplest configuration, but useful only for projects that never expect to run on a Unix-style OS.
- Add a Windows build stage that runs the tests against the latest version of Strawberry Perl. This pattern is ideal for projects that already test against multiple versions of Perl on Linux, and just want to make sure things work on windows.
- Add a build stage that tests against multiple versions of Strawberry Perl in separate jobs.
See the results of each of the three approaches in the CI build. A peek:
language: perl perl: - "5.28" - "5.26" - "5.24" - "5.22" - "5.20" - "5.18" - "5.16" - "5.14" - "5.12" - "5.10" - "5.8" before_install: - sudo pip install docutils - sudo apt-get install asciidoc - eval $(curl https://travis-perl.github.io/init) --auto jobs: include: - stage: Windows os: windows language: shell before_install: - cinst -y strawberryperl - export "PATH=/c/Strawberry/perl/site/bin:/c/Strawberry/perl/bin:/c/Strawberry/c/bin:$PATH" install: - cpanm --notest --installdeps . script: - cpanm -v --test-only .
The files starts with the typical Travis Perl configuration: select the
language (Perl) and the versions to test. The
before_install block installs a
couple of dependencies and executes the travis-perl helper for more flexible
Perl testing. This pattern practically serves as boilerplate for new Perl
The new bit is the
jobs.include section, which declares a new build stage
named “Windows”. This stage runs independent of the default phase, which runs on
Linux, and declares
os: windows to run on Windows.
before_install step uses the pre-installed Chocolatey package manager to
install the latest version of Strawberry Perl and update the
environment variable to include the paths to Perl and build tools. Note that the
Travis CI Window environment runs inside the Git Bash shell environment; hence
the Unix-style path configuration.
And with the stage set, the text-markup build has a nice new stage that ensures all tests pass on Windows.
The use of cpanminus, which ships with Strawberry Perl, keeps things simple,
and is essential for installing dependencies. But projects can also perform the
gmake test1 or
perl Build.PL && ./Build test
dance. Install Dist::Zilla via cpanminus to manage
prove currently does not work under Git Bash.2
Perhaps Travis will add full Perl support and things will become even easier. In the meantime, I’m pleased that I no longer have to guess about Windows compatibility. The new Travis Windows environment enables a welcome increase in cross-platform confidence.
Although versions of Strawberry Perl prior to 5.26 have trouble installing
Makefile.PL-based modules, including dependencies. I spent a fair bit of time trying to work out how to make it work, but ran out of steam. See issue #1 for details. ↩︎