xaizek / fragile (License: AGPLv3+) (since 2018-12-07)
Simple lightweight CI, attempting to be somewhat Unix-like in its philosophy.
Commit 7429f9fba1cfed27d4114d6dd1b9c822415905b0

Display duration in the interface
* On dashboard for buildsets.
* In builds.
Author: xaizek
Author date (UTC): 2018-11-24 12:33
Committer name: xaizek
Committer date (UTC): 2018-11-24 12:40
Parent(s): 1d91d3d8dddbb724ce9ecd4bed9a7db1bac5d5a0
Signing key: 99DC5E4DB05F6BE2
Tree: 5c66d93fc0e448ece5984186cf54938d25f8dd02
File Lines added Lines deleted
README.md 2 1
build.php 5 0
classes/Utils.php 28 0
dashboard.php 22 2
File README.md changed (mode: 100644) (index 1a53ec2..a0c9f74)
1 1 **fragile**, _v0.6_, _2015 – 2018_ **fragile**, _v0.6_, _2015 – 2018_
2 2
3 _This file last updated on 22 September, 2018_
3 _This file last updated on 24 November, 2018_
4 4
5 5 ### Brief Description ### ### Brief Description ###
6 6
 
... ... fixed in the future.
30 30 * Simple control interface through pushes to the repository * Simple control interface through pushes to the repository
31 31 * Smart order of running builders (those which failed on previous run on the * Smart order of running builders (those which failed on previous run on the
32 32 branch are executed first) branch are executed first)
33 * Measuring duration of builds
33 34
34 35 ### Screenshot ### ### Screenshot ###
35 36
File build.php changed (mode: 100644) (index 6c5432f..29c337a)
... ... require_once __DIR__ . '/header.php';
17 17
18 18 require_once __DIR__ . '/classes/Build.php'; require_once __DIR__ . '/classes/Build.php';
19 19 require_once __DIR__ . '/classes/Buildset.php'; require_once __DIR__ . '/classes/Buildset.php';
20 require_once __DIR__ . '/classes/Utils.php';
20 21
21 22 if (!isset($_GET['buildset']) || !isset($_GET['buildername'])) { if (!isset($_GET['buildset']) || !isset($_GET['buildername'])) {
22 23 die("Invalid parameters.\n"); die("Invalid parameters.\n");
 
... ... try {
56 57 print "<span class='infotitle'>Exit code:</span>\n"; print "<span class='infotitle'>Exit code:</span>\n";
57 58 print htmlentities($build->exitcode); print htmlentities($build->exitcode);
58 59 print "</span>\n"; print "</span>\n";
60 print "<span class='infocell'>\n";
61 print "<span class='infotitle'>Duration:</span>\n";
62 print htmlentities(Utils::formatDuration($build->getDuration()));
63 print "</span>\n";
59 64 print "</div>\n"; print "</div>\n";
60 65
61 66 $rawOutput = $build->getOutput(); $rawOutput = $build->getOutput();
File classes/Utils.php changed (mode: 100644) (index bdf0b08..899c9ef)
... ... class Utils
43 43 return rmdir($dir); return rmdir($dir);
44 44 } }
45 45
46 /**
47 * @brief Formats time duration as a string.
48 *
49 * @param duration Duration in seconds.
50 *
51 * @returns "unknown" for negative @p duration, "< 1s" for zero @p duration
52 * and "[Xm]Ys" for positive @p duration.
53 */
54 public static function formatDuration($duration)
55 {
56 if ($duration < 0) {
57 return 'unknown';
58 }
59 if ($duration == 0) {
60 return '< 1s';
61 }
62
63 $minutes = floor($duration/60);
64 $seconds = $duration%60;
65
66 $text = '';
67 if ($minutes >= 1) {
68 $text .= $minutes . 'm';
69 }
70 $text .= $seconds . 's';
71
72 return $text;
73 }
46 74 } }
47 75
48 76 ?> ?>
File dashboard.php changed (mode: 100644) (index 54c84e1..cc57973)
15 15
16 16 require_once __DIR__ . '/classes/Builds.php'; require_once __DIR__ . '/classes/Builds.php';
17 17 require_once __DIR__ . '/classes/Buildsets.php'; require_once __DIR__ . '/classes/Buildsets.php';
18 require_once __DIR__ . '/classes/Utils.php';
18 19 require_once __DIR__ . '/config.php'; require_once __DIR__ . '/config.php';
19 20
20 21 require_once __DIR__ . '/header.php'; require_once __DIR__ . '/header.php';
 
... ... function printBuildTable($buildsets, $builders)
62 63 print '<table class="dashboard"><tr><td></td>' . "\n"; print '<table class="dashboard"><tr><td></td>' . "\n";
63 64 foreach ($buildsets as $buildset) { foreach ($buildsets as $buildset) {
64 65 $ts = gmdate('Y-m-d H:i:s', $buildset->timestamp) . ' UTC'; $ts = gmdate('Y-m-d H:i:s', $buildset->timestamp) . ' UTC';
65 print "<td class='revision' title='$ts'>";
66 print '#' . htmlentities($buildset->buildsetid) . ': ';
66 $buildsetid = $buildset->buildsetid;
67
68 // compute duration of the buildset
69 $buildsetDuration = -1;
70 foreach ($builders as $buildername => $builderinfo) {
71 if (array_key_exists($buildsetid, $builderinfo)) {
72 $duration = $builderinfo[$buildsetid]->getDuration();
73 if ($duration >= 0) {
74 if ($buildsetDuration < 0) {
75 $buildsetDuration = 0;
76 }
77 $buildsetDuration += $duration;
78 }
79 }
80 }
81
82 $duration = Utils::formatDuration($buildsetDuration);
83 $tooltip = "Scheduled at: $ts\nTotal duration: ${duration}";
84
85 print "<td class='revision' title='$tooltip'>";
86 print '#' . htmlentities($buildsetid) . ': ';
67 87 print htmlentities($buildset->revision); print htmlentities($buildset->revision);
68 88 print "<br/><span class='name'>" print "<br/><span class='name'>"
69 89 . htmlentities($buildset->name) . htmlentities($buildset->name)
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/fragile

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/fragile

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master