Making GitHub CI work with Perl 5.8.
A while back. I got a pull request from Gabor Szabo adding a GitHub action to one of my distributions. I have been working with this, but have not (so far) blogged about it because, quite frankly, I am still not sure I know what I am doing.
One of my personal desires was to test my distributions on the oldest practicable Perl for each available architecture. For Unix (i.e. Linux and macOS) this is 5.8.8, provided the distribution itself supports that. A couple days ago, though, I pushed a modification to one of my distributions and had the 5.8.8 tests blow up.
The problem turned out to be that Module::Build, for reasons I have not investigated, has Pod::Man as a dependency. The current version of Module::Build
requires Pod::Man
version 2.17, but according to corelist Perl 5.8.8 comes with Pod::Man
version 1.37, so cpanm
wants to upgrade it.
The problem with this is that as of version 5.0 released November 25 2022, the podlators distribution, which supplies Pod::Man
, requires Perl 5.10. So under 5.8.8, cpanm --with-configure --notest --installdeps .
dies trying to install podlators
.
The solution I came up with was to pre-emptively install RRA/podlators-4.14.tar.gz
under Perl 5.8.8. The implementation was in two parts: define an environment variable that recorded whether we were running under Perl 5.10, and define a job step conditioned on that variable to install podlators 4.14
if we were using an earlier Perl.
Under GitHub Actions you can define environment variables by appending their definitions to the file whose path is in environment variable GITHUB_ENV
. After struggling with PowerShell for the Windows runners, I decided to do that step in Perl. The core of the Perl script is:
defined $ENV{GITHUB_ENV} and $ENV{GITHUB_ENV} ne '' or die "Environment variable GITHUB_ENV undefined or empty\n"; open my $fh, '>>:encoding(utf-8)', $ENV{GITHUB_ENV} or die "Can not open $ENV{GITHUB_ENV}: $!\n";my $home = File::HomeDir->my_home();
my $is_5_10 = "$]" >= 5.010 ? 1 : '';
my $is_windows = {
MSWin32 => 1,
dos => 1,
}->{$^O} || '';
my $is_unix = $is_windows ? '' : 1;print $fh <<"EOD";
MY_HOME=$home
MY_IS_UNIX=$is_unix
MY_IS_WINDOWS=$is_windows
MY_PERL_IS_5_10=$is_5_10
EOD
Next I had to run this from the YAML file that defined the workflow, and act on the created value. This was done using two steps:
- name: Customize environment run: | cpanm -v cpanm File::HomeDir perl .github/workflows/environment.PL
and
- name: Install old podlators distro if on old Perl if: "! env.MY_PERL_IS_5_10" run: cpanm RRA/podlators-4.14.tar.gz
The entirety of both the GitHub Actions file ci.yml
and the Perl script environment.PL
can be found in the GitHub repository for Astro::Coord::ECI. Other, and probably better, implementations can be imagined.
Leave a comment