<?php
// Copyright (C) 2015 xaizek <xaizek@posteo.net>
//
// fragile is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free
// Software Foundation, version 3.
//
// fragile is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
// A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
// details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
require_once __DIR__ . '/classes/Build.php';
require_once __DIR__ . '/classes/Buildset.php';
require_once __DIR__ . '/classes/Utils.php';
require_once __DIR__ . '/config.php';
if (sizeof($argv) < 3) {
print "Usage: ${argv[0]} name revision [builder-name..]\n";
die("Wrong invocation\n");
}
$name = $argv[1];
$revision = $argv[2];
$builders = array_slice($argv, 3);
if (substr($name, 0, strlen('fragile-do/')) === 'fragile-do/') {
$command = substr($name, strlen('fragile-do/'));
$pieces = explode('%', $command);
switch ($pieces[0]) {
case 'clean':
// XXX: ideally, this would only schedule the operation for the
// daemon; currently, we can change FS in parallel with it
Utils::delTree(BUILDS_PATH);
exit("Cleaned ".BUILDS_PATH);
case 'repeat':
if (sizeof($pieces) != 2) {
die('repeat command expects an argument');
}
$buildset = Buildset::get($pieces[1]);
if ($buildset === null) {
die("repeat command expects a valid buildset id as an ".
"argument\ngot: ${pieces[1]}");
}
$name = $buildset->name;
$revision = $buildset->revision;
$builders = [];
print "Repeating $name@$revision from #{$pieces[1]}\n";
break;
default:
exit("Unknown command: $command");
}
}
$buildset = Buildset::create($name, $revision);
if (!empty($builders)) {
$builders = pickBuilders(BUILDERS_PATH, $builders);
} else {
$builders = pickBuildersIn(BUILDERS_PATH, '');
$builders = array_merge($builders, pickBuildersIn(BUILDERS_PATH, "$name/"));
}
foreach ($builders as $builderName) {
Build::create($buildset, $builderName);
}
print "Buildset ID: $buildset->buildsetid\n";
if (sizeof($builders) == 0) {
print "No builders were scheduled\n";
} else {
print "Scheduled " . sizeof($builders) . " builder"
. (sizeof($builders) == 1 ? '' : 's')
. ": " . join(', ', $builders) . "\n";
}
/**
* @brief Schedules builders in @p dir directory specified by their name.
*
* @param dir Directory to look for builders.
* @param names List of builder names (appended to @p dir by one).
*
* @returns Array of names of builders to schedule.
*/
function pickBuilders($dir, $names)
{
$builders = [];
foreach ($names as $name) {
$path = "$dir/$name";
if (!is_dir($path) && is_executable($path)) {
array_push($builders, $name);
}
}
return $builders;
}
/**
* @brief Schedules builders discovered in @p dir directory.
*
* @param dir Directory to look for builders.
* @param suffix Additional suffix for builders path (appended to @p dir).
*
* @returns Array of names of builders to schedule.
*/
function pickBuildersIn($dir, $suffix)
{
$builders = [];
$basePath = "$dir/$suffix";
if (is_dir($basePath) && $handle = opendir($basePath)) {
while (($entry = readdir($handle)) !== false) {
$path = "$basePath/$entry";
if (!is_dir($path) && $entry != '.' && $entry != '..' &&
is_executable($path)) {
$builderName = "$suffix$entry";
array_push($builders, $builderName);
}
}
closedir($handle);
}
return $builders;
}
?>
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