How to set and get PERL5LIB environment variables on Github Action.
Linux, Mac
- name: Set PERL5LIB
run: echo "PERL5LIB=$HOME/mylib/lib/perl5:$HOME/mylib/lib/perl5/$(perl -MConfig -e 'print $Config{archname}')" >> $GITHUB_ENV
- name: Show PERL5LIB
run: echo $PERL5LIB
An example:
name: linux-ubuntu-latest
on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Perl version
run: perl -V
- name: Perl config
run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
- name: Set PERL5LIB
run: echo "PERL5LIB=$HOME/mylib/lib/perl5:$HOME/mylib/lib/perl5/$(perl -MConfig -e 'print $Config{archname}')" >> $GITHUB_ENV
- name: Show PERL5LIB
run: echo $PERL5LIB
- name: Download cpanm
run: perl -0777 -Mstrict -Mwarnings -MIO::Socket::INET -e 'my $socket = IO::Socket::INET->new( Proto => qq(tcp), PeerAddr => qq(cpanmin.us), PeerPort => 80,) or die $!;print $socket join qq(\r\n), qq(GET / HTTP/1.1), qq(Connection:close), qq(Host:cpanmin.us), qq(\r\n);my $res = <$socket>;$res =~ s[^HTTP/1\.1 200 OK\r\n.*?\r\n\r\n][]s or die $res;open my $out, qq(>), qq(cpanm) or die $!;print $out $res'
- name: cpanm installs dependent modules
run: perl cpanm -v -n -L ~/mylib --installdeps . --configure-args="--meta"
- run: perl Makefile.PL
- run: make
- run: make disttest
Windows/pwsh
- name: Set PERL5LIB
run: echo "PERL5LIB=$HOME/mylib/lib/perl5;$HOME/mylib/lib/perl5/$(perl -MConfig -e 'print $Config{archname}')" >> $env:GITHUB_ENV
- name: Show PERL5LIB
run: echo $env:PERL5LIB
An example:
name: windows-2019
on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:
jobs:
perl:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- name: Perl version
run: perl -V
- name: Perl config
run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
- name: Set PERL5LIB
run: echo "PERL5LIB=$HOME/mylib/lib/perl5;$HOME/mylib/lib/perl5/$(perl -MConfig -e 'print $Config{archname}')" >> $env:GITHUB_ENV
- name: Show PERL5LIB
run: echo $env:PERL5LIB
- name: Download cpanm
run: perl -0777 -Mstrict -Mwarnings -MIO::Socket::INET -e 'my $socket = IO::Socket::INET->new( Proto => qq(tcp), PeerAddr => qq(cpanmin.us), PeerPort => 80,) or die $!;print $socket join qq(\r\n), qq(GET / HTTP/1.1), qq(Connection:close), qq(Host:cpanmin.us), qq(\r\n);my $res = <$socket>;$res =~ s[^HTTP/1\.1 200 OK\r\n.*?\r\n\r\n][]s or die $res;open my $out, qq(>), qq(cpanm) or die $!;print $out $res'
- name: cpanm installs dependent modules
run: perl cpanm -v -n -L ~/mylib --installdeps . --configure-args="--meta"
- run: perl Makefile.PL
- run: gmake
- run: gmake disttest
Note
Set a environment variable.
# Linux, Mac
echo "PERL5LIB=Foo" >> $GITHUB_ENV
# Linux, Mac
echo "PERL5LIB=Foo" >> $env:GITHUB_ENV
Get a environment variable.
# Linux, Mac
echo $PERL5LIB
# Windows
echo $env:PERL5LIB
This is needed to be shown at the next Crun
Path separator is :
on Linux, Mac, ;
on Windows.
For Beginners
PERL5LIB
environment variable is the path that Perl search for modules.
Top comments (4)
Why not use the
env
key?What is the
env
key?Is it means the following?
Or
the latter
The reason is PERL5LIB environment variable must be set dynamically using
$Config{archname}
insteps
.In this case, it looks like the syntax of
bash
orpwsh
must be used.About environment variables
docs.github.com/en/actions/learn-g...