[DEV] add basic system for integration
This commit is contained in:
parent
5acfcc28c7
commit
76459a38b2
42
.htaccess
Normal file
42
.htaccess
Normal file
@ -0,0 +1,42 @@
|
||||
## make sure nobody gets the htaccess files
|
||||
<Files ~ "^[\._]ht">
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
Satisfy All
|
||||
</Files>
|
||||
|
||||
# option pour 1and1
|
||||
#AddType x-mapp-php5 .php
|
||||
#Options +FollowSymlinks
|
||||
|
||||
# autoriser le .htaccess dans sites-availlable/default.conf
|
||||
# enable the mode rewrite in : "/etc/apache2/mods-available" a copier dans "/etc/apache2/mods-enabled"
|
||||
# sudo cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/
|
||||
# redemarrer apache : "sudo /etc/init.d/apache2 restart"
|
||||
# voir les logs : "cat /var/log/apache2/error.log"
|
||||
|
||||
# charge la première page : the start page is the Wiki with Acceuil...
|
||||
#ErrorDocument 401 erreur/401
|
||||
#ErrorDocument 403 erreur/403
|
||||
#ErrorDocument 404 erreur/404
|
||||
#ErrorDocument 414 erreur/414
|
||||
|
||||
|
||||
RewriteEngine On
|
||||
# si ce n'est pas un fichier
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
|
||||
# constitution d'une adresse : "user-name/repository.svg" to get tag or "user-name/repository" to view lib
|
||||
RewriteRule ^build/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ build_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA]
|
||||
RewriteRule ^build/inject$ build_inject.php [L,QSA]
|
||||
|
||||
RewriteRule ^coverage/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ coverage_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA]
|
||||
RewriteRule ^coverage/inject$ coverage_inject.php [L,QSA]
|
||||
|
||||
RewriteRule ^warning/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ warning_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA]
|
||||
RewriteRule ^warning/inject$ warning_inject.php [L,QSA]
|
||||
|
||||
RewriteRule ^test/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ test_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA]
|
||||
RewriteRule ^test/inject$ test_inject.php [L,QSA]
|
||||
|
||||
RewriteRule ^([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*)$ view.php?USER=$1&LIB_NAME=$2 [L,QSA]
|
177
bdd.sql
Normal file
177
bdd.sql
Normal file
@ -0,0 +1,177 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 4.4.13.1
|
||||
-- http://www.phpmyadmin.net
|
||||
--
|
||||
-- Client : atriasofroot.mysql.db
|
||||
-- Généré le : Mar 20 Octobre 2015 à 10:26
|
||||
-- Version du serveur : 5.5.44-0+deb7u1-log
|
||||
-- Version de PHP : 5.3.8
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
--
|
||||
-- Structure de la table `CI_group`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `CI_group` (
|
||||
`id` int(11) NOT NULL,
|
||||
`user-name` varchar(256) NOT NULL,
|
||||
`lib-name` varchar(256) NOT NULL,
|
||||
`lib-branch` varchar(256) NOT NULL
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Structure de la table `COVERAGE_list`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `COVERAGE_list` (
|
||||
`id` int(11) NOT NULL,
|
||||
`id-group` int(11) NOT NULL,
|
||||
`time` int(11) NOT NULL,
|
||||
`sha1` varchar(256) NOT NULL,
|
||||
`executed` int(11) NOT NULL,
|
||||
`executable` int(11) NOT NULL
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=latin1;
|
||||
|
||||
--
|
||||
-- Structure de la table `COVERAGE_snapshot`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `COVERAGE_snapshot` (
|
||||
`id` int(11) NOT NULL,
|
||||
`id-group` int(11) NOT NULL,
|
||||
`id-list` int(11) NOT NULL,
|
||||
`json` text NOT NULL
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Structure de la table `TEST_list`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `TEST_list` (
|
||||
`id` int(11) NOT NULL,
|
||||
`id-group` int(11) NOT NULL,
|
||||
`time` int(11) NOT NULL,
|
||||
`sha1` varchar(256) CHARACTER SET latin1 NOT NULL,
|
||||
`passed` int(11) NOT NULL,
|
||||
`total` int(11) NOT NULL
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=131 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Structure de la table `TEST_snapshot`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `TEST_snapshot` (
|
||||
`id` int(11) NOT NULL,
|
||||
`id-group` int(11) NOT NULL,
|
||||
`id-list` int(11) NOT NULL,
|
||||
`json` text NOT NULL
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Structure de la table `WARNING_list`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WARNING_list` (
|
||||
`id` int(11) NOT NULL,
|
||||
`id-group` int(11) NOT NULL,
|
||||
`time` int(11) NOT NULL,
|
||||
`sha1` varchar(256) CHARACTER SET latin1 NOT NULL,
|
||||
`warning` int(11) NOT NULL,
|
||||
`error` int(11) NOT NULL
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=168 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Structure de la table `WARNING_snapshot`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WARNING_snapshot` (
|
||||
`id` int(11) NOT NULL,
|
||||
`id-group` int(11) NOT NULL,
|
||||
`id-list` int(11) NOT NULL,
|
||||
`json` text NOT NULL
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Index pour la table `CI_group`
|
||||
--
|
||||
ALTER TABLE `CI_group`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Index pour la table `COVERAGE_list`
|
||||
--
|
||||
ALTER TABLE `COVERAGE_list`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Index pour la table `COVERAGE_snapshot`
|
||||
--
|
||||
ALTER TABLE `COVERAGE_snapshot`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD UNIQUE KEY `id-group` (`id-group`);
|
||||
|
||||
--
|
||||
-- Index pour la table `TEST_list`
|
||||
--
|
||||
ALTER TABLE `TEST_list`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Index pour la table `TEST_snapshot`
|
||||
--
|
||||
ALTER TABLE `TEST_snapshot`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Index pour la table `WARNING_list`
|
||||
--
|
||||
ALTER TABLE `WARNING_list`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Index pour la table `WARNING_snapshot`
|
||||
--
|
||||
ALTER TABLE `WARNING_snapshot`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT pour les tables exportées
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `CI_group`
|
||||
--
|
||||
ALTER TABLE `CI_group`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=10;
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `COVERAGE_list`
|
||||
--
|
||||
ALTER TABLE `COVERAGE_list`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=52;
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `COVERAGE_snapshot`
|
||||
--
|
||||
ALTER TABLE `COVERAGE_snapshot`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4;
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `TEST_list`
|
||||
--
|
||||
ALTER TABLE `TEST_list`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=131;
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `TEST_snapshot`
|
||||
--
|
||||
ALTER TABLE `TEST_snapshot`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `WARNING_list`
|
||||
--
|
||||
ALTER TABLE `WARNING_list`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=168;
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `WARNING_snapshot`
|
||||
--
|
||||
ALTER TABLE `WARNING_snapshot`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;
|
131
build_inject.php
Normal file
131
build_inject.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
// force display of error
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
if (isset($_POST) == FALSE) {
|
||||
die("[ERROR] Missing POST");
|
||||
}
|
||||
if (isset($_POST['REPO']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'REPO' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['TAG']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'TAG'");
|
||||
}
|
||||
if (isset($_POST['STATUS']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'STATUS'");
|
||||
}
|
||||
if (isset($_POST['LIB_BRANCH']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'LIB_BRANCH' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['SHA1']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'SHA1' (max string 256 char)");
|
||||
}
|
||||
|
||||
list($userName, $libName) = explode("/", $_POST['REPO'], 2);
|
||||
//die("[ERROR] test : ".$userName." ".$libName);
|
||||
if ($userName == "") {
|
||||
die("[ERROR] missing the user-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
if ($libName == "") {
|
||||
die("[ERROR] missing the lib-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$COVERAGE_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
/* Check connection */
|
||||
if (mysqli_connect_errno()) {
|
||||
die("[ERROR] my-SQL-connection ERROR: '".mysqli_connect_error()."'");
|
||||
}
|
||||
|
||||
$idGroup = -1;
|
||||
// first step : check if the group exist ...
|
||||
$sql = " SELECT * FROM `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$userName."'"
|
||||
." AND `CI_group`.`lib-name` = '".$libName."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'"
|
||||
." LIMIT 1";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
$exist = TRUE;
|
||||
if ($result == NULL) {
|
||||
// no result ...
|
||||
$exist = FALSE;
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$userGroup = $result->fetch_assoc();
|
||||
$idGroup = $userGroup['id'];
|
||||
} else {
|
||||
$exist = FALSE;
|
||||
}
|
||||
if ($exist == FALSE) {
|
||||
// create a new one ...
|
||||
$sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)"
|
||||
." VALUES ('".$userName."',"
|
||||
." '".$libName."',"
|
||||
." '".$_POST['LIB_BRANCH']."')";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
$exist == TRUE;
|
||||
$idGroup = $COVERAGE_bdd->insert_id;
|
||||
} else {
|
||||
echo "[ERROR] Can not CREATE new group ...";
|
||||
}
|
||||
}
|
||||
|
||||
if ($idGroup <= -1) {
|
||||
echo("[ERROR] can not create or find group");
|
||||
} else {
|
||||
$sql = " INSERT INTO `BUILD_list` (`time`, `id-group`, `sha1`, `tag`, `status`)"
|
||||
." VALUES ('".time()."',"
|
||||
." '".$idGroup."',"
|
||||
." '".$_POST['SHA1']."',"
|
||||
." '".$_POST['TAG']."',"
|
||||
." '".$_POST['STATUS']."')";
|
||||
//echo $sql;
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == FALSE) {
|
||||
echo("[ERROR] Can not register in db ... (LIST)");
|
||||
}
|
||||
$sql = "SELECT `BUILD_snapshot`.`id` "
|
||||
." FROM `BUILD_snapshot`"
|
||||
." , `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$userName."'"
|
||||
." AND `CI_group`.`lib-name` = '".$libName."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'"
|
||||
." AND `CI_group`.`id` = `BUILD_snapshot`.`id-group`"
|
||||
." LIMIT 1";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
//echo("sql : ".$sql);
|
||||
if ( $result == NULL
|
||||
|| $result->num_rows == 0) {
|
||||
// simply insert:
|
||||
$sql = " INSERT INTO `BUILD_snapshot` (`id-group`, `".$_POST['TAG']."`)"
|
||||
." VALUES ('".$idGroup."',"
|
||||
." '".$_POST['STATUS']."')";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done (new entry)");
|
||||
} else {
|
||||
echo("[ERROR] Can not register in db ... (snapshot)");
|
||||
}
|
||||
} else {
|
||||
// try to update the curent values:
|
||||
$sql = " UPDATE `BUILD_snapshot`"
|
||||
." SET `BUILD_snapshot`.`".$_POST['TAG']."` = '".$_POST['STATUS']."'"
|
||||
." WHERE `BUILD_snapshot`.`id-group` = '".$idGroup."'";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done (update)");
|
||||
} else {
|
||||
echo("[ERROR] Can not register in db ... (snapshot)");
|
||||
}
|
||||
}
|
||||
}
|
||||
// simply close link with the DB...
|
||||
$COVERAGE_bdd->close();
|
||||
?>
|
101
build_send.py
Executable file
101
build_send.py
Executable file
@ -0,0 +1,101 @@
|
||||
#!/usr/bin/python
|
||||
##
|
||||
## @author Edouard DUPIN
|
||||
##
|
||||
## @copyright 2012, Edouard DUPIN, all right reserved
|
||||
##
|
||||
## @license APACHE v2.0 (see license file)
|
||||
##
|
||||
import urllib, urllib2
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-u", "--url", help="server URL",
|
||||
default="http://atria-soft.com/ci/build/inject")
|
||||
parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)",
|
||||
default="")
|
||||
parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)",
|
||||
default="")
|
||||
parser.add_argument("-b", "--branch", help="branch of the repository (default master)",
|
||||
default="")
|
||||
parser.add_argument("-t", "--tag", help="Tag to register the system 'Linux', 'MacOs', 'Windows', 'IOs', 'Android' ('' for exit)",
|
||||
default="")
|
||||
parser.add_argument("-S", "--status", help="Build status 'START', 'OK', 'ERROR' or $?",
|
||||
default="")
|
||||
###################
|
||||
## Choice 3 ##
|
||||
###################
|
||||
parser.add_argument("--test", help="test value (local server ...)",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.test == True:
|
||||
args.url = 'http://127.0.0.1/build/inject.php'
|
||||
args.repo = 'HeeroYui/test'
|
||||
args.sha1 = ''
|
||||
args.branch = 'master'
|
||||
args.tag = 'Windows'
|
||||
args.status = 'START'
|
||||
else:
|
||||
if args.tag == "":
|
||||
print("[NOTE] (local) not set '--tag' parameter ==> just stop")
|
||||
exit(0)
|
||||
list_tag = ['Linux', 'MacOs', 'Windows', 'IOs', 'Android', 'Mingw']
|
||||
if args.tag not in list_tag:
|
||||
print("[ERROR] (local) set '--tag' parameter: " + str(list_tag))
|
||||
exit(-2)
|
||||
if args.status == "":
|
||||
print("[ERROR] (local) set '--status' parameter")
|
||||
exit(-2)
|
||||
|
||||
if args.status not in ['START', 'OK', 'ERROR']:
|
||||
#print("ploppp : '" + str(args.status) + "'")
|
||||
if args.status == "0":
|
||||
args.status = 'OK'
|
||||
else:
|
||||
args.status = 'ERROR'
|
||||
|
||||
# todo : check if repo is contituated with a "/" ...
|
||||
# if repo, sha1 and branch is not set, we try to get it with travis global environement variable :
|
||||
if args.repo == "":
|
||||
args.repo = os.environ.get('TRAVIS_REPO_SLUG')
|
||||
if args.repo == None:
|
||||
print("[ERROR] (local) missing 'repo' parameter can not get travis env variable")
|
||||
exit(-2)
|
||||
if args.sha1 == "":
|
||||
args.sha1 = os.environ.get('TRAVIS_COMMIT')
|
||||
if args.sha1 == None:
|
||||
args.sha1 = ""
|
||||
|
||||
if args.branch == "":
|
||||
args.branch = os.environ.get('TRAVIS_BRANCH')
|
||||
if args.branch == None:
|
||||
args.branch = ""
|
||||
|
||||
print(" url = " + args.url)
|
||||
print(" repo = " + args.repo)
|
||||
print(" sha1 = " + args.sha1)
|
||||
print(" branch = " + args.branch)
|
||||
print(" tag = " + args.tag)
|
||||
print(" status = " + args.status)
|
||||
|
||||
data = urllib.urlencode({'REPO':args.repo,
|
||||
'SHA1':args.sha1,
|
||||
'LIB_BRANCH':args.branch,
|
||||
'TAG':args.tag,
|
||||
'STATUS':args.status})
|
||||
|
||||
req = urllib2.Request(args.url, data)
|
||||
response = urllib2.urlopen(req)
|
||||
#print response.geturl()
|
||||
#print response.info()
|
||||
return_data = response.read()
|
||||
print return_data
|
||||
if return_data[:7] == "[ERROR]":
|
||||
exit(-1)
|
||||
|
||||
exit(0)
|
||||
|
122
build_thumb.php
Normal file
122
build_thumb.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
// force display of error
|
||||
//error_reporting(E_ALL);
|
||||
//ini_set('display_errors', '1');
|
||||
//date_default_timezone_set('Europe/Paris');
|
||||
|
||||
// check if all is here ...
|
||||
//echo("<br/>USER = ".$_GET['USER']);
|
||||
//echo("<br/>LIB_NAME = ".$_GET['LIB_NAME']);
|
||||
//echo("<br/>branch = ".$_GET['branch']);
|
||||
//die("<br/>die");
|
||||
header("Content-Type: image/svg+xml");
|
||||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
|
||||
|
||||
function errorSVG($_name) {
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="180" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="#F00"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="60" y="15" fill="#010101" fill-opacity=".3">BUILD: '.$_name.'</text>');
|
||||
echo(' <text x="60" y="14">BUILD: '.$_name.'</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
exit();
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$COVERAGE_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
// Check connection
|
||||
if (mysqli_connect_errno()) {
|
||||
errorSVG("SQL ERROR");
|
||||
}
|
||||
// check if all is here ...
|
||||
$branch = "master";
|
||||
$tag = "Linux";
|
||||
if (isset($_GET['USER']) == FALSE) {
|
||||
errorSVG("USER??");
|
||||
}
|
||||
if (isset($_GET['LIB_NAME']) == FALSE) {
|
||||
errorSVG("LIB_NAME??");
|
||||
}
|
||||
if (isset($_GET['branch']) == TRUE) {
|
||||
$branch = $_GET['branch'];
|
||||
}
|
||||
if (isset($_GET['tag']) == TRUE) {
|
||||
$tag = $_GET['tag'];
|
||||
}
|
||||
|
||||
//echo "register ".$_POST['JSON_FILE'];
|
||||
|
||||
$sql = "SELECT `BUILD_snapshot`.`".$tag."` "
|
||||
." FROM `BUILD_snapshot`"
|
||||
." , `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'"
|
||||
." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$branch."'"
|
||||
." AND `CI_group`.`id` = `BUILD_snapshot`.`id-group`"
|
||||
." LIMIT 1";
|
||||
|
||||
//echo("sql : ".$sql);
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
//
|
||||
if ($result == NULL) {
|
||||
errorSVG("UNKNOW");
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
if ($result->num_rows > 1) {
|
||||
errorSVG("To much value");
|
||||
}
|
||||
$row = $result->fetch_assoc();
|
||||
} else {
|
||||
errorSVG("No Value");
|
||||
}
|
||||
|
||||
$status = $row[$tag];
|
||||
|
||||
|
||||
//some coverage value :
|
||||
if ($status == "UNKNOW") {
|
||||
$color = "333";
|
||||
} else if ($status == "START") {
|
||||
$color = "11F";
|
||||
} else if ($status == "ERROR") {
|
||||
$color = "c11";
|
||||
} else if ($status == "OK") {
|
||||
$color = "4c1";
|
||||
} else {
|
||||
$color = "FF0";
|
||||
}
|
||||
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="180" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="180" height="20" fill="#555"/>');
|
||||
echo(' <rect rx="3" x="40" width="75" height="20" fill="#A60"/>');
|
||||
echo(' <rect rx="3" x="110" width="70" height="20" fill="#'.$color.'"/>');
|
||||
echo(' <rect rx="3" width="180" height="20" fill="url(#a)"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="19" y="15" fill="#010101" fill-opacity=".3">build</text>');
|
||||
echo(' <text x="19" y="14">Build</text>');
|
||||
echo(' <text x="75" y="15" fill="#010101" fill-opacity=".3">'.$tag.'</text>');
|
||||
echo(' <text x="75" y="14">'.$tag.'</text>');
|
||||
echo(' <text x="145" y="15" fill="#010101" fill-opacity=".3">'.$status.'</text>');
|
||||
echo(' <text x="145" y="14">'.$status.'</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
|
||||
// simply close link with the DB...
|
||||
$COVERAGE_bdd->close();
|
||||
|
||||
?>
|
6
connect.php
Normal file
6
connect.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$sqlServer = "localhost";
|
||||
$sqlLogin = "root";
|
||||
$sqlPass = "password";
|
||||
$sqlBDD = "CI";
|
||||
?>
|
177
coverage_inject.php
Normal file
177
coverage_inject.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
// force display of error
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
// check if all is here ...
|
||||
/*
|
||||
if (isset($_GET) == FALSE) {
|
||||
echo "[ERROR] Missing GET";
|
||||
} else if (isset($_GET['JSON_FILE']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'JSON_FILE'";
|
||||
} else if (isset($_GET['LIB_NAME']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'LIB_NAME'";
|
||||
} else if (isset($_GET['LIB_BRANCH']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'LIB_BRANCH'";
|
||||
} else {
|
||||
|
||||
echo "[OK] registered done";
|
||||
}
|
||||
echo "\n";
|
||||
*/
|
||||
if (isset($_POST) == FALSE) {
|
||||
die("[ERROR] Missing POST");
|
||||
}
|
||||
if (isset($_POST['REPO']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'REPO' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['JSON_FILE']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'JSON_FILE'");
|
||||
}
|
||||
if (isset($_POST['LIB_BRANCH']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'LIB_BRANCH' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['SHA1']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'SHA1' (max string 256 char)");
|
||||
}
|
||||
// check json data:
|
||||
$val = json_decode($_POST['JSON_FILE'], true);
|
||||
if ( $val == NULL
|
||||
&& strlen($_POST['JSON_FILE']) > 0) {
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_NONE");
|
||||
case JSON_ERROR_DEPTH:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_DEPTH");
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_STATE_MISMATCH");
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_CTRL_CHAR");
|
||||
case JSON_ERROR_SYNTAX:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_SYNTAX");
|
||||
default:
|
||||
die("[ERROR] JSON parse: ???");
|
||||
}
|
||||
die("[ERROR] JSON parse: ".json_last_error_msg());
|
||||
}
|
||||
|
||||
if (isset($val["executed"]) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (root): 'executed'");
|
||||
}
|
||||
if (isset($val["executable"]) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (root): 'executable'");
|
||||
}
|
||||
$newJsonData = array();
|
||||
if (isset($val["list"]) == TRUE) {
|
||||
foreach ($val["list"] as $value) {
|
||||
if (isset($value['file']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): file");
|
||||
}
|
||||
if (isset($value['executed']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): executed");
|
||||
}
|
||||
if (isset($value['executable']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): executable");
|
||||
}
|
||||
array_push($newJsonData, array("file" => $value['file'], "executed" => $value['executed'], "executable" => $value['executable']));
|
||||
}
|
||||
}
|
||||
$dataJSON = json_encode($newJsonData);
|
||||
|
||||
list($userName, $libName) = explode("/", $_POST['REPO'], 2);
|
||||
//die("[ERROR] test : ".$userName." ".$libName);
|
||||
if ($userName == "") {
|
||||
die("[ERROR] missing the user-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
if ($libName == "") {
|
||||
die("[ERROR] missing the lib-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$COVERAGE_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
/* Check connection */
|
||||
if (mysqli_connect_errno()) {
|
||||
die("[ERROR] my-SQL-connection ERROR: '".mysqli_connect_error()."'");
|
||||
}
|
||||
|
||||
$idGroup = -1;
|
||||
// first step : check if the group exist ...
|
||||
$sql = " SELECT * FROM `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$userName."'"
|
||||
." AND `CI_group`.`lib-name` = '".$libName."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'"
|
||||
." LIMIT 1";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
$exist = TRUE;
|
||||
if ($result == NULL) {
|
||||
// no result ...
|
||||
$exist = FALSE;
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$userGroup = $result->fetch_assoc();
|
||||
$idGroup = $userGroup['id'];
|
||||
} else {
|
||||
$exist = FALSE;
|
||||
}
|
||||
if ($exist == FALSE) {
|
||||
// create a new one ...
|
||||
$sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)"
|
||||
." VALUES ('".$userName."',"
|
||||
." '".$libName."',"
|
||||
." '".$_POST['LIB_BRANCH']."')";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
$exist == TRUE;
|
||||
$idGroup = $COVERAGE_bdd->insert_id;
|
||||
} else {
|
||||
echo "[ERROR] Can not CREATE new group ...";
|
||||
}
|
||||
}
|
||||
|
||||
if ($idGroup <= -1) {
|
||||
echo("[ERROR] can not create or find group");
|
||||
} else {
|
||||
$sql = " INSERT INTO `COVERAGE_list` (`time`, `id-group`, `sha1`, `executed`, `executable`)"
|
||||
." VALUES ('".time()."',"
|
||||
." '".$idGroup."',"
|
||||
." '".$_POST['SHA1']."',"
|
||||
." '".$val["executed"]."',"
|
||||
." '".$val["executable"]."')";
|
||||
//echo $sql;
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == FALSE) {
|
||||
echo("[ERROR] Can not register in db ... (LIST)");
|
||||
} else {
|
||||
// get the id inserted
|
||||
$idList = $COVERAGE_bdd->insert_id;
|
||||
// try to update the curent values:
|
||||
$sql = " UPDATE `COVERAGE_snapshot`"
|
||||
." SET `COVERAGE_snapshot`.`id-list` = '".$idList."'"
|
||||
." , `COVERAGE_snapshot`.`json` = '".$dataJSON."'"
|
||||
." WHERE `COVERAGE_snapshot`.`id-group` = '".$idGroup."'";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done");
|
||||
} else {
|
||||
$sql = " INSERT INTO `COVERAGE_snapshot` (`id-group`, `id-list`, `json`)"
|
||||
." VALUES ('".$idGroup."',"
|
||||
." '".$idList."',"
|
||||
." '".$dataJSON."')";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done");
|
||||
} else {
|
||||
echo("[ERROR] Can not register in db ... (snapshot)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// simply close link with the DB...
|
||||
$COVERAGE_bdd->close();
|
||||
|
||||
?>
|
118
coverage_send.py
Executable file
118
coverage_send.py
Executable file
@ -0,0 +1,118 @@
|
||||
#!/usr/bin/python
|
||||
##
|
||||
## @author Edouard DUPIN
|
||||
##
|
||||
## @copyright 2012, Edouard DUPIN, all right reserved
|
||||
##
|
||||
## @license APACHE v2.0 (see license file)
|
||||
##
|
||||
import urllib, urllib2
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-u", "--url", help="server URL",
|
||||
default="http://atria-soft.com/ci/coverage/inject")
|
||||
parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)",
|
||||
default="")
|
||||
parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)",
|
||||
default="")
|
||||
parser.add_argument("-b", "--branch", help="branch of the repository (default master)",
|
||||
default="")
|
||||
###################
|
||||
## Choice 1 ##
|
||||
###################
|
||||
parser.add_argument("-j", "--json", help="all data to send ... (json file NOT json data)",
|
||||
default="")
|
||||
###################
|
||||
## Choice 2 ##
|
||||
###################
|
||||
parser.add_argument("--executed", help="if not use JSON file: simply generate the nb executed line in the lib/program",
|
||||
default=-1,
|
||||
type=int)
|
||||
parser.add_argument("--executable", help="if not use JSON file: simply generate the nb executable line in the lib/program",
|
||||
default=-1,
|
||||
type=int)
|
||||
###################
|
||||
## Choice 3 ##
|
||||
###################
|
||||
parser.add_argument("--test", help="test value (local server ...)",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.test == True:
|
||||
args.url = 'http://127.0.0.1/coverage/inject.php'
|
||||
args.repo = 'HeeroYui/test'
|
||||
args.sha1 = ''
|
||||
args.branch = 'master'
|
||||
json_data = '{"executed":16,"executable":512,"list":[{"file":"test/plop.cpp","executed":57,"executable":75}]}'
|
||||
else:
|
||||
if args.json != "":
|
||||
if args.executed >= 0:
|
||||
print("[ERROR] (local) set 'executed' parameter with a json file")
|
||||
exit(-2)
|
||||
if args.executable >= 0:
|
||||
print("[ERROR] (local) set 'executable' parameter with a json file")
|
||||
exit(-2)
|
||||
if not os.path.isfile(args.json):
|
||||
print("[ERROR] (local) can not read json file" + args.json)
|
||||
exit(-2)
|
||||
file = open(args.json, "r")
|
||||
json_data = file.read()
|
||||
file.close()
|
||||
if len(json_data) <= 0:
|
||||
print("[ERROR] (local) json file is empty")
|
||||
exit(-2)
|
||||
else:
|
||||
if args.executed < 0:
|
||||
print("[ERROR] (local) missing 'executed' parameter with NO json file")
|
||||
exit(-2)
|
||||
if args.executable < 0:
|
||||
print("[ERROR] (local) missing 'executable' parameter with NO json file")
|
||||
exit(-2)
|
||||
# create the minimal json file:
|
||||
json_data = '{"executed":' + str(args.executed) + ',"executable":' + str(args.executable) + ',"list":[]}'
|
||||
|
||||
print("json data: " + str(json_data))
|
||||
|
||||
# todo : check if repo is contituated wit a "/" ...
|
||||
# if repo, sha1 and branch is not set, we try to get it with travis global environement variable :
|
||||
if args.repo == "":
|
||||
args.repo = os.environ.get('TRAVIS_REPO_SLUG')
|
||||
if args.repo == None:
|
||||
print("[ERROR] (local) missing 'repo' parameter can not get travis env variable")
|
||||
exit(-2)
|
||||
if args.sha1 == "":
|
||||
args.sha1 = os.environ.get('TRAVIS_COMMIT')
|
||||
if args.sha1 == None:
|
||||
args.sha1 = ""
|
||||
|
||||
if args.branch == "":
|
||||
args.branch = os.environ.get('TRAVIS_BRANCH')
|
||||
if args.branch == None:
|
||||
args.branch = ""
|
||||
|
||||
print(" url = " + args.url)
|
||||
print(" repo = " + args.repo)
|
||||
print(" sha1 = " + args.sha1)
|
||||
print(" branch = " + args.branch)
|
||||
print(" json_data len = " + str(len(json_data)))
|
||||
|
||||
data = urllib.urlencode({'REPO':args.repo,
|
||||
'SHA1':args.sha1,
|
||||
'LIB_BRANCH':args.branch,
|
||||
'JSON_FILE':json_data})
|
||||
|
||||
req = urllib2.Request(args.url, data)
|
||||
response = urllib2.urlopen(req)
|
||||
#print response.geturl()
|
||||
#print response.info()
|
||||
return_data = response.read()
|
||||
print return_data
|
||||
if return_data[:7] == "[ERROR]":
|
||||
exit(-1)
|
||||
|
||||
exit(0)
|
||||
|
135
coverage_thumb.php
Normal file
135
coverage_thumb.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
// force display of error
|
||||
//error_reporting(E_ALL);
|
||||
//ini_set('display_errors', '1');
|
||||
//date_default_timezone_set('Europe/Paris');
|
||||
/*
|
||||
// check if all is here ...
|
||||
echo("<br/>USER = ".$_GET['USER']);
|
||||
echo("<br/>LIB_NAME = ".$_GET['LIB_NAME']);
|
||||
echo("<br/>branch = ".$_GET['branch']);
|
||||
die("<br/>die");
|
||||
*/
|
||||
header("Content-Type: image/svg+xml");
|
||||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
|
||||
/*
|
||||
header('Content-Type: image/svg+xml');
|
||||
echo '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" version="1.1"xmlns="http://www.w3.org/2000/svg">';
|
||||
$c = (int)(($x*$y)/$scaler);
|
||||
$prev = 0;
|
||||
foreach($rgb as $k=>$v){
|
||||
if($v > 0) {
|
||||
$r = ($k >> 16) & 0xFF;
|
||||
$g = ($k >> 8) & 0xFF;
|
||||
$b = $k & 0xFF;
|
||||
$hex = str_pad(dechex($r),2,'0',STR_PAD_LEFT).str_pad(dechex($g),2,'0',STR_PAD_LEFT).str_pad(dechex($b),2,'0',STR_PAD_LEFT);
|
||||
echo '<circle cx="'.$c.'" cy="'.$c.'" r="'.($c-$prev).'" fill="#'.$hex.'" />';
|
||||
echo "\n";
|
||||
$prev += (int)($v/$scaler);
|
||||
}
|
||||
}
|
||||
echo '</svg>';
|
||||
*/
|
||||
|
||||
|
||||
function errorSVG($_name) {
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="120" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="#F00"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="60" y="15" fill="#010101" fill-opacity=".3">COV: '.$_name.'</text>');
|
||||
echo(' <text x="60" y="14">COV: '.$_name.'</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
exit();
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$COVERAGE_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
// Check connection
|
||||
if (mysqli_connect_errno()) {
|
||||
errorSVG("SQL ERROR");
|
||||
}
|
||||
// check if all is here ...
|
||||
$branch = "master";
|
||||
if (isset($_GET['USER']) == FALSE) {
|
||||
errorSVG("USER??");
|
||||
} else if (isset($_GET['LIB_NAME']) == FALSE) {
|
||||
errorSVG("LIB_NAME??");
|
||||
}
|
||||
if (isset($_GET['branch']) == TRUE) {
|
||||
$branch = $_GET['branch'];
|
||||
}
|
||||
|
||||
//echo "register ".$_POST['JSON_FILE'];
|
||||
$sql = "SELECT `COVERAGE_list`.`executed` "
|
||||
." , `COVERAGE_list`.`executable` "
|
||||
." FROM `COVERAGE_list`"
|
||||
." , `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'"
|
||||
." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$branch."'"
|
||||
." AND `CI_group`.`id` = `COVERAGE_list`.`id-group`"
|
||||
." ORDER BY `COVERAGE_list`.`time` DESC"
|
||||
." LIMIT 1";
|
||||
$result = $COVERAGE_bdd->query($sql);
|
||||
//echo("sql : ".$sql);
|
||||
if ($result == NULL) {
|
||||
errorSVG("UNKNOW");
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
if ($result->num_rows > 1) {
|
||||
errorSVG("To much value");
|
||||
}
|
||||
$row = $result->fetch_assoc();
|
||||
} else {
|
||||
errorSVG("No Value");
|
||||
}
|
||||
|
||||
if ($row['executable'] == 0) {
|
||||
$coverage = 100;
|
||||
} else {
|
||||
$coverage = intval(100 * $row['executed'] / $row['executable']);
|
||||
}
|
||||
|
||||
//some coverage value :
|
||||
if ($coverage < 25 ) {
|
||||
$color = "c11";
|
||||
} else if ($coverage < 50 ) {
|
||||
$color = "c1c";
|
||||
} else if ($coverage < 75 ) {
|
||||
$color = "c71";
|
||||
} else {
|
||||
$color = "4c1";
|
||||
}
|
||||
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="120" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="#555"/>');
|
||||
echo(' <rect rx="3" x="67" width="53" height="20" fill="#'.$color.'"/>');
|
||||
#echo(' <path fill="#4c1" d="M37 0h4v20h-4z"/>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="url(#a)"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="32" y="15" fill="#010101" fill-opacity=".3">coverage</text>');
|
||||
echo(' <text x="32" y="14">coverage</text>');
|
||||
echo(' <text x="92.5" y="15" fill="#010101" fill-opacity=".3">'.$coverage.'%</text>');
|
||||
echo(' <text x="92.5" y="14">'.$coverage.'%</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
|
||||
// simply close link with the DB...
|
||||
$COVERAGE_bdd->close();
|
||||
?>
|
1
index.html
Normal file
1
index.html
Normal file
@ -0,0 +1 @@
|
||||
Coverage interface (No web interface availlable now ...)
|
174
test_inject.php
Normal file
174
test_inject.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
// force display of error
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
// check if all is here ...
|
||||
/*
|
||||
if (isset($_GET) == FALSE) {
|
||||
echo "[ERROR] Missing GET";
|
||||
} else if (isset($_GET['JSON_FILE']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'JSON_FILE'";
|
||||
} else if (isset($_GET['LIB_NAME']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'LIB_NAME'";
|
||||
} else if (isset($_GET['LIB_BRANCH']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'LIB_BRANCH'";
|
||||
} else {
|
||||
|
||||
echo "[OK] registered done";
|
||||
}
|
||||
echo "\n";
|
||||
*/
|
||||
if (isset($_POST) == FALSE) {
|
||||
die("[ERROR] Missing POST");
|
||||
}
|
||||
if (isset($_POST['REPO']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'REPO' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['JSON_FILE']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'JSON_FILE'");
|
||||
}
|
||||
if (isset($_POST['LIB_BRANCH']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'LIB_BRANCH' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['SHA1']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'SHA1' (max string 256 char)");
|
||||
}
|
||||
// check json data:
|
||||
$val = json_decode($_POST['JSON_FILE'], true);
|
||||
if ( $val == NULL
|
||||
&& strlen($_POST['JSON_FILE']) > 0) {
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_NONE");
|
||||
case JSON_ERROR_DEPTH:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_DEPTH");
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_STATE_MISMATCH");
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_CTRL_CHAR");
|
||||
case JSON_ERROR_SYNTAX:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_SYNTAX");
|
||||
default:
|
||||
die("[ERROR] JSON parse: ???");
|
||||
}
|
||||
die("[ERROR] JSON parse: ".json_last_error_msg());
|
||||
}
|
||||
|
||||
if (isset($val["passed"]) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (root): 'passed'");
|
||||
}
|
||||
if (isset($val["total"]) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (root): 'executable'");
|
||||
}
|
||||
$newJsonData = array();
|
||||
if (isset($val["list"]) == TRUE) {
|
||||
foreach ($val["list"] as $value) {
|
||||
if (isset($value['test-name']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): test-name");
|
||||
}
|
||||
if (isset($value['fail']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): fail");
|
||||
}
|
||||
array_push($newJsonData, array("file" => $value['test-name'], "test-name" => $value['fail']));
|
||||
}
|
||||
}
|
||||
$dataJSON = json_encode($newJsonData);
|
||||
|
||||
list($userName, $libName) = explode("/", $_POST['REPO'], 2);
|
||||
//die("[ERROR] test : ".$userName." ".$libName);
|
||||
if ($userName == "") {
|
||||
die("[ERROR] missing the user-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
if ($libName == "") {
|
||||
die("[ERROR] missing the lib-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$TEST_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
/* Check connection */
|
||||
if (mysqli_connect_errno()) {
|
||||
die("[ERROR] my-SQL-connection ERROR: '".mysqli_connect_error()."'");
|
||||
}
|
||||
|
||||
$idGroup = -1;
|
||||
// first step : check if the group exist ...
|
||||
$sql = " SELECT * FROM `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$userName."'"
|
||||
." AND `CI_group`.`lib-name` = '".$libName."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'"
|
||||
." LIMIT 1";
|
||||
$result = $TEST_bdd->query($sql);
|
||||
$exist = TRUE;
|
||||
if ($result == NULL) {
|
||||
// no result ...
|
||||
$exist = FALSE;
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$userGroup = $result->fetch_assoc();
|
||||
$idGroup = $userGroup['id'];
|
||||
} else {
|
||||
$exist = FALSE;
|
||||
}
|
||||
if ($exist == FALSE) {
|
||||
// create a new one ...
|
||||
$sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)"
|
||||
." VALUES ('".$userName."',"
|
||||
." '".$libName."',"
|
||||
." '".$_POST['LIB_BRANCH']."')";
|
||||
$result = $TEST_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
$exist == TRUE;
|
||||
$idGroup = $TEST_bdd->insert_id;
|
||||
} else {
|
||||
echo "[ERROR] Can not CREATE new group ...";
|
||||
}
|
||||
}
|
||||
|
||||
if ($idGroup <= -1) {
|
||||
echo("[ERROR] can not create or find group");
|
||||
} else {
|
||||
$sql = " INSERT INTO `TEST_list` (`time`, `id-group`, `sha1`, `passed`, `total`)"
|
||||
." VALUES ('".time()."',"
|
||||
." '".$idGroup."',"
|
||||
." '".$_POST['SHA1']."',"
|
||||
." '".$val["passed"]."',"
|
||||
." '".$val["total"]."')";
|
||||
//echo $sql;
|
||||
$result = $TEST_bdd->query($sql);
|
||||
if ($result == FALSE) {
|
||||
echo("[ERROR] Can not register in db ... (LIST)");
|
||||
} else {
|
||||
// get the id inserted
|
||||
$idList = $TEST_bdd->insert_id;
|
||||
// try to update the curent values:
|
||||
$sql = " UPDATE `TEST_snapshot`"
|
||||
." SET `TEST_snapshot`.`id-list` = '".$idList."'"
|
||||
." , `TEST_snapshot`.`json` = '".$dataJSON."'"
|
||||
." WHERE `TEST_snapshot`.`id-group` = '".$idGroup."'";
|
||||
$result = $TEST_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done");
|
||||
} else {
|
||||
$sql = " INSERT INTO `TEST_snapshot` (`id-group`, `id-list`, `json`)"
|
||||
." VALUES ('".$idGroup."',"
|
||||
." '".$idList."',"
|
||||
." '".$dataJSON."')";
|
||||
$result = $TEST_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done");
|
||||
} else {
|
||||
echo("[ERROR] Can not register in db ... (snapshot)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// simply close link with the DB...
|
||||
$TEST_bdd->close();
|
||||
|
||||
?>
|
184
test_send.py
Executable file
184
test_send.py
Executable file
@ -0,0 +1,184 @@
|
||||
#!/usr/bin/python
|
||||
##
|
||||
## @author Edouard DUPIN
|
||||
##
|
||||
## @copyright 2012, Edouard DUPIN, all right reserved
|
||||
##
|
||||
## @license APACHE v2.0 (see license file)
|
||||
##
|
||||
import urllib, urllib2
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-u", "--url", help="server URL",
|
||||
default="http://atria-soft.com/ci/test/inject")
|
||||
parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)",
|
||||
default="")
|
||||
parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)",
|
||||
default="")
|
||||
parser.add_argument("-b", "--branch", help="branch of the repository (default master)",
|
||||
default="")
|
||||
###################
|
||||
## Choice 1 ##
|
||||
###################
|
||||
parser.add_argument("-j", "--json", help="all data to send ... (json file NOT json data)",
|
||||
default="")
|
||||
###################
|
||||
## Choice 2 ##
|
||||
###################
|
||||
parser.add_argument("--passed", help="if not use JSON file: nb Test passsed in the lib/program",
|
||||
default=-1,
|
||||
type=int)
|
||||
parser.add_argument("--total", help="if not use JSON file: number total of test in the lib/program",
|
||||
default=-1,
|
||||
type=int)
|
||||
###################
|
||||
## Choice 3 ##
|
||||
###################
|
||||
parser.add_argument("--file", help="if not use JSON file: file with the 'gtest' log",
|
||||
default="")
|
||||
###################
|
||||
## Choice 4 ##
|
||||
###################
|
||||
parser.add_argument("--test", help="test value (local server ...)",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.test == True:
|
||||
args.url = 'http://127.0.0.1/ci/test_inject.php'
|
||||
args.repo = 'HeeroYui/test'
|
||||
args.sha1 = ''
|
||||
args.branch = 'master'
|
||||
json_data = '{"executed":16,"executable":512,"list":[{"file":"test/plop.cpp","executed":57,"executable":75}]}'
|
||||
else:
|
||||
if args.json != "":
|
||||
if args.passed >= 0:
|
||||
print("[ERROR] (local) set 'passed' parameter with a json file")
|
||||
exit(-2)
|
||||
if args.total >= 0:
|
||||
print("[ERROR] (local) set 'total' parameter with a json file")
|
||||
exit(-2)
|
||||
if args.file != "":
|
||||
print("[ERROR] (local) set 'file' parameter with a json file")
|
||||
exit(-2)
|
||||
if not os.path.isfile(args.json):
|
||||
print("[ERROR] (local) can not read json file" + args.json)
|
||||
exit(-2)
|
||||
file = open(args.json, "r")
|
||||
json_data = file.read()
|
||||
file.close()
|
||||
if len(json_data) <= 0:
|
||||
print("[ERROR] (local) json file is empty")
|
||||
exit(-2)
|
||||
elif args.passed >= 0:
|
||||
if args.file != "":
|
||||
print("[ERROR] (local) set 'file' parameter with 'passed'")
|
||||
exit(-2)
|
||||
if args.total < 0:
|
||||
args.total = 0
|
||||
json_data = '{"passed":' + args.passed + ',"total":' + args.total + ',"list":[]}'
|
||||
else:
|
||||
if args.file == "":
|
||||
print("[ERROR] (local) set 'file' parameter empty")
|
||||
exit(-2)
|
||||
if not os.path.isfile(args.file):
|
||||
print("[ERROR] (local) can not read test file" + args.file)
|
||||
exit(-2)
|
||||
file = open(args.file, "r")
|
||||
data = file.read()
|
||||
file.close()
|
||||
lines = data.split("\n")
|
||||
result = []
|
||||
total_test = 0
|
||||
total_passed = 0
|
||||
# parse all lines
|
||||
for line in lines:
|
||||
if len(line) <= 0:
|
||||
continue
|
||||
if line[0] != '[':
|
||||
continue
|
||||
if line[:12] == "[ RUN ]":
|
||||
#next line is usefull ...
|
||||
continue
|
||||
if line[:12] == "[ PASSED ]":
|
||||
#End of test result
|
||||
break
|
||||
if line[:12] == "[ OK ]":
|
||||
# this test is OK ...
|
||||
# TestDeclaration.testBase (0 ms)
|
||||
test_name = line[13:].split(" ")[0]
|
||||
result.append([test_name, True])
|
||||
total_test += 1
|
||||
total_passed += 1
|
||||
continue
|
||||
if line[:12] == "[ FAILED ]":
|
||||
# this test failled ...
|
||||
test_name = line[13:].split(" ")[0]
|
||||
result.append([test_name, False])
|
||||
total_test += 1
|
||||
continue
|
||||
# nothing to do ...
|
||||
#print("result : " + str(result))
|
||||
|
||||
# create the minimal json file:
|
||||
json_data = '{\n\t"passed":' + str(total_passed) + ',\n\t"total":' + str(total_test) + ',\n\t"list":[\n'
|
||||
first = True
|
||||
for elem in result:
|
||||
if first == True:
|
||||
first = False
|
||||
json_data += '\t\t{\n'
|
||||
else:
|
||||
json_data += '\t\t}, {\n'
|
||||
json_data += '\t\t\t"test-name":"' + elem[0] + '",\n'
|
||||
if elem[1] == True:
|
||||
json_data += '\t\t\t"fail":false\n'
|
||||
else:
|
||||
json_data += '\t\t\t"fail":true\n'
|
||||
if first == False:
|
||||
json_data += '\t\t}\n'
|
||||
json_data += '\t]\n}'
|
||||
|
||||
print("json data: " + str(json_data))
|
||||
|
||||
# todo : check if repo is contituated wit a "/" ...
|
||||
# if repo, sha1 and branch is not set, we try to get it with travis global environement variable :
|
||||
if args.repo == "":
|
||||
args.repo = os.environ.get('TRAVIS_REPO_SLUG')
|
||||
if args.repo == None:
|
||||
print("[ERROR] (local) missing 'repo' parameter can not get travis env variable")
|
||||
exit(-2)
|
||||
if args.sha1 == "":
|
||||
args.sha1 = os.environ.get('TRAVIS_COMMIT')
|
||||
if args.sha1 == None:
|
||||
args.sha1 = ""
|
||||
|
||||
if args.branch == "":
|
||||
args.branch = os.environ.get('TRAVIS_BRANCH')
|
||||
if args.branch == None:
|
||||
args.branch = ""
|
||||
|
||||
print(" url = " + args.url)
|
||||
print(" repo = " + args.repo)
|
||||
print(" sha1 = " + args.sha1)
|
||||
print(" branch = " + args.branch)
|
||||
print(" json_data len = " + str(len(json_data)))
|
||||
|
||||
data = urllib.urlencode({'REPO':args.repo,
|
||||
'SHA1':args.sha1,
|
||||
'JSON_FILE':json_data,
|
||||
'LIB_BRANCH':args.branch})
|
||||
|
||||
req = urllib2.Request(args.url, data)
|
||||
response = urllib2.urlopen(req)
|
||||
#print response.geturl()
|
||||
#print response.info()
|
||||
return_data = response.read()
|
||||
print return_data
|
||||
if return_data[:7] == "[ERROR]":
|
||||
exit(-1)
|
||||
|
||||
exit(0)
|
||||
|
135
test_thumb.php
Normal file
135
test_thumb.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
// force display of error
|
||||
//error_reporting(E_ALL);
|
||||
//ini_set('display_errors', '1');
|
||||
//date_default_timezone_set('Europe/Paris');
|
||||
/*
|
||||
// check if all is here ...
|
||||
echo("<br/>USER = ".$_GET['USER']);
|
||||
echo("<br/>LIB_NAME = ".$_GET['LIB_NAME']);
|
||||
echo("<br/>branch = ".$_GET['branch']);
|
||||
die("<br/>die");
|
||||
*/
|
||||
header("Content-Type: image/svg+xml");
|
||||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
|
||||
/*
|
||||
header('Content-Type: image/svg+xml');
|
||||
echo '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" version="1.1"xmlns="http://www.w3.org/2000/svg">';
|
||||
$c = (int)(($x*$y)/$scaler);
|
||||
$prev = 0;
|
||||
foreach($rgb as $k=>$v){
|
||||
if($v > 0) {
|
||||
$r = ($k >> 16) & 0xFF;
|
||||
$g = ($k >> 8) & 0xFF;
|
||||
$b = $k & 0xFF;
|
||||
$hex = str_pad(dechex($r),2,'0',STR_PAD_LEFT).str_pad(dechex($g),2,'0',STR_PAD_LEFT).str_pad(dechex($b),2,'0',STR_PAD_LEFT);
|
||||
echo '<circle cx="'.$c.'" cy="'.$c.'" r="'.($c-$prev).'" fill="#'.$hex.'" />';
|
||||
echo "\n";
|
||||
$prev += (int)($v/$scaler);
|
||||
}
|
||||
}
|
||||
echo '</svg>';
|
||||
*/
|
||||
|
||||
|
||||
function errorSVG($_name) {
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="120" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="#F00"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="60" y="15" fill="#010101" fill-opacity=".3">TEST: '.$_name.'</text>');
|
||||
echo(' <text x="60" y="14">TEST: '.$_name.'</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
exit();
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$TEST_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
// Check connection
|
||||
if (mysqli_connect_errno()) {
|
||||
errorSVG("SQL ERROR");
|
||||
}
|
||||
// check if all is here ...
|
||||
$branch = "master";
|
||||
if (isset($_GET['USER']) == FALSE) {
|
||||
errorSVG("USER??");
|
||||
} else if (isset($_GET['LIB_NAME']) == FALSE) {
|
||||
errorSVG("LIB_NAME??");
|
||||
}
|
||||
if (isset($_GET['branch']) == TRUE) {
|
||||
$branch = $_GET['branch'];
|
||||
}
|
||||
|
||||
//echo "register ".$_POST['JSON_FILE'];
|
||||
$sql = "SELECT `TEST_list`.`passed` "
|
||||
." , `TEST_list`.`total` "
|
||||
." FROM `TEST_list`"
|
||||
." , `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'"
|
||||
." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$branch."'"
|
||||
." AND `CI_group`.`id` = `TEST_list`.`id-group`"
|
||||
." ORDER BY `TEST_list`.`time` DESC"
|
||||
." LIMIT 1";
|
||||
$result = $TEST_bdd->query($sql);
|
||||
//echo("sql : ".$sql);
|
||||
if ($result == NULL) {
|
||||
errorSVG("UNKNOW");
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
if ($result->num_rows > 1) {
|
||||
errorSVG("To much value");
|
||||
}
|
||||
$row = $result->fetch_assoc();
|
||||
} else {
|
||||
errorSVG("No Value");
|
||||
}
|
||||
|
||||
if ($row['total'] == 0) {
|
||||
$testRatio = 0;
|
||||
} else {
|
||||
$testRatio = intval(100 * $row['passed'] / $row['total']);
|
||||
}
|
||||
|
||||
//some testRatio value :
|
||||
if ($testRatio < 25 ) {
|
||||
$color = "c11";
|
||||
} else if ($testRatio < 50 ) {
|
||||
$color = "c1c";
|
||||
} else if ($testRatio < 100 ) {
|
||||
$color = "c71";
|
||||
} else {
|
||||
$color = "4c1";
|
||||
}
|
||||
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="120" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="#555"/>');
|
||||
echo(' <rect rx="3" x="67" width="53" height="20" fill="#'.$color.'"/>');
|
||||
#echo(' <path fill="#4c1" d="M37 0h4v20h-4z"/>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="url(#a)"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="32" y="15" fill="#010101" fill-opacity=".3">test</text>');
|
||||
echo(' <text x="32" y="14">test</text>');
|
||||
echo(' <text x="92.5" y="15" fill="#010101" fill-opacity=".3">'.$testRatio.'%</text>');
|
||||
echo(' <text x="92.5" y="14">'.$testRatio.'%</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
|
||||
// simply close link with the DB...
|
||||
$TEST_bdd->close();
|
||||
?>
|
177
warning_inject.php
Normal file
177
warning_inject.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
// force display of error
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
// check if all is here ...
|
||||
/*
|
||||
if (isset($_GET) == FALSE) {
|
||||
echo "[ERROR] Missing GET";
|
||||
} else if (isset($_GET['JSON_FILE']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'JSON_FILE'";
|
||||
} else if (isset($_GET['LIB_NAME']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'LIB_NAME'";
|
||||
} else if (isset($_GET['LIB_BRANCH']) == FALSE) {
|
||||
echo "[ERROR] Missing GET : 'LIB_BRANCH'";
|
||||
} else {
|
||||
|
||||
echo "[OK] registered done";
|
||||
}
|
||||
echo "\n";
|
||||
*/
|
||||
if (isset($_POST) == FALSE) {
|
||||
die("[ERROR] Missing POST");
|
||||
}
|
||||
if (isset($_POST['REPO']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'REPO' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['JSON_FILE']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'JSON_FILE'");
|
||||
}
|
||||
if (isset($_POST['LIB_BRANCH']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'LIB_BRANCH' (max string 256 char)");
|
||||
}
|
||||
if (isset($_POST['SHA1']) == FALSE) {
|
||||
die("[ERROR] Missing POST : 'SHA1' (max string 256 char)");
|
||||
}
|
||||
// check json data:
|
||||
$val = json_decode($_POST['JSON_FILE'], true);
|
||||
if ( $val == NULL
|
||||
&& strlen($_POST['JSON_FILE']) > 0) {
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_NONE");
|
||||
case JSON_ERROR_DEPTH:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_DEPTH");
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_STATE_MISMATCH");
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_CTRL_CHAR");
|
||||
case JSON_ERROR_SYNTAX:
|
||||
die("[ERROR] JSON parse: JSON_ERROR_SYNTAX");
|
||||
default:
|
||||
die("[ERROR] JSON parse: ???");
|
||||
}
|
||||
die("[ERROR] JSON parse: ".json_last_error_msg());
|
||||
}
|
||||
|
||||
if (isset($val["warning"]) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (root): 'warning'");
|
||||
}
|
||||
if (isset($val["error"]) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (root): 'error'");
|
||||
}
|
||||
$newJsonData = array();
|
||||
if (isset($val["list"]) == TRUE) {
|
||||
foreach ($val["list"] as $value) {
|
||||
if (isset($value['file']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): file");
|
||||
}
|
||||
if (isset($value['warning']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): warning");
|
||||
}
|
||||
if (isset($value['error']) == FALSE) {
|
||||
die("[ERROR] Missing JSON data (list): error");
|
||||
}
|
||||
array_push($newJsonData, array("file" => $value['file'], "warning" => $value['warning'], "error" => $value['error']));
|
||||
}
|
||||
}
|
||||
$dataJSON = json_encode($newJsonData);
|
||||
|
||||
list($userName, $libName) = explode("/", $_POST['REPO'], 2);
|
||||
//die("[ERROR] test : ".$userName." ".$libName);
|
||||
if ($userName == "") {
|
||||
die("[ERROR] missing the user-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
if ($libName == "") {
|
||||
die("[ERROR] missing the lib-name in '".$_POST['REPO']."'");
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$WARNING_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
/* Check connection */
|
||||
if (mysqli_connect_errno()) {
|
||||
die("[ERROR] my-SQL-connection ERROR: '".mysqli_connect_error()."'");
|
||||
}
|
||||
|
||||
$idGroup = -1;
|
||||
// first step : check if the group exist ...
|
||||
$sql = " SELECT * FROM `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$userName."'"
|
||||
." AND `CI_group`.`lib-name` = '".$libName."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'"
|
||||
." LIMIT 1";
|
||||
$result = $WARNING_bdd->query($sql);
|
||||
$exist = TRUE;
|
||||
if ($result == NULL) {
|
||||
// no result ...
|
||||
$exist = FALSE;
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$userGroup = $result->fetch_assoc();
|
||||
$idGroup = $userGroup['id'];
|
||||
} else {
|
||||
$exist = FALSE;
|
||||
}
|
||||
if ($exist == FALSE) {
|
||||
// create a new one ...
|
||||
$sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)"
|
||||
." VALUES ('".$userName."',"
|
||||
." '".$libName."',"
|
||||
." '".$_POST['LIB_BRANCH']."')";
|
||||
$result = $WARNING_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
$exist == TRUE;
|
||||
$idGroup = $WARNING_bdd->insert_id;
|
||||
} else {
|
||||
echo "[ERROR] Can not CREATE new group ...";
|
||||
}
|
||||
}
|
||||
|
||||
if ($idGroup <= -1) {
|
||||
echo("[ERROR] can not create or find group");
|
||||
} else {
|
||||
$sql = " INSERT INTO `WARNING_list` (`time`, `id-group`, `sha1`, `warning`, `error`)"
|
||||
." VALUES ('".time()."',"
|
||||
." '".$idGroup."',"
|
||||
." '".$_POST['SHA1']."',"
|
||||
." '".$val["warning"]."',"
|
||||
." '".$val["error"]."')";
|
||||
//echo $sql;
|
||||
$result = $WARNING_bdd->query($sql);
|
||||
if ($result == FALSE) {
|
||||
echo("[ERROR] Can not register in db ... (LIST)");
|
||||
} else {
|
||||
// get the id inserted
|
||||
$idList = $WARNING_bdd->insert_id;
|
||||
// try to update the curent values:
|
||||
$sql = " UPDATE `WARNING_snapshot`"
|
||||
." SET `WARNING_snapshot`.`id-list` = '".$idList."'"
|
||||
." , `WARNING_snapshot`.`json` = '".$dataJSON."'"
|
||||
." WHERE `WARNING_snapshot`.`id-group` = '".$idGroup."'";
|
||||
$result = $WARNING_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done");
|
||||
} else {
|
||||
$sql = " INSERT INTO `WARNING_snapshot` (`id-group`, `id-list`, `json`)"
|
||||
." VALUES ('".$idGroup."',"
|
||||
." '".$idList."',"
|
||||
." '".$dataJSON."')";
|
||||
$result = $WARNING_bdd->query($sql);
|
||||
if ($result == TRUE) {
|
||||
echo("[OK] registered done");
|
||||
} else {
|
||||
echo("[ERROR] Can not register in db ... (snapshot)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// simply close link with the DB...
|
||||
$WARNING_bdd->close();
|
||||
|
||||
?>
|
198
warning_send.py
Executable file
198
warning_send.py
Executable file
@ -0,0 +1,198 @@
|
||||
#!/usr/bin/python
|
||||
##
|
||||
## @author Edouard DUPIN
|
||||
##
|
||||
## @copyright 2012, Edouard DUPIN, all right reserved
|
||||
##
|
||||
## @license APACHE v2.0 (see license file)
|
||||
##
|
||||
import urllib, urllib2
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import fnmatch
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-u", "--url", help="server URL",
|
||||
default="http://atria-soft.com/ci/warning/inject")
|
||||
parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)",
|
||||
default="")
|
||||
parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)",
|
||||
default="")
|
||||
parser.add_argument("-b", "--branch", help="branch of the repository (default master)",
|
||||
default="")
|
||||
###################
|
||||
## Choice 1 ##
|
||||
###################
|
||||
parser.add_argument("-j", "--json", help="all data to send ... (json file NOT json data)",
|
||||
default="")
|
||||
###################
|
||||
## Choice 2 ##
|
||||
###################
|
||||
parser.add_argument("--find-path", help="recursive path finding all file with the regex value (--regex)",
|
||||
default="out/")
|
||||
parser.add_argument("--extention", help="file extention where is stored the data of warnings (default : 'warning')",
|
||||
default="warning")
|
||||
parser.add_argument("--regex", help="Filtering the path finding element (default '*')",
|
||||
default="*")
|
||||
parser.add_argument("--rm-path", help="remove path in the output file name",
|
||||
action="store_true")
|
||||
###################
|
||||
## Choice 3 ##
|
||||
###################
|
||||
parser.add_argument("--warning", help="if not use JSON file: simply generate the nb warning lines in the lib/program",
|
||||
default=-1,
|
||||
type=int)
|
||||
parser.add_argument("--error", help="if not use JSON file: simply generate the nb error lines in the lib/program",
|
||||
default=-1,
|
||||
type=int)
|
||||
###################
|
||||
## Choice 4 ##
|
||||
###################
|
||||
parser.add_argument("--test", help="test value (local server ...)",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.test == True:
|
||||
args.url = 'http://127.0.0.1/ci/warning/inject.php'
|
||||
args.repo = 'HeeroYui/test'
|
||||
args.sha1 = ''
|
||||
args.branch = 'master'
|
||||
json_data = '{"count":5200,"list":[{"file":"test/plop.cpp","count-warning":57,"count-error":3}]}'
|
||||
else:
|
||||
if args.json != "":
|
||||
if args.warning >= 0:
|
||||
print("[ERROR] (local) set 'warning' parameter with a json file")
|
||||
exit(-2)
|
||||
if args.error >= 0:
|
||||
print("[ERROR] (local) set 'error' parameter with a json file")
|
||||
exit(-2)
|
||||
if args.find_path >= 0:
|
||||
print("[ERROR] (local) set 'find-path' parameter with a json file")
|
||||
exit(-2)
|
||||
if args.regex >= 0:
|
||||
print("[ERROR] (local) set 'regex' parameter with a json file")
|
||||
exit(-2)
|
||||
if not os.path.isfile(args.json):
|
||||
print("[ERROR] (local) can not read json file" + args.json)
|
||||
exit(-2)
|
||||
file = open(args.json, "r")
|
||||
json_data = file.read()
|
||||
file.close()
|
||||
if len(json_data) <= 0:
|
||||
print("[ERROR] (local) json file is empty")
|
||||
exit(-2)
|
||||
elif args.warning >= 0:
|
||||
if args.find_path >= 0:
|
||||
print("[ERROR] (local) set 'find-path' parameter with 'count'")
|
||||
exit(-2)
|
||||
if args.regex >= 0:
|
||||
print("[ERROR] (local) set 'regex' parameter with 'count'")
|
||||
exit(-2)
|
||||
if args.error < 0:
|
||||
args.error = 0
|
||||
json_data = '{"warning":' + args.warning + ',"error":' + args.error + ',"list":[]}'
|
||||
else:
|
||||
if args.find_path == "":
|
||||
print("[ERROR] (local) set 'find-path' parameter empty")
|
||||
exit(-2)
|
||||
if args.regex == "":
|
||||
print("[ERROR] (local) set 'regex' parameter empty")
|
||||
exit(-2)
|
||||
# get all the requested files :
|
||||
all_files = []
|
||||
for root, dirnames, filenames in os.walk(args.find_path):
|
||||
# filter with extention ...
|
||||
filesss = fnmatch.filter(filenames, "*." + args.extention)
|
||||
for filename in filesss:
|
||||
file = os.path.join(root, filename)
|
||||
all_files.append(file)
|
||||
# filter with the regular expression
|
||||
all_files = fnmatch.filter(all_files, args.regex)
|
||||
all_files2 = []
|
||||
for elem in all_files:
|
||||
file = elem[len(args.find_path):-len(args.extention)-1]
|
||||
all_files2.append(file)
|
||||
print("file : " + file);
|
||||
all_files = all_files2
|
||||
result = [];
|
||||
total_warning_count = 0
|
||||
total_error_count = 0
|
||||
# parse all files needed:
|
||||
for elem in all_files:
|
||||
file = open(args.find_path + elem + "." + args.extention, "r")
|
||||
data = file.read()
|
||||
file.close()
|
||||
if len(data) == 0:
|
||||
# no warning and no error posible
|
||||
result.append([elem, 0, 0])
|
||||
else:
|
||||
lines = data.split("\n")
|
||||
error_count = 0
|
||||
warning_count = 0
|
||||
for line in lines:
|
||||
warning_count += line.count('warning:')
|
||||
error_count += line.count('error:')
|
||||
total_warning_count += warning_count
|
||||
total_error_count += error_count
|
||||
result.append([elem, warning_count, error_count])
|
||||
print("result : " + str(result))
|
||||
|
||||
# create the minimal json file:
|
||||
json_data = '{\n\t"warning":' + str(total_warning_count) + ',\n\t"error":' + str(total_error_count) + ',\n\t"list":[\n'
|
||||
first = True
|
||||
for elem in result:
|
||||
if first == True:
|
||||
first = False
|
||||
json_data += '\t\t{\n'
|
||||
else:
|
||||
json_data += '\t\t}, {\n'
|
||||
json_data += '\t\t\t"file":"' + elem[0] + '",\n'
|
||||
json_data += '\t\t\t"warning":"' + str(elem[1]) + '",\n'
|
||||
json_data += '\t\t\t"error":"' + str(elem[2]) + '"\n'
|
||||
if first == False:
|
||||
json_data += '\t\t}\n'
|
||||
json_data += '\t]\n}'
|
||||
|
||||
print("json data: " + str(json_data))
|
||||
|
||||
# todo : check if repo is contituated wit a "/" ...
|
||||
# if repo, sha1 and branch is not set, we try to get it with travis global environement variable :
|
||||
if args.repo == "":
|
||||
args.repo = os.environ.get('TRAVIS_REPO_SLUG')
|
||||
if args.repo == None:
|
||||
print("[ERROR] (local) missing 'repo' parameter can not get travis env variable")
|
||||
exit(-2)
|
||||
if args.sha1 == "":
|
||||
args.sha1 = os.environ.get('TRAVIS_COMMIT')
|
||||
if args.sha1 == None:
|
||||
args.sha1 = ""
|
||||
|
||||
if args.branch == "":
|
||||
args.branch = os.environ.get('TRAVIS_BRANCH')
|
||||
if args.branch == None:
|
||||
args.branch = ""
|
||||
|
||||
print(" url = " + args.url)
|
||||
print(" repo = " + args.repo)
|
||||
print(" sha1 = " + args.sha1)
|
||||
print(" branch = " + args.branch)
|
||||
print(" json_data len = " + str(len(json_data)))
|
||||
|
||||
data = urllib.urlencode({'REPO':args.repo,
|
||||
'SHA1':args.sha1,
|
||||
'LIB_BRANCH':args.branch,
|
||||
'JSON_FILE':json_data})
|
||||
|
||||
req = urllib2.Request(args.url, data)
|
||||
response = urllib2.urlopen(req)
|
||||
#print response.geturl()
|
||||
#print response.info()
|
||||
return_data = response.read()
|
||||
print return_data
|
||||
if return_data[:7] == "[ERROR]":
|
||||
exit(-1)
|
||||
|
||||
exit(0)
|
||||
|
131
warning_thumb.php
Normal file
131
warning_thumb.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
// force display of error
|
||||
//error_reporting(E_ALL);
|
||||
//ini_set('display_errors', '1');
|
||||
//date_default_timezone_set('Europe/Paris');
|
||||
/*
|
||||
// check if all is here ...
|
||||
echo("<br/>USER = ".$_GET['USER']);
|
||||
echo("<br/>LIB_NAME = ".$_GET['LIB_NAME']);
|
||||
echo("<br/>branch = ".$_GET['branch']);
|
||||
die("<br/>die");
|
||||
*/
|
||||
header("Content-Type: image/svg+xml");
|
||||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
|
||||
/*
|
||||
header('Content-Type: image/svg+xml');
|
||||
echo '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" version="1.1"xmlns="http://www.w3.org/2000/svg">';
|
||||
$c = (int)(($x*$y)/$scaler);
|
||||
$prev = 0;
|
||||
foreach($rgb as $k=>$v){
|
||||
if($v > 0) {
|
||||
$r = ($k >> 16) & 0xFF;
|
||||
$g = ($k >> 8) & 0xFF;
|
||||
$b = $k & 0xFF;
|
||||
$hex = str_pad(dechex($r),2,'0',STR_PAD_LEFT).str_pad(dechex($g),2,'0',STR_PAD_LEFT).str_pad(dechex($b),2,'0',STR_PAD_LEFT);
|
||||
echo '<circle cx="'.$c.'" cy="'.$c.'" r="'.($c-$prev).'" fill="#'.$hex.'" />';
|
||||
echo "\n";
|
||||
$prev += (int)($v/$scaler);
|
||||
}
|
||||
}
|
||||
echo '</svg>';
|
||||
*/
|
||||
|
||||
|
||||
function errorSVG($_name) {
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="120" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="#F00"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="60" y="15" fill="#010101" fill-opacity=".3">WAR: '.$_name.'</text>');
|
||||
echo(' <text x="60" y="14">WAR: '.$_name.'</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
exit();
|
||||
}
|
||||
|
||||
include_once("connect.php");
|
||||
|
||||
@include_once("connect_server.php");
|
||||
|
||||
$WARNING_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD);
|
||||
// Check connection
|
||||
if (mysqli_connect_errno()) {
|
||||
errorSVG("SQL ERROR");
|
||||
}
|
||||
// check if all is here ...
|
||||
$branch = "master";
|
||||
if (isset($_GET['USER']) == FALSE) {
|
||||
errorSVG("USER??");
|
||||
} else if (isset($_GET['LIB_NAME']) == FALSE) {
|
||||
errorSVG("LIB_NAME??");
|
||||
}
|
||||
if (isset($_GET['branch']) == TRUE) {
|
||||
$branch = $_GET['branch'];
|
||||
}
|
||||
|
||||
//echo "register ".$_POST['JSON_FILE'];
|
||||
$sql = "SELECT `WARNING_list`.`warning` "
|
||||
." , `WARNING_list`.`error` "
|
||||
." FROM `WARNING_list`"
|
||||
." , `CI_group`"
|
||||
." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'"
|
||||
." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'"
|
||||
." AND `CI_group`.`lib-branch` = '".$branch."'"
|
||||
." AND `CI_group`.`id` = `WARNING_list`.`id-group`"
|
||||
." ORDER BY `WARNING_list`.`time` DESC"
|
||||
." LIMIT 1";
|
||||
$result = $WARNING_bdd->query($sql);
|
||||
//echo("sql : ".$sql);
|
||||
if ($result == NULL) {
|
||||
errorSVG("UNKNOW");
|
||||
}
|
||||
//echo("find result : ".$result);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
if ($result->num_rows > 1) {
|
||||
errorSVG("To much value");
|
||||
}
|
||||
$row = $result->fetch_assoc();
|
||||
} else {
|
||||
errorSVG("No Value");
|
||||
}
|
||||
|
||||
$warningCount = $row['warning'] + $row['error'];
|
||||
|
||||
//some warningCount value :
|
||||
if ($warningCount < 5 ) {
|
||||
$color = "4c1";
|
||||
} else if ($warningCount < 20 ) {
|
||||
$color = "c71";
|
||||
} else if ($warningCount < 50 ) {
|
||||
$color = "c1c";
|
||||
} else {
|
||||
$color = "c11";
|
||||
}
|
||||
|
||||
echo('<svg xmlns="http://www.w3.org/2000/svg" width="120" height="20">');
|
||||
echo(' <linearGradient id="a" x2="0" y2="100%">');
|
||||
echo(' <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>');
|
||||
echo(' <stop offset="1" stop-opacity=".1"/>');
|
||||
echo(' </linearGradient>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="#555"/>');
|
||||
echo(' <rect rx="3" x="67" width="53" height="20" fill="#'.$color.'"/>');
|
||||
#echo(' <path fill="#4c1" d="M37 0h4v20h-4z"/>');
|
||||
echo(' <rect rx="3" width="120" height="20" fill="url(#a)"/>');
|
||||
echo(' <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">');
|
||||
echo(' <text x="32" y="15" fill="#010101" fill-opacity=".3">warning</text>');
|
||||
echo(' <text x="32" y="14">warning</text>');
|
||||
echo(' <text x="92.5" y="15" fill="#010101" fill-opacity=".3">'.$warningCount.'</text>');
|
||||
echo(' <text x="92.5" y="14">'.$warningCount.'</text>');
|
||||
echo(' </g>');
|
||||
echo('</svg>');
|
||||
|
||||
// simply close link with the DB...
|
||||
$WARNING_bdd->close();
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user