Skip to content

Commit 85a2f5d

Browse files
committed
Add GitHub CI.
1 parent 7dcbbc1 commit 85a2f5d

File tree

4 files changed

+414
-1
lines changed

4 files changed

+414
-1
lines changed

.github/workflows/ci.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Explicit name of workflow. This is optional.
2+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#name
3+
name: Perl CI
4+
5+
# Specify the events that trigger this workflow.
6+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
7+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
8+
on:
9+
push:
10+
pull_request:
11+
12+
13+
# Define the jobs that make up the workflow.
14+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobs
15+
jobs:
16+
17+
# Define a job called 'test'
18+
test:
19+
20+
# Create a matrix of configurations for the job. It will be run on
21+
# the Cartesian product of the resources specified.
22+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategy
23+
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
24+
strategy:
25+
26+
# Do not cancel other jobs in the matrix if one of them fails
27+
fail-fast: false
28+
29+
# The actual matrix
30+
matrix:
31+
32+
# OS environments under which the job runs.
33+
runner: [ubuntu-latest, macos-latest, windows-latest]
34+
# Version of Perl to run. This specifies the most-recent Perl 5.
35+
perl: [ '5' ]
36+
37+
# Add minimum Perl versions, which differ among operating
38+
# systems
39+
include:
40+
- runner: ubuntu-latest
41+
# v5.8.8 is the earliest known to work
42+
perl: '5.8.8'
43+
- runner: macos-latest
44+
# v5.8.8 is the earliest known to work
45+
perl: '5.8.8'
46+
- runner: windows-latest
47+
# v5.26.0 is the earliest known to work
48+
perl: '5.26.0'
49+
# Define where the job runs.
50+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
51+
runs-on: ${{matrix.runner}}
52+
53+
# The name of this job
54+
name: OS ${{matrix.runner}} Perl ${{matrix.perl}}
55+
56+
# The individual steps in the job
57+
steps:
58+
59+
- name: Check out code
60+
uses: actions/checkout@v4
61+
62+
- name: Set up perl
63+
# Specify the action performed by this step. In this case it is a
64+
# custom action residing in repository shogo82148/actions-setup-perl
65+
# and tagged v1. Yes, shogo82148 is the user name and
66+
# actions-setup-perl is the repository name. See
67+
# https://github.com/marketplace/actions/setup-perl-environment
68+
# The available Perl versions are in
69+
# https://github.com/shogo82148/actions-setup-perl/tree/main/versions
70+
uses: shogo82148/actions-setup-perl@v1
71+
# Specify variables to the action
72+
with:
73+
perl-version: ${{ matrix.perl }}
74+
distribution: ${{ ( startsWith( matrix.runner, 'windows-' ) && 'strawberry' ) || 'default' }}
75+
76+
- name: Show Perl Version
77+
# Run a command to display the version of Perl being used.
78+
run: |
79+
perl -v
80+
81+
- name: Install support modules
82+
continue-on-error: true
83+
run: |
84+
cpanm -v
85+
cpanm File::HomeDir Getopt::Long version
86+
87+
- name: Customize environment
88+
run: |
89+
perl .github/workflows/environment.PL
90+
91+
- name: Display local envoronment variables
92+
run: |
93+
echo MY_HOME=${{ env.MY_HOME }}
94+
echo MY_IS_GITHUB_ACTION=${{ env.MY_IS_GITHUB_ACTION }}
95+
echo MY_IS_UNIX=${{ env.MY_IS_UNIX }}
96+
echo MY_IS_WINDOWS=${{ env.MY_IS_WINDOWS }}
97+
echo MY_TOOLCHAIN_EUMM=${{ env.MY_TOOLCHAIN_EUMM }}
98+
echo MY_TOOLCHAIN_MB=${{ env.MY_TOOLCHAIN_MB }}
99+
echo MY_WANT_MODULES=${{ env.MY_WANT_MODULES }}
100+
101+
# The current versions of various non-core toolchain modules have
102+
# problems under older Perls. We make use of this step to get older
103+
# versions installed if needed.
104+
- name: Install old versions of modules if on old Perl
105+
if: env.MY_WANT_MODULES
106+
run: cpanm --notest ${{ env.MY_WANT_MODULES }}
107+
108+
- name: Install module dependencies
109+
run: |
110+
cpanm Module::Build
111+
cpanm --with-configure --notest --installdeps .
112+
113+
- name: Run ExtUtils::MakeMaker tests
114+
if: env.MY_TOOLCHAIN_EUMM
115+
run: |
116+
perl Makefile.PL
117+
perl .github/workflows/make.PL
118+
perl .github/workflows/make.PL test
119+
120+
- name: Run Module::Build tests
121+
if: env.MY_TOOLCHAIN_MB
122+
run: |
123+
perl Build.PL
124+
./Build
125+
./Build test
126+
127+
# The following technique from Gabor Szabo. Thanks:
128+
# https://perlmaven.com/install-developer-dependencies-first-test-css
129+
- name: Show cpanm install log under Unix
130+
if: failure() && env.MY_IS_UNIX
131+
run: cat $MY_HOME/.cpanm/work/*/build.log
132+
133+
- name: Show cpanm install log under Windows
134+
if: failure() && env.MY_IS_WINDOWS
135+
run: |
136+
$dirs = Get-ChildItem "$env:MY_HOME\\.cpanm\\work\\"
137+
foreach ( $d in $dirs ) {
138+
$file = $d.FullName + "\\build.log"
139+
echo ""
140+
echo $file
141+
type $file
142+
}

.github/workflows/environment.PL

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/usr/bin/env perl
2+
3+
use 5.006002;
4+
5+
use strict;
6+
use warnings;
7+
8+
use Getopt::Long;
9+
use version;
10+
11+
use constant THIS_PERL => version->parse( $] );
12+
use constant PERL_5_10 => version->parse( 'v5.10.0' );
13+
use constant PERL_5_10_1 => version->parse( 'v5.10.1' );
14+
use constant PERL_5_12 => version->parse( 'v5.12.0' );
15+
16+
unless ( caller ) {
17+
my %opt;
18+
19+
GetOptions( \%opt,
20+
qw{ verbose },
21+
) or die "Bad option\n";
22+
23+
24+
my $env_hash = compute_environment();
25+
26+
my $env_text;
27+
$env_text .= "$_=$env_hash->{$_}\n" for sort keys %{ $env_hash };
28+
29+
$opt{verbose} and print $env_text;
30+
31+
defined $ENV{GITHUB_ENV}
32+
and $ENV{GITHUB_ENV} ne ''
33+
or die "Environment variable GITHUB_ENV undefined or empty\n";
34+
open my $fh, '>>:encoding(utf-8)', $ENV{GITHUB_ENV}
35+
or die "Can not open $ENV{GITHUB_ENV}: $!\n";
36+
37+
print { $fh } $env_text;
38+
39+
close $fh;
40+
}
41+
42+
sub compute_environment {
43+
my $is_windows = {
44+
MSWin32 => 1,
45+
dos => 1,
46+
}->{$^O} || '';
47+
my $is_unix = $is_windows ? '' : 1;
48+
my $my_home;
49+
{
50+
local $@ = undef;
51+
eval {
52+
require File::HomeDir;
53+
$my_home = File::HomeDir->my_home();
54+
print "Home from File::HomeDir\n";
55+
1;
56+
} or do {
57+
$my_home = $ENV{HOME};
58+
print "Home from \$HOME\n";
59+
};
60+
}
61+
my @want_modules = want_modules();
62+
my %env = (
63+
MY_HOME => $my_home,
64+
MY_IS_GITHUB_ACTION => 1,
65+
MY_IS_UNIX => $is_unix,
66+
MY_IS_WINDOWS => $is_windows,
67+
MY_TOOLCHAIN_EUMM => -e 'Makefile.PL' ? 1 : '',
68+
MY_TOOLCHAIN_MB => -e 'Build.PL' ? 1 : '',
69+
MY_WANT_MODULES => "@want_modules",
70+
);
71+
72+
$is_windows
73+
and @env{ qw{ LINES COLUMNS } } = ( 24, 80 );
74+
75+
return \%env;
76+
}
77+
78+
# FIXME Not all my distros need HTML-Tagset. Figure out a way to handle
79+
# this other than by bashing this script. This is not straightforward
80+
# because HTML-Tagset is probably not a direct dependency.
81+
sub want_modules {
82+
my ( $perl_ver ) = @_;
83+
defined $perl_ver
84+
or $perl_ver = THIS_PERL;
85+
if ( $perl_ver >= PERL_5_12 ) {
86+
return;
87+
} elsif ( $perl_ver >= PERL_5_10_1 ) {
88+
# NOTE that, thus far, XSLoader, Test-Deep, and Perl-Critic are
89+
# only needed for Perl-Critic policies, and maybe not all of
90+
# those.
91+
# NOTE that, thus far, HTML-Tagset is only needed for modules
92+
# that make use of libwww-perl, directly or indirectly.
93+
return qw{
94+
RRA/podlators-4.14.tar.gz
95+
};
96+
} elsif ( $perl_ver >= PERL_5_10 ) {
97+
return qw{
98+
RRA/podlators-4.14.tar.gz
99+
};
100+
} else {
101+
return qw{
102+
SMUELLER/ExtUtils-ParseXS-3.30.tar.gz
103+
RRA/podlators-4.14.tar.gz
104+
};
105+
}
106+
}
107+
108+
1;
109+
110+
__END__
111+
112+
=head1 TITLE
113+
114+
environment.PL - Customize GitHub Actions environment
115+
116+
=head1 SYNOPSIS
117+
118+
.github/workflows/environment.PL
119+
.github/workflows/environment.PL --verbose
120+
121+
=head1 OPTIONS
122+
123+
=head2 --verbose
124+
125+
If this Boolean option is asserted, the environment variables defiend
126+
are written to standard output.
127+
128+
The default is C<--no-verbose>.
129+
130+
=head1 DETAILS
131+
132+
This Perl script adds environment variables to the GitHub Actions
133+
environment. The following environment variables are added:
134+
135+
=head2 MY_HOME
136+
137+
The job's home directory, as determined by
138+
L<File::HomeDir|File::HomeDir>.
139+
140+
=head2 MY_IS_GITHUB_ACTION
141+
142+
Always true (i.e. C<'1'>).
143+
144+
=head2 MY_IS_UNIX
145+
146+
True (i.e. C<1>) if running under some flavor of Unix, and false (i.e.
147+
C<''>) otherwise. At the moment this is the Boolean inverse of
148+
L<MY_IS_WINDOWS|/MY_IS_WINDOWS>.
149+
150+
=head2 MY_IS_WINDOWS
151+
152+
True (i.e. C<1>) if running under Windows, and false (i.e. C<''>)
153+
othewise. At the moment this is true if C<$^O> is C<'MSWin32'> or
154+
C<'dos'>.
155+
156+
=head2 MY_WANT_MODUKES
157+
158+
A space-delimited list of modules or repositories to install B<before>
159+
installing dependencies. This is computed in an admittedly ad-hoc manner
160+
based on the version of Perl being used, and is intended to cover the
161+
case where old Perls (typically before C<5.10> can not execute the
162+
current version of a module.
163+
164+
=head1 INVOCATION AS MODULINO
165+
166+
This script can also be used (or required) as a modulino. When you do
167+
this, the following subroutines get loaded into C<main::>:
168+
169+
=head2 compute_environment
170+
171+
This subroutine takes no arguments. It returns a reference to a hash
172+
that describes the environment variables to be added to the environment.
173+
174+
=head2 want_modules
175+
176+
This subroutine takes an optional L<version|version> object representing
177+
a Perl version, and returns a list of modules or distributions to be
178+
installed that version B<before> module prerequisites are
179+
processed. If no argument is provided, the version of the
180+
currently-running Perl is assumed.
181+
182+
=head1 AUTHOR
183+
184+
Thomas R. Wyant, III F<wyant at cpan dot org>
185+
186+
=head1 COPYRIGHT AND LICENSE
187+
188+
Copyright (C) 2022 by Thomas R. Wyant, III
189+
190+
This program is free software; you can redistribute it and/or modify it
191+
under the same terms as Perl 5.10.0. For more details, see the full text
192+
of the licenses in the directory LICENSES.
193+
194+
This program is distributed in the hope that it will be useful, but
195+
without any warranty; without even the implied warranty of
196+
merchantability or fitness for a particular purpose.
197+
198+
=cut
199+
200+
# ex: set ts=8 sts=4 sw=4 tw=72 ft=perl expandtab shiftround :

0 commit comments

Comments
 (0)