release script

This commit is contained in:
xdrm-brackets 2017-12-10 23:20:06 +01:00
parent da5d4bab74
commit 4a7d07546c
4 changed files with 60 additions and 62 deletions

View File

@ -1,32 +0,0 @@
<?php
namespace api\module;
use \error\core\Error;
class authentification{
/* RENEW CYCLING HASH
*
* @hash<String> 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 [];
}
}

View File

@ -7,58 +7,80 @@
class release{ class release{
/* PULLS A BRANCH FROM GIT /* Releases a project
* *
* @project<String> Project's name * @project<String> Project's name
* @branch<String> Git branch * @step<id> [OPT] Step to run
* *
*/ */
public static function pull($args){ public function post($args){
extract($args); extract($args);
/* [1] Load projects' configuration /* (1) Load projects' configuration
=========================================================*/ ---------------------------------------------------------*/
/* (1) Fetch file */ /* (1) Fetch file */
$fc = file_get_contents(__CONFIG__.'/projects.json'); $fc = file_get_contents(__CONFIG__.'/projects.json');
if( !$fc ) if( !$fc )
return ['ModuleError'=>Error::UnreachableResource]; return [ 'error' => new Error(Err::UnreachableResource) ];
/* (2) Checks json format */ /* (2) Checks json format */
$js = json_decode( $fc, true ); $js = json_decode( $fc, true );
if( !$js ) 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 */ /* (1) Checks @project */
if( !isset($js[$project]) ) if( !isset($js[$project]) )
return ['ModuleError'=>Error::UnreachableResource]; return [ 'error' => new Error(Err::UnreachableResource) ];
/* (2) Checks @project's folder */ /* (2) Checks @project's folder */
if( !is_dir($js[$project]['git']) ) if( !is_dir($js[$project]['dir']) )
return ['ModuleError'=>Error::UnreachableResource]; return [ 'error' => new Error(Err::UnreachableResource) ];
/* (3) Checks @git directory */ /* (3) Checks @git directory */
if( !is_dir($js[$project]['git'].'/.git') ) if( !is_dir($js[$project]['dir']) )
return ['ModuleError'=>Error::UnreachableResource]; return [ 'error' => new Error(Err::UnreachableResource) ];
/* [3] Launch script /* (3) Launch script
=========================================================*/ ---------------------------------------------------------*/
/* (1) Launch command + test */ /* (1) 'cd' to project dir */
$cmd = 'cd '.$js[$project]['git'].'; git pull origin '.$branch.';'; chdir($js[$project]['dir']);
$stdout = shell_exec($cmd);
/* (2) If error, raise error */ /* (2) If given step, only do this one */
if( is_null($stdout) ) if( !is_null($step) ){
return ['ModuleError'=>Error::PermissionError, 'command'=>$cmd];
/* (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 [];
} }
} }

View File

@ -52,15 +52,17 @@
}, },
"release/pull": { "release": {
"POST": { "POST": {
"description": "Pulls project from git branch.", "description": "Pulls project from git branch.",
"permissions": ["cyclic-hash"], "permissions": [["admin"]],
"parameters": { "parameters": {
"project": { "description": "Project's name.", "type": "varchar(2,30,alphanumeric)" }, "URL0": { "description": "Name of the project to release", "type": "alphanumeric", "rename": "project" },
"branch": { "description": "Git release branch.", "type": "varchar(2,30,alphanumeric)" } "URL1": { "description": "Step to run, if not given, all steps will be run", "type": "id", "rename": "step" }
} }
} }
} }
} }

View File

@ -1,5 +1,11 @@
{ {
"prod-releaser": {
"dir": "/vhost/prod-releaser",
"cmd" : [
"git pull origin master"
]
},
"ndli1718": { "ndli1718": {
"dir": "/vhost/ndli1718", "dir": "/vhost/ndli1718",
"cmd" : [ "cmd" : [