Skip to content

Commit e333caa

Browse files
committed
Upgrade my GitHub CI machinery to v2.0.4.
1 parent 094f75f commit e333caa

File tree

3 files changed

+88
-202
lines changed

3 files changed

+88
-202
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Explicit name of workflow. This is optional.
22
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#name
3-
name: Perl CI
3+
name: Perl CI v2.0.4
44

55
# Specify the events that trigger this workflow.
66
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
@@ -9,6 +9,11 @@ on:
99
push:
1010
pull_request:
1111

12+
# Define environment variables for all jobs
13+
env:
14+
MY_IS_GITHUB_ACTION: 1
15+
PERL_CPANM_OPT: '--mirror https://cpan.metacpan.org'
16+
1217

1318
# Define the jobs that make up the workflow.
1419
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobs
@@ -28,18 +33,13 @@ jobs:
2833

2934
# The actual matrix
3035
matrix:
31-
32-
# OS environments under which the job runs.
33-
runner: [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
3936
include:
40-
- runner: windows-latest
41-
# v5.26.0 is the earliest known to work
42-
perl: '5.26.0'
37+
- perl: 5.26.0
38+
runner: windows-latest
39+
perl:
40+
- 5
41+
runner:
42+
- windows-latest
4343
# Define where the job runs.
4444
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
4545
runs-on: ${{matrix.runner}}
@@ -67,29 +67,21 @@ jobs:
6767
perl-version: ${{ matrix.perl }}
6868
distribution: ${{ ( startsWith( matrix.runner, 'windows-' ) && 'strawberry' ) || 'default' }}
6969

70-
- name: Show Perl Version
70+
- name: Show Perl and Cpanm versions
7171
# Run a command to display the version of Perl being used.
7272
run: |
7373
perl -v
74-
75-
- name: Install support modules
76-
continue-on-error: true
77-
run: |
7874
cpanm -v
79-
cpanm File::HomeDir Getopt::Long version
8075
8176
- name: Customize environment
8277
run: |
78+
cpanm --notest File::HomeDir
8379
perl .github/workflows/environment.PL
8480
8581
- name: Display local envoronment variables
8682
run: |
87-
echo MY_HOME=${{ env.MY_HOME }}
88-
echo MY_IS_GITHUB_ACTION=${{ env.MY_IS_GITHUB_ACTION }}
89-
echo MY_IS_UNIX=${{ env.MY_IS_UNIX }}
90-
echo MY_IS_WINDOWS=${{ env.MY_IS_WINDOWS }}
91-
echo MY_TOOLCHAIN_EUMM=${{ env.MY_TOOLCHAIN_EUMM }}
92-
echo MY_TOOLCHAIN_MB=${{ env.MY_TOOLCHAIN_MB }}
83+
echo MY_MAKE=${{ env.MY_MAKE }}
84+
echo MY_PORTABLE_HOME=${{ env.MY_PORTABLE_HOME }}
9385
echo MY_WANT_MODULES=${{ env.MY_WANT_MODULES }}
9486
9587
# The current versions of various non-core toolchain modules have
@@ -101,36 +93,32 @@ jobs:
10193

10294
- name: Install module dependencies
10395
run: |
104-
cpanm Module::Build
10596
cpanm --with-configure --notest --installdeps .
10697
10798
- name: Run ExtUtils::MakeMaker tests
108-
if: env.MY_TOOLCHAIN_EUMM
99+
# Abuse the hashFiles() built-in to see if file exists. From
100+
# https://stackoverflow.com/questions/71336204/github-action-check-if-a-file-already-exists
101+
if: ${{ hashFiles( 'Makefile.PL' ) != '' }}
109102
run: |
110103
perl Makefile.PL
111-
perl .github/workflows/make.PL
112-
perl .github/workflows/make.PL test
104+
${{ env.MY_MAKE }}
105+
${{ env.MY_MAKE }} test
113106
114107
- name: Run Module::Build tests
115-
if: env.MY_TOOLCHAIN_MB
108+
if: ${{ hashFiles( 'Build.PL' ) != '' }}
116109
run: |
110+
cpanm --notest Module::Build
117111
perl Build.PL
118112
./Build
119113
./Build test
120114
121115
# The following technique from Gabor Szabo. Thanks:
122116
# https://perlmaven.com/install-developer-dependencies-first-test-css
123-
- name: Show cpanm install log under Unix
124-
if: failure() && env.MY_IS_UNIX
125-
run: cat $MY_HOME/.cpanm/work/*/build.log
126-
127-
- name: Show cpanm install log under Windows
128-
if: failure() && env.MY_IS_WINDOWS
117+
# I had to change the home directory because $HOME doesn't find the
118+
# logs under Windows. See .github/workflows/environment.PL for more
119+
# information.
120+
- name: Show cpanm install log
121+
if: failure()
122+
shell: bash
129123
run: |
130-
$dirs = Get-ChildItem "$env:MY_HOME\\.cpanm\\work\\"
131-
foreach ( $d in $dirs ) {
132-
$file = $d.FullName + "\\build.log"
133-
echo ""
134-
echo $file
135-
type $file
136-
}
124+
cat $MY_PORTABLE_HOME/.cpanm/work/*/build.log

.github/workflows/environment.PL

Lines changed: 58 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,104 +5,87 @@ use 5.006002;
55
use strict;
66
use warnings;
77

8-
use Getopt::Long;
9-
use version;
8+
use Config;
109

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";
10+
our $VERSION = '2.000004';
2211

12+
use constant THIS_PERL => "$]";
2313

14+
unless ( caller ) {
2415
my $env_hash = compute_environment();
2516

2617
my $env_text;
2718
$env_text .= "$_=$env_hash->{$_}\n" for sort keys %{ $env_hash };
2819

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;
20+
if ( defined( $ENV{GITHUB_ENV} ) && $ENV{GITHUB_ENV} ne '' ) {
21+
open my $fh, '>>:encoding(utf-8)', $ENV{GITHUB_ENV}
22+
or die "Can not open $ENV{GITHUB_ENV}: $!\n";
23+
print { $fh } $env_text;
24+
close $fh;
25+
} else {
26+
print $env_text;
27+
die "Environment variable GITHUB_ENV undefined or empty\n";
28+
}
4029
}
4130

4231
sub compute_environment {
4332
my $is_windows = {
4433
MSWin32 => 1,
4534
dos => 1,
4635
}->{$^O} || '';
47-
my $is_unix = $is_windows ? '' : 1;
48-
my $my_home;
36+
my %env = (
37+
MY_MAKE => $Config{make},
38+
MY_WANT_MODULES => join( ' ', want_modules() ),
39+
);
40+
4941
{
42+
# Finding the actual cpanm logs under Windows is a pain. $HOME
43+
# does not point to the right place, but
44+
# File::HomeDir->my_home() does. It turns out that under
45+
# Windows, the Portable module (another Adam Kennedy creation)
46+
# hooks itself into File::HomeDir. I don't know how it does its
47+
# magic, but it is NOT equivalent to File::HomeDir::Windows.
5048
local $@ = undef;
49+
my $src;
5150
eval {
5251
require File::HomeDir;
53-
$my_home = File::HomeDir->my_home();
54-
print "Home from File::HomeDir\n";
52+
$env{MY_PORTABLE_HOME} = File::HomeDir->my_home();
53+
# Windows seems to need a Posix path or bash glob doesn't
54+
# work.
55+
$is_windows
56+
and $env{MY_PORTABLE_HOME} =~ tr|\\|/|;
57+
no warnings qw{ once };
58+
$src = $File::HomeDir::IMPLEMENTED_BY;
5559
1;
5660
} or do {
57-
$my_home = $ENV{HOME};
58-
print "Home from \$HOME\n";
61+
$env{MY_PORTABLE_HOME} = $ENV{HOME};
62+
$src = '$HOME';
5963
};
64+
print "MY_PORTABLE_HOME from $src is $env{MY_PORTABLE_HOME}\n";
6065
}
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-
);
7166

7267
$is_windows
7368
and @env{ qw{ LINES COLUMNS } } = ( 24, 80 );
7469

7570
return \%env;
7671
}
7772

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.
73+
# NOTE that we rely on the templating system's perl::Type module to
74+
# compute recursive dependencies to figure out which possibly-indirect
75+
# dependencies we need to handle under old Perls.
8176
sub want_modules {
8277
my ( $perl_ver ) = @_;
8378
defined $perl_ver
8479
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-
};
80+
foreach (
81+
[ qw{ 5.010001 } ],
82+
[ qw{ 5.000000 [email protected] } ],
83+
) {
84+
my ( $version, @want ) = @{ $_ };
85+
$perl_ver >= $version
86+
and return @want;
10587
}
88+
die "Bug - Unsupported perl version $]";
10689
}
10790

10891
1;
@@ -116,42 +99,27 @@ environment.PL - Customize GitHub Actions environment
11699
=head1 SYNOPSIS
117100
118101
.github/workflows/environment.PL
119-
.github/workflows/environment.PL --verbose
120102
121103
=head1 OPTIONS
122104
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>.
105+
None.
129106
130107
=head1 DETAILS
131108
132109
This Perl script adds environment variables to the GitHub Actions
133110
environment. The following environment variables are added:
134111
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
112+
=head2 COLUMNS
141113
142-
Always true (i.e. C<'1'>).
114+
Windows only. C<'80'>.
143115
144-
=head2 MY_IS_UNIX
116+
=head2 LINES
145117
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>.
118+
Windows only. C<'24'>.
149119
150-
=head2 MY_IS_WINDOWS
120+
=head2 MY_MAKE
151121
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'>.
122+
The value of C<$Config{make}>.
155123
156124
=head2 MY_WANT_MODUKES
157125
@@ -173,19 +141,18 @@ that describes the environment variables to be added to the environment.
173141
174142
=head2 want_modules
175143
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.
144+
This subroutine takes an optional Perl version, and returns a list of
145+
modules or distributions to be installed that version B<before> module
146+
prerequisites are processed. If no argument is provided, the version of
147+
the currently-running Perl is assumed.
181148
182149
=head1 AUTHOR
183150
184151
Thomas R. Wyant, III F<wyant at cpan dot org>
185152
186153
=head1 COPYRIGHT AND LICENSE
187154
188-
Copyright (C) 2022 by Thomas R. Wyant, III
155+
Copyright (C) 2025 by Thomas R. Wyant, III
189156
190157
This program is free software; you can redistribute it and/or modify it
191158
under the same terms as Perl 5.10.0. For more details, see the full text

0 commit comments

Comments
 (0)