GitHub::Actions - Work in GitHub Actions using Perl
This document describes GitHub::Actions version 0.1.1.1
use GitHub::Actions; use v5.14; # Imported %github contains all GITHUB_* environment variables for my $g (keys %github ) { say "GITHUB_$g -> ", $github{$g} } # Set step output set_output("FOO", "BAR"); # Set environment variable value set_env("FOO", "BAR"); # Produces an error and sets exit code to 1 error( "FOO has happened" ); # Error/warning with information on file error_on_file( "There's foo", $file, $line, $col ); warning_on_file( "There's bar", $file, $line, $col ); # Debugging messages and warnings debug( "Value of FOO is $bar" ); warning( "Value of FOO is $bar" ); # Start and end group start_group( "Foo" ); # do stuff end_group; # Exits with error if that's the case exit_action(); # Errors and exits set_failed( "We're doomed" );
Install this module within a GitHub action
. name: "Install GitHub::Actions" run: sudo cpan GitHub::Actions
(we need sudo since we're using the system Perl)
sudo
You can use this as a step
step
- name: Test env variables shell: perl {0} run: | use GitHub::Actions; set_env( 'FOO', 'BAR');
In most cases, you'll want to just have it installed locally and fatpack it to upload it to the repository.
GitHub Actions include by default, at least in its Linux runners, a system Perl which you can use directly in your GitHub actions. This here is a (for the time being) minimalistic module that tries to help a bit with that, by defining a few functions that will be useful when performing GitHub actions. Besides the system Perl, you can use any of the modules installed. You can install other modules via cpan or, preferably for speed, via the Ubuntu package (or equivalent)
Check out an example of using it in the repository
This is equivalent to setting an environment variable
Equivalent to set_output
set_output
Equivalent to debug
debug
Equivalent to error, prints an error message. Remember to call exit_action() to make the step fail if there's been some error.
error
Equivalent to warning, simply prints a warning.
warning
Common code for error_on_file and warning_on_file. Can be used for any future commands.
Equivalent to error, prints an error message with file and line info
Equivalent to warning, prints an warning with file and line info.
Exits with an error status of 1 after setting the error message.
Starts a group in the logs, grouping the following messages. Corresponds to group.
group
Ends current log grouping.
Exits with the exit code generated during run, that is, 1 if there's been any error reported.
GitHub::Actions requires no configuration files or environment variables. Those set by GitHub Actions will only be available there, or if you set them explicitly. Remember that they will need to be set during the BEGIN phase to be available when this module loads.
BEGIN
BEGIN { $ENV{'GITHUB_FOO'} = 'foo'; $ENV{'GITHUB_BAR'} = 'bar'; }
Intentionally, no dependencies are included.
None reported.
No bugs have been reported.
Please report any bugs or feature requests to https://github.com/JJ/perl-GitHub-Actions/issues.
JJ Merelo <jmerelo@CPAN.org>. Many thanks to RENEEB and Gabor Szabo for their help with test and metadata.
<jmerelo@CPAN.org>
Copyright (c) 2021, JJ Merelo <jmerelo@CPAN.org>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
To install GitHub::Actions, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GitHub::Actions
CPAN shell
perl -MCPAN -e shell install GitHub::Actions
For more information on module installation, please visit the detailed CPAN module installation guide.