+add prod-releaser

This commit is contained in:
xdrm-brackets 2018-02-17 19:01:17 +01:00
parent 9828a67547
commit a54f3f7345
3 changed files with 189 additions and 73 deletions

View File

@ -0,0 +1,87 @@
<?php
namespace api\module;
use \error\core\Error;
use \error\core\Err;
class release{
/* Releases a project
*
* @project<String> Project's name
* @step<id> [OPT] Step to run
*
*/
public function get($args){
extract($args);
/* (1) Load projects' configuration
---------------------------------------------------------*/
/* (1) Fetch file */
$fc = file_get_contents(__CONFIG__.'/projects.json');
if( !$fc )
return [ 'error' => new Error(Err::UnreachableResource) ];
/* (2) Checks json format */
$js = json_decode( $fc, true );
if( !$js )
return [ 'error' => new Error(Err::ParsingFailed) ];
/* (2) Checks @project argument and files
---------------------------------------------------------*/
/* (1) Checks @project */
if( !isset($js[$project]) )
return [ 'error' => new Error(Err::UnreachableResource) ];
/* (2) Checks @project's folder */
if( !is_dir($js[$project]['dir']) )
return [ 'error' => new Error(Err::UnreachableResource) ];
/* (3) Checks @git directory */
if( !is_dir($js[$project]['dir']) )
return [ 'error' => new Error(Err::UnreachableResource) ];
/* (3) Launch script
---------------------------------------------------------*/
/* (1) 'cd' to project dir */
chdir($js[$project]['dir']);
/* (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 [ 'stdout' => [ $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 ];
}
}

View File

@ -1,94 +1,106 @@
{
"GET": {
"des": "Returns the API documentation",
"per": [],
"par": {
"URL0": { "des": "Method name", "typ": "varchar(1,30)", "ren": "method_name", "opt": true, "def": null }
}
},
"article": {
"admin": {
"POST": {
"description": "Posts a new article",
"permissions": ["journalist"],
"parameters": {
"title": { "description": "Article's title", "type": "varchar(5,100)" },
"content": { "description": "Article's content", "type": "text" }
},
"output": {
"created_id": { "description": "Id of the created article", "type": "id" }
}
},
"GET": {
"description": "Gets all or a specific article",
"permissions": ["viewer", "journalist"],
"parameters": {
"URL0": { "description": "Article id", "type": "id", "optional": true, "rename": "id_article" }
},
"output": {
"articles": { "description": "List of selected articles", "type": "array<mixed>" }
}
},
"VIEW": {
"description": "Gets a specific article into a json file (download)",
"permissions": ["viewer", "journalist"],
"options": { "download": true },
"parameters": {
"URL0": { "description": "Article id", "type": "id", "rename": "id_article" }
},
"output": {
"article": { "description": "Selected article as JSON file", "type": "text" }
"des": "Creates a new administrator",
"per": [["admin"]],
"par": {
"username": { "des": "The new administrator username", "typ": "varchar(3,20,alphanumeric)" },
"mail": { "des": "The new administrator email address", "typ": "mail" },
"password": { "des": "The new administrator passowrd", "typ": "text" }
}
},
"PUT": {
"description": "Updates a specific article",
"permissions": ["journalist"],
"parameters": {
"URL0": { "description": "Article id", "type": "id", "rename": "id_article" },
"content": { "description": "Article's content", "type": "text" }
},
"output": {
"article": { "description": "Returns updated article", "type": "array<mixed>" }
"des": "Updates an existing administrator's data",
"per": [["admin"]],
"par": {
"URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "ren": "id_admin" },
"mail": { "des": "The new administrator email address", "typ": "mail", "opt": true },
"password": { "des": "The new administrator passowrd", "typ": "text", "opt": true }
}
},
"DELETE": {
"description": "Deletes a specific article",
"permissions": ["journalist"],
"parameters": {
"URL0": { "description": "Article id", "type": "id", "rename": "id_article" }
},
"output": {}
"des": "Deletes an administrator",
"per": [["admin"]],
"par": {
"URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "opt": true, "ren": "id_admin" }
}
},
"GET": {
"des": "Gets an administrator | Gets all administrators if no id defined",
"per": [["admin"]],
"par": {
"URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "opt": true, "ren": "id_admin" }
}
}
},
"release": {
"encapsuled": {
"url": {
"with": {
"possible": {
"methods": {
"at": {
"GET": {
"each": {
"level": {
"GET": {
"description": "GET /encapsuled/url/with/possible/methods/at/each/level",
"permissions": [],
"parameters": {}
}
}
},
"POST": {
"description": "POST /encapsuled/url/with/possible/methods/at",
"permissions": [],
"parameters": {}
}
}
}
}
"des": "Pulls project from git branch.",
"per": [["admin"]],
"par": {
"URL0": { "des": "Name of the project to release", "typ": "alphanumeric", "ren": "project", "opt": true, "def": "self" },
"URL1": { "des": "Step to run, if not given, all steps will be run", "typ": "id", "ren": "step", "opt": true }
}
}
},
"a": {
"b": {
"c": {
"PUT": {
"des": "PUT A/B/C.",
"per": [],
"par": {}
},
"DELETE": {
"des": "DELETE A/B/C.",
"per": [],
"par": {}
}
},
"PUT": {
"des": "PUT A/B.",
"per": [],
"par": {}
},
"DELETE": {
"des": "DELETE A/B.",
"per": [],
"par": {}
}
},
"GET": {
"des": "GET A.",
"per": [],
"par": {}
},
"POST": {
"des": "POST A.",
"per": [],
"par": {}
}
}
}
}

17
config/projects.json Executable file
View File

@ -0,0 +1,17 @@
{
"web": {
"dir": "/vhost",
"cmd" : [
"git pull origin master",
"npm run build"
]
},
"env": {
"dir": "/env",
"cmd" : [
"rm restart.trigger"
]
}
}