From a76554e43fb1bcb9dc811d368511e03acc22a169 Mon Sep 17 00:00:00 2001 From: Tom Wyant Date: Fri, 2 Feb 2024 10:07:42 -0500 Subject: [PATCH] Robustify GitHub CI. --- .github/workflows/ci.yml | 16 ++-- .github/workflows/environment.PL | 133 +++++++++---------------------- .github/workflows/make.PL | 69 ++++++++++++++++ 3 files changed, 116 insertions(+), 102 deletions(-) create mode 100644 .github/workflows/make.PL diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 364292a1..8eace924 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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 @@ -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: | diff --git a/.github/workflows/environment.PL b/.github/workflows/environment.PL index c4a730bb..5a173483 100644 --- a/.github/workflows/environment.PL +++ b/.github/workflows/environment.PL @@ -5,8 +5,6 @@ use 5.006002; use strict; use warnings; -use Config; -use File::Spec; use Getopt::Long; use version; @@ -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(), ); @@ -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 @@ -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. +The job's home directory, as determined by +L. =head2 MY_IS_GITHUB_ACTION @@ -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 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: + +=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 object. It +returns the computed value of the C environment +variable. If no argument is given, the computation is for the running +Perl. + =head1 AUTHOR Thomas R. Wyant, III F diff --git a/.github/workflows/make.PL b/.github/workflows/make.PL new file mode 100644 index 00000000..f8d6ca56 --- /dev/null +++ b/.github/workflows/make.PL @@ -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 of C<$Config{make}>, passing +it all its arguments. + +=head1 AUTHOR + +Thomas R. Wyant, III F + +=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 :