Compare commits

...

7 Commits

Author SHA1 Message Date
Pavel Shevaev 0d084aa072 Добавить CHANGELOG.md 2024-07-23 14:30:48 +03:00
Pavel Shevaev 762cfe2b2d Adding support for environment variables specified with .env root file
Publish PHP Package / docker (push) Successful in 6s Details
2024-07-23 14:23:04 +03:00
Pavel Shevaev 9a8e6ceb11 Добавить .gitea/workflows/build_composer.yaml
Publish PHP Package / docker (push) Successful in 5s Details
2024-02-13 12:33:24 +03:00
Pavel Shevaev 7de74415df Missing environments are now reported 2023-10-25 20:28:20 +03:00
Pavel Shevaev 2bcda8e7d5 Изменил(а) на 'composer.json' 2023-10-24 18:22:11 +03:00
Pavel Shevaev cbe3401086 Tweaking composer autoload 2023-10-24 17:36:47 +03:00
Pavel Shevaev 910b4fffdb Fixing typo 2022-07-21 11:01:12 +03:00
5 changed files with 81 additions and 14 deletions

View File

@ -0,0 +1,31 @@
name: Publish PHP Package
on:
push:
tags:
- 'v*'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get tag name
run: echo "TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: zip and send
run: |
ls -la
apt-get update -y
apt-get install -y zip
cd ../
zip -r ${{ gitea.event.repository.name }}.zip ${{ gitea.event.repository.name }} -x '*.git*'
curl -v \
--user composer-pbl:${{ secrets.COMPOSER_PSWD }} \
--upload-file ${{ gitea.event.repository.name }}.zip \
https://git.bit5.ru/api/packages/bit/composer?version=${{ env.TAG }}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tags

2
CHANGELOG.md Normal file
View File

@ -0,0 +1,2 @@
## v1.1.0
- Adding support for root directory .env file which is used to set environment variables

View File

@ -4,8 +4,5 @@
"homepage": "https://git.bit5.ru/composer/taskman_env",
"require": {
"php": ">=7.4"
},
"autoload": {
"classmap": ["env.inc.php"]
}
}

View File

@ -7,20 +7,27 @@ $GLOBALS['TASKMAN_ROOT_ENV_NAME'] = 'gamectl.props.php';
task('envs', function()
{
global $GAME_ROOT;
$dir = $GAME_ROOT."/env/";
$dir = normalize_path($GAME_ROOT."/env/", true);
echo "=== Available envs ===\n";
$results = scan_files_rec(array($dir), array(".props.php"));
foreach($results as $file)
echo str_replace(".props.php", "", str_replace($dir, "", $file)) . "\n";
{
$file = str_replace($dir, '', normalize_path($file, true));
$file = str_replace(".props.php", '', $file);
$file = ltrim($file, '/');
echo $file . "\n";
}
});
function put_env(&$argv)
{
global $GAME_ROOT;
_set_env_vars_from_file();
$env = '';
$filtered = array();
for($i=0;$i<sizeof($argv);++$i)
@ -48,6 +55,37 @@ function put_env(&$argv)
putenv("GAME_ENV=");
}
function _set_env_vars_from_file()
{
global $GAME_ROOT;
if(!file_exists($GAME_ROOT . '/.env'))
return;
$var_arrs = array();
$lines = file($GAME_ROOT . '/.env');
foreach($lines as $line)
{
$line = trim($line);
$line_is_comment = (substr(trim($line),0 , 1) == '#') ? true: false;
if($line_is_comment || empty(trim($line)))
continue;
// Split the line variable and succeeding comment on line if exists
$line_no_comment = explode("#", $line, 2)[0];
// Split the variable name and value
$env_ex = preg_split('/(\s?)\=(\s?)/', $line_no_comment);
$env_name = trim($env_ex[0]);
$env_value = isset($env_ex[1]) ? trim($env_ex[1]) : "";
$var_arrs[$env_name] = $env_value;
}
foreach($var_arrs as $k => $v)
putenv("$k=$v");
}
function set_root_env_name($root_name)
{
$GLOBALS['TASKMAN_ROOT_ENV_NAME'] = $root_name;
@ -63,12 +101,9 @@ function include_env()
global $GAME_ROOT;
$env_filename = get_env_file();
$root_env = get_root_env_name();
if($env_filename && !file_exists($env_filename))
throw new Exception("Error setting environment. No such env file $env_filename");
else if($env_filename === null && file_exists("$GAME_ROOT/$root_env"))
$env_filename = "$GAME_ROOT/$root_env";
throw new Exception("No env file '$env_filename'");
if($env_filename)
include($env_filename);
@ -83,13 +118,14 @@ function get_env_file()
$env = getenv("GAME_ENV");
if($env)
{
$env_filename = "$GAME_ROOT/env/$env.props.php";
else
$env_filename = "$GAME_ROOT/" . get_root_env_props_name();
if(file_exists($env_filename))
return $env_filename;
}
//checking optional env.file
$env_filename = "$GAME_ROOT/" . get_root_env_name();
return null;
return file_exists($env_filename) ? $env_filename : null;
}