first commit
This commit is contained in:
commit
859da82a4c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
tasks/
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Charles
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# NanoCI
|
||||||
|
|
||||||
|
This is a small CI written in PHP, but can produce anything.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
Start off by making an environment variable AUTH_KEY.
|
||||||
|
|
||||||
|
Now, create a folder named `tasks/<TASKNAME>.task`.
|
||||||
|
|
||||||
|
Then, make a file in it called `TASK`, and executable.
|
||||||
|
|
||||||
|
This is a template:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
cd $(dirname ${BASH_SOURCE[0]})
|
||||||
|
rm -vfr artifacts
|
||||||
|
mkdir -p artifacts
|
||||||
|
```
|
||||||
|
|
||||||
|
Just place your stuff in `artifacts` when done.
|
||||||
|
|
||||||
|
Now, you can add a webhook which is `http://<SERVER_URL>/task.php?task=TASKNAME&authkey=CHANGEME`.
|
||||||
|
|
22
index.php
Normal file
22
index.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>NanoCI</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>NanoCI</h1>
|
||||||
|
<p>Task list. Click to view logs, artifacts, and the task code.</p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach (glob("tasks/*.task") as $task) {
|
||||||
|
$taskName = basename($task, ".task");
|
||||||
|
$safeTaskName = htmlspecialchars($taskName, ENT_QUOTES, "UTF-8");
|
||||||
|
echo "<li>";
|
||||||
|
echo '<a href="viewtask.php?task=' .
|
||||||
|
urlencode($taskName) .
|
||||||
|
'">' .
|
||||||
|
htmlspecialchars($safeTaskName, ENT_QUOTES, "UTF-8") .
|
||||||
|
"</a>";
|
||||||
|
echo "</li>";
|
||||||
|
} ?>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
24
task.php
Normal file
24
task.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
$authkey = getenv("AUTH_KEY");
|
||||||
|
if (!isset($_REQUEST["task"], $_REQUEST["authkey"])) {
|
||||||
|
die("Missing parameters.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$task = basename($_REQUEST["task"]);
|
||||||
|
$authkeyInput = $_REQUEST["authkey"];
|
||||||
|
|
||||||
|
if ($authkeyInput !== $authkey) {
|
||||||
|
die("Incorrect auth key.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$taskPath = "tasks/$task.task/TASK";
|
||||||
|
$logPath = "tasks/$task.task/LOG";
|
||||||
|
|
||||||
|
if (!is_file($taskPath)) {
|
||||||
|
die("Invalid task.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$escapedTaskPath = escapeshellarg($taskPath);
|
||||||
|
$escapedLogPath = escapeshellarg($logPath);
|
||||||
|
exec("nohup $escapedTaskPath > $escapedLogPath &");
|
||||||
|
?>
|
49
viewtask.php
Normal file
49
viewtask.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>View task</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>View task</h1>
|
||||||
|
<?php
|
||||||
|
$task = basename($_GET["task"]);
|
||||||
|
$taskDir = "tasks/$task.task";
|
||||||
|
|
||||||
|
if (!is_dir($taskDir)) {
|
||||||
|
die("Invalid task.");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<p><a href="<?php echo htmlspecialchars(
|
||||||
|
"$taskDir/LOG",
|
||||||
|
ENT_QUOTES,
|
||||||
|
"UTF-8"
|
||||||
|
); ?>">View logfile</a></p>
|
||||||
|
<p><a href="<?php echo htmlspecialchars(
|
||||||
|
"$taskDir/TASK",
|
||||||
|
ENT_QUOTES,
|
||||||
|
"UTF-8"
|
||||||
|
); ?>">View code</a></p>
|
||||||
|
<h2>Artifacts</h2>
|
||||||
|
<ul>
|
||||||
|
<?php
|
||||||
|
$artifactDir = "$taskDir/artifacts";
|
||||||
|
if (is_dir($artifactDir)) {
|
||||||
|
foreach (scandir($artifactDir) as $artifact) {
|
||||||
|
if ($artifact !== "." && $artifact !== "..") {
|
||||||
|
echo '<li><a href="' .
|
||||||
|
htmlspecialchars(
|
||||||
|
"$artifactDir/$artifact",
|
||||||
|
ENT_QUOTES,
|
||||||
|
"UTF-8"
|
||||||
|
) .
|
||||||
|
'">' .
|
||||||
|
htmlspecialchars($artifact, ENT_QUOTES, "UTF-8") .
|
||||||
|
"</a></li>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<li>No artifacts were found.</li>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user