From a54f3f73456e6ecc681dd0d6342b5d3083eb0c0b Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 17 Feb 2018 19:01:17 +0100 Subject: [PATCH] +add prod-releaser --- build/api/module/release.php | 87 +++++++++++++++++++ config/modules.json | 158 +++++++++++++++++++---------------- config/projects.json | 17 ++++ 3 files changed, 189 insertions(+), 73 deletions(-) create mode 100644 build/api/module/release.php create mode 100755 config/projects.json diff --git a/build/api/module/release.php b/build/api/module/release.php new file mode 100644 index 0000000..204b040 --- /dev/null +++ b/build/api/module/release.php @@ -0,0 +1,87 @@ + Project's name + * @step [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 ]; + + } + + } diff --git a/config/modules.json b/config/modules.json index c79936b..3f64396 100644 --- a/config/modules.json +++ b/config/modules.json @@ -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" } - } - }, - - "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" } + "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": {} } } -} +} \ No newline at end of file diff --git a/config/projects.json b/config/projects.json new file mode 100755 index 0000000..96e9732 --- /dev/null +++ b/config/projects.json @@ -0,0 +1,17 @@ +{ + + "web": { + "dir": "/vhost", + "cmd" : [ + "git pull origin master", + "npm run build" + ] + }, + "env": { + "dir": "/env", + "cmd" : [ + "rm restart.trigger" + ] + } + +}