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{
/* PULLS A BRANCH FROM GIT
/* Releases a project
*
* @project<String> Project's name
* @branch<String> Git branch
* @project<String> Project's name
* @step<id> [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 [];
}
}

View File

@ -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" }
}
}
}
}

View File

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