Compare commits

...

23 Commits

Author SHA1 Message Date
Alexey Chubar 54694eaed0 Edited changelog
Publish PHP Package / docker (push) Successful in 6s Details
2025-03-13 19:46:05 +07:00
Alexey Chubar c4be07e36e Edited changelog 2025-03-13 19:32:09 +07:00
Alexey Chubar d73f06fec8 Added unity helper method 2025-03-13 19:07:33 +07:00
Alexey Chubar 5ae5b81992 guess_unity_app_dir fix for linux
Publish PHP Package / docker (push) Successful in 7s Details
2025-03-11 15:57:47 +07:00
Alexey Chubar eebc83e8a7 Added a low-level task for unity_batch_exec
Publish PHP Package / docker (push) Successful in 6s Details
2024-10-14 12:58:06 +03:00
wrenge 2b11b6724b Linux build fix
Publish PHP Package / docker (push) Successful in 6s Details
2024-09-17 17:34:51 +03:00
Pavel Shevaev 08b65dd720 Добавить .gitea/workflows/build_composer.yaml
Publish PHP Package / docker (push) Successful in 6s Details
2024-02-13 14:46:35 +03:00
Pavel Shevaev 113d64a8db Изменил(а) на 'composer.json' 2023-10-24 18:26:20 +03:00
Pavel Shevaev f72fb3ca5a Tweaking composer autoload 2023-10-24 17:33:23 +03:00
Pavel Shevaev 7c47baa66b Making PHPStan happy 2023-08-16 14:06:32 +03:00
wrenge 62567e2d40 unity task linux support 2023-07-06 22:19:58 +03:00
wrenge bb0d8129f1 Linux support 2023-07-06 21:46:00 +03:00
Pavel Shevaev c32d6ba9ec Merge branch 'master' of https://git.bit5.ru/bit/taskman_unity 2023-04-14 11:35:45 +03:00
Pavel Shevaev f6c8b2d723 Make Unity app dir guess error more informative 2023-04-14 11:34:45 +03:00
Pavel Shevaev 9d9c46a8ef Making unity_exec(..) more robust and reliable 2023-03-21 18:39:27 +03:00
Pavel Shevaev c632553277 Experimenting with more robust Unity build error detection which actually shows the real build error 2023-01-16 16:57:28 +03:00
wrenge b8f812dd99 Changelog 2022-08-09 11:02:41 +03:00
wrenge 0e520b02fd Unity task fix 2022-08-09 11:02:35 +03:00
wrenge b010f75d67 Fixed build project path 2022-06-01 15:01:42 +03:00
wrenge f08896a5a2 Added changelog :D 2022-05-31 15:53:08 +03:00
a.samsonkin ccff99e4d8 Added quotes to path 2022-05-31 15:28:32 +03:00
a.samsonkin 9ea2c02dc7 Fixed unity task 2022-05-31 15:08:31 +03:00
Pavel Shevaev 07100f700d Adding more stuff 2022-05-19 18:50:30 +03:00
5 changed files with 311 additions and 41 deletions

View File

@ -0,0 +1,29 @@
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

24
CHANGELOG.md Normal file
View File

@ -0,0 +1,24 @@
# Change Log
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.0.21] - 2025-03-13
### Fixed
- Added helper methods, fixed Linux
## [1.0.5] - 2022-08-09
### Fixed
- Unity task on windows not working
## [1.0.4] - 2022-06-01
### Fixed
- Fixed build project path
## [1.0.3] - 2022-05-31
### Added
- A changelog. Cuz why not? :D
### Fixed
- Task unity now uses proper folder from propery

View File

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

View File

@ -5,39 +5,35 @@ use Exception;
task('unity', function() task('unity', function()
{ {
$unity_path = guess_unity_app_dir(); $unity_path = guess_unity_app_dir();
$proj_path = normalize_path(get("UNITY_ASSETS_DIR") . '/../');
if(is_win()) if(is_win())
{ {
$unity_app_path = "'$unity_path/Editor/Unity.exe'"; $unity_app_path = "'$unity_path/Editor/Unity.exe'";
run_background_proc($unity_app_path, ['-projectPath', '.']); run_background_proc($unity_app_path, ['-projectPath', "$proj_path"]);
}
else if(is_linux())
{
$unity_path = get('UNITY_APP_DIR');
$unity_app_path = "'$unity_path/Editor/Unity'";
run_background_proc($unity_app_path, ['-projectPath', "$proj_path"]);
} }
else else
{ {
$cmd = guess_unity_app_dir()."'Unity.app/Contents/MacOS/Unity' -projectPath . > /dev/null 2>&1&"; $cmd = guess_unity_app_dir()."'Unity.app/Contents/MacOS/Unity' -projectPath '$proj_path' > /dev/null 2>&1&";
system($cmd, $res); system($cmd, $res);
} }
}); });
task('unity_kill', function() task('unity_kill', function()
{ {
$proc_id = unity_find_proc_id(); unity_kill();
if($proc_id)
{
echo "Found Unity process '$proc_id', killing it...\n";
system("kill -9 $proc_id");
sleep(5);
}
else
{
echo "No Unity process found to kill\n";
}
}); });
function unity_exec($func, $build_target = "", $quit = true, $batchmode = true) function unity_exec($func, $build_target = "", $quit = true, $batchmode = true)
{ {
global $GAME_ROOT; global $GAME_ROOT;
$proj_path = normalize_path("$GAME_ROOT/"); $proj_path = normalize_path(get("UNITY_ASSETS_DIR") . '/../');
$log_file = "$GAME_ROOT/build/unity.log"; $log_file = "$GAME_ROOT/build/unity.log";
ensure_rm($log_file); ensure_rm($log_file);
@ -67,33 +63,57 @@ function unity_exec($func, $build_target = "", $quit = true, $batchmode = true)
return array($log_file, $pid); return array($log_file, $pid);
} }
function unity_batch_exec($func, $build_target = "", $notify = true) function unity_batch_exec($func, $build_target = "")
{ {
global $GAME_ROOT; global $GAME_ROOT;
try unity_kill();
{
list($log_file, $pid) = unity_exec($func, $build_target, /*$quit = */ true, /*$batchmode = */ true);
watch_running_process($pid, $log_file, list($log_file, $pid) = unity_exec($func, $build_target, /*$quit = */ true, /*$batchmode = */ true);
array(
'Exiting batchmode successfully' watch_running_process(
), $pid,
array( $log_file,
'UnityException:', array(
'Aborting batchmode due to failure', 'Exiting batchmode successfully',
'Launching bug reporter', 'Batchmode quit successfully invoked - shutting down!'
),
array(
'Build Finished, Result: Failure',
'UnityException:',
'Aborting batchmode due to failure',
'Launching bug reporter',
'Unrecognized assets cannot be included in AssetBundles:'
),
true,
-1,
//ignored errors:
array(
//NOTE: weird editor crash, sometimes happens on exit after batch task is actually done
// seems like it's never been fixed though issue tracker says otherwise (https://vk.cc/bYpyUS)
"Fatal Error! GetManagerFromContext: pointer to object of manager 'MonoManager' is NULL (table index 5)"
),
//noted warnings: they don't abort execution but show up at the end of the log if command fails
array(
': error CS', ': error CS',
'Unrecognized assets cannot be included in AssetBundles:' )
) );
);
}
catch(Exception $e)
{
throw $e;
}
} }
task('unity_batch_exec', function(array $args)
{
if(count($args) != 2)
{
echo "Usage: gamectl unity_batch_exec <method name> <platform>\n";
return;
}
$func = $args[0];
$platform = $args[1];
unity_batch_exec($func, $platform);
});
function unity_run_proc($shared_cmd) function unity_run_proc($shared_cmd)
{ {
$app_dir = get('UNITY_APP_DIR'); $app_dir = get('UNITY_APP_DIR');
@ -104,6 +124,10 @@ function unity_run_proc($shared_cmd)
$unity_app_path = $app_dir . "Editor/Unity.exe"; $unity_app_path = $app_dir . "Editor/Unity.exe";
$cmd = "powershell.exe (Start-Process '$unity_app_path'-ArgumentList '$shared_cmd' -passthru).Id"; $cmd = "powershell.exe (Start-Process '$unity_app_path'-ArgumentList '$shared_cmd' -passthru).Id";
} }
else if(is_linux())
{
$cmd = "'$app_dir/Editor/Unity' $shared_cmd > /dev/null & echo $!";
}
else else
{ {
$cmd = "'$app_dir/Unity.app/Contents/MacOS/Unity' $shared_cmd > /dev/null & echo $!"; $cmd = "'$app_dir/Unity.app/Contents/MacOS/Unity' $shared_cmd > /dev/null & echo $!";
@ -115,6 +139,19 @@ function unity_run_proc($shared_cmd)
return trim($out[0]); return trim($out[0]);
} }
function unity_kill()
{
$proc_id = unity_find_proc_id();
if($proc_id)
{
echo "Found Unity process '$proc_id', killing it...\n";
system("kill -9 $proc_id");
sleep(5);
}
else
echo "No Unity process found to kill\n";
}
function unity_find_proc_id() function unity_find_proc_id()
{ {
global $GAME_ROOT; global $GAME_ROOT;
@ -138,13 +175,14 @@ function guess_unity_app_dir()
$path = "/Applications/Unity/"; $path = "/Applications/Unity/";
if(is_win()) if(is_win())
$path = getenv("ProgramFiles")."/Unity/"; $path = getenv("ProgramFiles")."/Unity/";
else if(is_linux())
$path = getenv("HOME")."/Unity/";
$proj_version_file = $GAME_ROOT.'/unity/ProjectSettings/ProjectVersion.txt'; $proj_version_file = $GAME_ROOT.'/unity/ProjectSettings/ProjectVersion.txt';
if(is_file($proj_version_file)) if(is_file($proj_version_file))
{ {
list($_, $unity_version) = array_map('trim', explode(":", file($proj_version_file)[0])); list($_, $unity_version) = array_map('trim', explode(":", file($proj_version_file)[0]));
if(is_dir("{$path}Hub/Editor/$unity_version/")) $path .= "Hub/Editor/$unity_version/";
$path .= "Hub/Editor/$unity_version/";
} }
return $path; return $path;
} }
@ -153,9 +191,190 @@ function get_unity_dir()
{ {
$app_dir = get('UNITY_APP_DIR'); $app_dir = get('UNITY_APP_DIR');
if(is_win()) if(is_win() || is_linux())
return "$app_dir/Editor/Data"; return "$app_dir/Editor/Data";
else else
return "$app_dir/Unity.app/Contents/"; return "$app_dir/Unity.app/Contents/";
} }
function unity_build_cmd($shared_cmd)
{
$app_dir = get('UNITY_APP_DIR');
if(is_win())
$cmd = "\"$app_dir/Editor/Unity.exe\" $shared_cmd";
else if(is_linux())
$cmd = "\"$app_dir/Editor/Unity\" $shared_cmd";
else
$cmd = "$app_dir/Unity.app/Contents/MacOS/Unity $shared_cmd";
return $cmd;
}
function mono_mcs_bin()
{
if(!get("USE_UNITY_MONO"))
return 'mcs';
$unity_dir = get_unity_dir();
if(!is_dir($unity_dir))
throw new Exception("Unity directory doesn't exist: $unity_dir");
$canidates = array(
"$unity_dir/Mono/bin/gmcs",
"$unity_dir/MonoBleedingEdge/bin/mcs",
"$unity_dir/Frameworks/Mono/bin/gmcs",
"$unity_dir/Mono/bin/gmcs",
);
foreach($canidates as $mcs_bin)
{
if(is_file($mcs_bin))
{
if(is_win())
return '"' . normalize_path($mcs_bin, false) . '"';
else
return $mcs_bin;
}
}
throw new Exception("Mono compiler binary not found");
}
function mono_try_override_path()
{
if(!get("USE_UNITY_MONO"))
return '';
$mono_dir = dirname(trim(mono_mcs_bin(), '"'));
$prev_path = getenv('PATH');
echo "UNITY MONO PATH=$mono_dir\n";
putenv("PATH=$mono_dir".(is_win() ? ";" : ":")."$prev_path");
return $prev_path;
}
function mono_try_restore_path($prev_path)
{
if(!get("USE_UNITY_MONO"))
return;
putenv("PATH=$prev_path");
}
function build_mono_dll($src_spec, $out_file, $ref_dlls = array(), $mcs_opts = "")
{
build_mono($src_spec, $out_file, $ref_dlls, "$mcs_opts -target:library");
}
function build_mono($src_spec, $out_file, $ref_dlls = array(), $mcs_opts = "")
{
global $GAME_ROOT;
$unity_dir = get_unity_dir();
$mcs_bin = mono_mcs_bin();
if(is_array($src_spec))
$sources = $src_spec;
else if(is_dir($src_spec))
$sources = scan_files_rec(array($src_spec), array('.cs'));
else
$sources = glob($src_spec);
$sources_str = '';
foreach($sources as $src)
{
if(is_win())
$sources_str .= '"'.normalize_path($src).'" ';
else
$sources_str .= '\''.normalize_path($src).'\' ';
}
$deps = $sources;
$refs_str = "";
foreach($ref_dlls as $ref_dll)
{
if($ref_dll === "UnityEngine.dll")
{
$ref_dll = "$unity_dir/Managed/UnityEngine.dll";
if(!is_file($ref_dll))
$ref_dll = "$unity_dir/Frameworks/Managed/UnityEngine.dll";
}
$ref_dll = normalize_path($ref_dll, !is_win());
$refs_str .= "-r:\"$ref_dll\" ";
$deps[] = $ref_dll;
}
$out_file = normalize_path($out_file, !is_win());
$cmd = "$mcs_bin $mcs_opts $refs_str -out:$out_file $sources_str";
if(is_string($src_spec) && is_dir($src_spec))
$cmd = "cd $src_spec && $cmd";
$cmd_hash = crc32($cmd);
$cmd_hash_file = "$GAME_ROOT/build/" . crc32($out_file) . ".mhash";
if(!is_file($cmd_hash_file) || file_get_contents($cmd_hash_file) != "$cmd_hash")
file_put_contents($cmd_hash_file, "$cmd_hash");
$deps[] = $cmd_hash_file;
if(need_to_regen($out_file, $deps))
{
ensure_mkdir(dirname($out_file));
shell($cmd);
echo "> $out_file " . round(filesize($out_file)/1024, 2) . "kb\n";
}
}
function run_mono($exe_file)
{
$app_dir = get('UNITY_APP_DIR');
if(is_win())
{
$unity_dir = "$app_dir/Editor/Data";
$mono_bin = '"' . normalize_path("$unity_dir/Mono/bin/mono") . '"';
}
else
{
$unity_dir = "$app_dir/Unity.app/Contents/";
if(is_dir("$unity_dir/Frameworks/Mono"))
$mono_bin = "$unity_dir/Frameworks/Mono/bin/mono";
else
$mono_bin = "$unity_dir/Mono/bin/mono";
}
$exe_file = normalize_path($exe_file, !is_win());
$mono_path = realpath(dirname($mono_bin) . '/../lib/mono/unity');
putenv("MONO_PATH=$mono_path");
$cmd = "$mono_bin $exe_file";
shell($cmd);
}
function build_option_exists($option)
{
return strpos(getor("BUILD_CLIENT_OPTS", ""), $option) !== FALSE;
}
function build_option_add($option)
{
if(build_option_exists($option))
return;
$propname = "BUILD_CLIENT_OPTS";
$opts = getor($propname, "");
if(strlen($opts) > 0)
$opts .= ",$option";
else
$opts = $option;
set($propname, $opts);
}
function is_gradle_project_export()
{
return build_option_exists("AcceptExternalModificationsToPlayer");
}