Skip to content

Commit

Permalink
Robustify GitHub CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
trwyant committed Feb 2, 2024
1 parent 9c49bb4 commit a76554e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 102 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
steps:

- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up perl
# Specify the action performed by this step. In this case it is a
Expand All @@ -78,11 +78,14 @@ jobs:
run: |
perl -v
- name: Customize environment
- name: Install support modules
continue-on-error: true
run: |
perl -V:make
cpanm -v
cpanm File::Spec Getopt::Long version
cpanm File::HomeDir Getopt::Long version
- name: Customize environment
run: |
perl .github/workflows/environment.PL
- name: Display local envoronment variables
Expand All @@ -91,7 +94,6 @@ jobs:
echo MY_IS_GITHUB_ACTION=${{ env.MY_IS_GITHUB_ACTION }}
echo MY_IS_UNIX=${{ env.MY_IS_UNIX }}
echo MY_IS_WINDOWS=${{ env.MY_IS_WINDOWS }}
echo MY_MAKE=${{ env.MY_MAKE }}
echo MY_WANT_POD_MAN=${{ env.MY_WANT_POD_MAN }}
# Non-core toolchain Module::Build needs Pod::Man, which is in
Expand All @@ -113,8 +115,8 @@ jobs:
- name: Run ExtUtils::MakeMaker tests
run: |
perl Makefile.PL
${{ env.MY_MAKE }}
${{ env.MY_MAKE }} test
perl .github/workflows/make.PL
perl .github/workflows/make.PL test
- name: Run Module::Build tests
run: |
Expand Down
133 changes: 38 additions & 95 deletions .github/workflows/environment.PL
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use 5.006002;
use strict;
use warnings;

use Config;
use File::Spec;
use Getopt::Long;
use version;

Expand Down Expand Up @@ -46,15 +44,24 @@ sub compute_environment {
dos => 1,
}->{$^O} || '';
my $is_unix = $is_windows ? '' : 1;
my $my_home = $is_windows ?
__PACKAGE__->my_home_windows() :
__PACKAGE__->my_home_unix();
my $my_home;
{
local $@ = undef;
eval {
require File::HomeDir;
$my_home = File::HomeDir->my_home();
print "Home from File::HomeDir\n";
1;
} or do {
$my_home = $ENV{HOME};
print "Home from \$HOME\n";
};
}
my %env = (
MY_HOME => $my_home,
MY_IS_GITHUB_ACTION => 1,
MY_IS_UNIX => $is_unix,
MY_IS_WINDOWS => $is_windows,
MY_MAKE => $Config{make},
MY_WANT_POD_MAN => want_pod_man(),
);

Expand All @@ -64,92 +71,6 @@ sub compute_environment {
return \%env;
}

# BEGIN Stolen shamelessly from File::HomeDir::Windows

sub my_home_windows
{
my $class = shift;

# A lot of unix people and unix-derived tools rely on
# the ability to overload HOME. We will support it too
# so that they can replace raw HOME calls with File::HomeDir.
if (exists $ENV{HOME} and defined $ENV{HOME} and length $ENV{HOME})
{
return $ENV{HOME};
}

# Do we have a user profile?
if (exists $ENV{USERPROFILE} and $ENV{USERPROFILE})
{
return $ENV{USERPROFILE};
}

# Some Windows use something like $ENV{HOME}
if (exists $ENV{HOMEDRIVE} and exists $ENV{HOMEPATH} and $ENV{HOMEDRIVE} and $ENV{HOMEPATH})
{
return File::Spec->catpath($ENV{HOMEDRIVE}, $ENV{HOMEPATH}, '',);
}

return undef;
}

sub my_home_unix
{
my $class = shift;
my $home = $class->_guess_home(@_);

# On Unix in general, a non-existent home means "no home"
# For example, "nobody"-like users might use /nonexistent
if (defined $home and not -d $home)
{
$home = undef;
}

return $home;
}

sub _guess_env_home
{
my $class = shift;
if (exists $ENV{HOME} and defined $ENV{HOME} and length $ENV{HOME})
{
return $ENV{HOME};
}

# This is from the original code, but I'm guessing
# it means "login directory" and exists on some Unixes.
if (exists $ENV{LOGDIR} and $ENV{LOGDIR})
{
return $ENV{LOGDIR};
}

return;
}

sub _guess_determined_home
{
my $class = shift;

# Light desperation on any (Unixish) platform
SCOPE:
{
my $home = (getpwuid($<))[7];
return $home if $home and -d $home;
}

return;
}

sub _guess_home
{
my $class = shift;
my $home = $class->_guess_env_home($@);
$home ||= $class->_guess_determined_home($@);
return $home;
}

# END Stolen shamelessly from File::HomeDir::Windows

sub want_pod_man {
my ( $perl_ver ) = @_;
defined $perl_ver
Expand Down Expand Up @@ -193,8 +114,8 @@ environment. The following environment variables are added:
=head2 MY_HOME
The job's home directory, as determined by internal code stolen
shamelessly from L<File::HomeDir|File::HomeDir>.
The job's home directory, as determined by
L<File::HomeDir|File::HomeDir>.
=head2 MY_IS_GITHUB_ACTION
Expand All @@ -212,12 +133,34 @@ True (i.e. C<1>) if running under Windows, and false (i.e. C<''>)
othewise. At the moment this is true if C<$^O> is C<'MSWin32'> or
C<'dos'>.
=head2 MY_PERL_IS_5_10
True (i.e. C<1>) if running under at least Perl 5.10.0, and false
(i.e. C<''>) otherwise.
=head2 MY_WANT_POD_MAN
The specification of the C<podlators> distribution to install.
Empty if the version that comes with the running Perl is OK. This
Emptu if the version that comes with the running Perl is OK. This
is needed because Module::Build requires it.
=head1 INVOCATION AS MODULINO
This script can also be used (or required) as a modulino. When you do
this, the following subroutines get loaded into C<main::>:
=head2 compute_environment
This subroutine takes no arguments. It returns a reference to a hash
that describes the environment variables to be added to the environment.
=head2 want_pod_man
This subroutine takes as its argument a L<version|version> object. It
returns the computed value of the C<MY_WANT_POD_MAN> environment
variable. If no argument is given, the computation is for the running
Perl.
=head1 AUTHOR
Thomas R. Wyant, III F<wyant at cpan dot org>
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/make.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env perl

use 5.006002;

use strict;
use warnings;

use Config;
use Getopt::Long 2.33 qw{ :config auto_version };
use Pod::Usage;

our $VERSION = '0.164';

my %opt;

GetOptions( \%opt,
help => sub { pod2usage( { -verbose => 2 } ) },
) or pod2usage( { -verbose => 0 } );

exec { $Config{make} } $Config{make}, @ARGV;

__END__
=head1 TITLE
make.PL - Perl front end to *make
=head1 SYNOPSIS
make.PL
make.PL test
make.PL --help
make.PL --version
=head1 OPTIONS
=head2 --help
This option displays the documentation for this script. The script then
exits.
=head2 --version
This option displays the version of this script. The script then exits.
=head1 DETAILS
This Perl script simply does an C<exec()> of C<$Config{make}>, passing
it all its arguments.
=head1 AUTHOR
Thomas R. Wyant, III F<wyant at cpan dot org>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2024 by Thomas R. Wyant, III
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl 5.10.0. For more details, see the full text
of the licenses in the directory LICENSES.
This program is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.
=cut
# ex: set textwidth=72 :

0 comments on commit a76554e

Please sign in to comment.