diff --git a/build/api/module/authentification.php b/build/api/module/authentification.php deleted file mode 100644 index d52d21a..0000000 --- a/build/api/module/authentification.php +++ /dev/null @@ -1,32 +0,0 @@ - New hash - * - */ - public static function renew($args){ - extract($args); - - /* (1) Fetch cyclic-hashing-system -> check file */ - $fn = __BUILD__.'/api/chs/hash'; - - if( !is_file($fn) ) - return ['ModuleError'=>Error::UnreachableResource]; - - /* (2) Stores new hash */ - file_put_contents($fn, $hash); - - - return []; - } - - } diff --git a/build/api/module/release.php b/build/api/module/release.php index 48de7f8..506e988 100755 --- a/build/api/module/release.php +++ b/build/api/module/release.php @@ -7,58 +7,80 @@ class release{ - /* PULLS A BRANCH FROM GIT + /* Releases a project * - * @project Project's name - * @branch Git branch + * @project Project's name + * @step [OPT] Step to run * */ - public static function pull($args){ + public function post($args){ extract($args); - /* [1] Load projects' configuration - =========================================================*/ + /* (1) Load projects' configuration + ---------------------------------------------------------*/ /* (1) Fetch file */ $fc = file_get_contents(__CONFIG__.'/projects.json'); if( !$fc ) - return ['ModuleError'=>Error::UnreachableResource]; + return [ 'error' => new Error(Err::UnreachableResource) ]; /* (2) Checks json format */ $js = json_decode( $fc, true ); if( !$js ) - return ['ModuleError'=>Error::ParsingFailed]; + return [ 'error' => new Error(Err::ParsingFailed) ]; - /* [2] Checks @project argument and files - =========================================================*/ + /* (2) Checks @project argument and files + ---------------------------------------------------------*/ /* (1) Checks @project */ if( !isset($js[$project]) ) - return ['ModuleError'=>Error::UnreachableResource]; + return [ 'error' => new Error(Err::UnreachableResource) ]; /* (2) Checks @project's folder */ - if( !is_dir($js[$project]['git']) ) - return ['ModuleError'=>Error::UnreachableResource]; + if( !is_dir($js[$project]['dir']) ) + return [ 'error' => new Error(Err::UnreachableResource) ]; /* (3) Checks @git directory */ - if( !is_dir($js[$project]['git'].'/.git') ) - return ['ModuleError'=>Error::UnreachableResource]; + if( !is_dir($js[$project]['dir']) ) + return [ 'error' => new Error(Err::UnreachableResource) ]; - /* [3] Launch script - =========================================================*/ - /* (1) Launch command + test */ - $cmd = 'cd '.$js[$project]['git'].'; git pull origin '.$branch.';'; - $stdout = shell_exec($cmd); + /* (3) Launch script + ---------------------------------------------------------*/ + /* (1) 'cd' to project dir */ + chdir($js[$project]['dir']); - /* (2) If error, raise error */ - if( is_null($stdout) ) - return ['ModuleError'=>Error::PermissionError, 'command'=>$cmd]; + /* (2) If given step, only do this one */ + if( !is_null($step) ){ + /* (2.1) If step does not exist */ + if( !isset($js[$project]['cmd'][$step]) ) + return [ 'error' => new Error(Err::ModuleError, 'step out of bounds') ]; + + /* (2.2) Execute step */ + exec($js[$project]['cmd'][$step], $stdout); + + /* (2.3) Dispatch output */ + return [ $js[$project]['cmd'][$step] => $stdout ]; + + } + + /* (3) Execute each step one by one */ + $stdout = []; + + foreach($js[$project]['cmd'] as $step=>$cmd){ + + /* (3.1) Pre-create stdout */ + $stdout[$cmd] = ''; + + /* (3.2) Execute step */ + exec($cmd, $stdout[$cmd]); + + } + + /* (4) Dispatch stdout */ + return [ 'stdout' => $stdout ]; - /* [4] Return success error - =========================================================*/ - return []; } } diff --git a/config/modules.json b/config/modules.json index 1413009..3b171d9 100755 --- a/config/modules.json +++ b/config/modules.json @@ -52,15 +52,17 @@ }, - "release/pull": { + "release": { "POST": { + "description": "Pulls project from git branch.", - "permissions": ["cyclic-hash"], + "permissions": [["admin"]], "parameters": { - "project": { "description": "Project's name.", "type": "varchar(2,30,alphanumeric)" }, - "branch": { "description": "Git release branch.", "type": "varchar(2,30,alphanumeric)" } + "URL0": { "description": "Name of the project to release", "type": "alphanumeric", "rename": "project" }, + "URL1": { "description": "Step to run, if not given, all steps will be run", "type": "id", "rename": "step" } } + } } } diff --git a/config/projects.json b/config/projects.json index ab48f12..6f43d59 100755 --- a/config/projects.json +++ b/config/projects.json @@ -1,5 +1,11 @@ { + "prod-releaser": { + "dir": "/vhost/prod-releaser", + "cmd" : [ + "git pull origin master" + ] + }, "ndli1718": { "dir": "/vhost/ndli1718", "cmd" : [