This commit is contained in:
Varun 2020-10-21 13:51:40 +05:30
parent 5bfdab47a9
commit bf09647d53
No known key found for this signature in database
GPG key ID: 93FB46DCF16E0D6F
3 changed files with 59 additions and 3 deletions

View file

@ -61,5 +61,19 @@ gh_log( gh_input( 'VALUE1' ) );
gh_log( gh_input( 'VALUE2' ) );
gh_log( gh_input( 'VALUE3' ) );
gh_log( gh_input( 'VALUE4', 'DEFAULT_VALUE' ) );
gh_validate_input( 'VALUE5', 'Sorry Can\'t Process VALUE5 Input Is Required' );
gh_validate_input( 'VALUE6' );
#gh_validate_input( 'VALUE5', 'Sorry Can\'t Process VALUE5 Input Is Required' );
#gh_validate_input( 'VALUE6' );
# Sets A New ENV Variable And Logs A Success Message
gh_set_env( "ENV_VAR_NAME", "ENV_VAR_CONTENT" );
gh_set_env( "ENV_VAR_NAME2", "ENV_VAR_CONTENT" );
# Sets A New ENV Variable And No Log Will Be Generated
gh_set_env_silent( "ENV_VAR_NAME3", "Custom Content Here" );
# Sets A New ENV Variable Which Will have Multiple Lines Of String
gh_set_env_multiline( "VARIABLE_NAME", "Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." );

View file

@ -2,4 +2,5 @@
require_once __DIR__ . '/php/logger.php';
require_once __DIR__ . '/php/log-functions.php';
require_once __DIR__ . '/php/inputvar.php';
require_once __DIR__ . '/php/inputvar.php';
require_once __DIR__ . '/php/env.php';

41
toolkit/php/env.php Normal file
View file

@ -0,0 +1,41 @@
<?php
function gh_env( $key, $default = null ) {
if ( isset( $_ENV[ $key ] ) ) {
return $_ENV[ $key ];
}
return $default;
}
function gh_validate_env( $key, $custom_message ) {
if ( null === gh_env( $key ) ) {
$custom_message = ( false === $custom_message ) ? '%s Not Found. Please Set It As ENV Variable' : $custom_message;
$custom_message = sprintf( $custom_message, $key );
$custom_message = '🚩 ' . $custom_message;
gh_log_red( $custom_message );
exit;
}
return gh_env( $key );
}
function gh_set_env_multiline( $key, $value, $silent = false ) {
echo 'echo "' . $key . '<<EOF" >> $GITHUB_ENV';
echo 'echo "' . addslashes( $value ) . '" >> $GITHUB_ENV';
echo 'echo "EOF" >> $GITHUB_ENV';
if ( ! $silent ) {
gh_log( "✔️ ENV : ${key} => ${value}" );
}
}
function gh_set_env( $key, $value, $silent = false ) {
echo 'echo "' . $key . '=' . $value . '" >> $GITHUB_ENV';
if ( ! $silent ) {
gh_log( "✔️ ENV : ${key} => ${value}" );
}
}
function gh_set_env_silent( $key, $value ) {
gh_set_env( $key, $value, true );
}