Last active
April 6, 2022 23:46
-
-
Save PEMapModder/6ac745b5ff0283c8c02f to your computer and use it in GitHub Desktop.
StatsCore Travis-CI build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$extension = "phar"; | |
if(!isset($_POST["commit"], $_POST["branch"], $_POST["pr"], $_FILE["build"], $_POST["repo-id"])){ | |
echo "400 bad request - Insufficient parameters passed"; | |
http_response_code(400); | |
} | |
else{ | |
switch($_POST["repo-id"]){ | |
case "0": | |
$repo_url = "https://github.com/LegendOfMCPE/StatsCore"; | |
$repo_name = "StatsCore"; | |
break; | |
default: | |
echo "403 forbidden: You are not allowed to upload builds of this repo."; | |
http_response_code(403); | |
return; | |
} | |
@mkdir($dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . "builds" . DIRECTORY_SEPARATOR . $repo_name . DIRECTORY_SEPARATOR, 0777, true); | |
$branch = $_POST["branch"]; | |
$pr = $_POST["pr"]; | |
$commit = $_POST["commit"]; | |
$file = $dir . "$pr@$branch#$commit." . $extension; | |
if(is_file($file)){ | |
echo "403 forbidden - build already exists for such file"; | |
http_response_code(403); | |
} | |
else{ | |
$upload = $_FILES["build"]; | |
if($upload["error"] > 0){ | |
echo "400 bar request: Error with upload file: " . $file["error"]; | |
http_response_code(400); | |
} | |
else{ | |
if(match_github_commit($commit, $repo_url, $branch, $pr)){ | |
if(move_uploaded_file($upload["tmp_name"], $file)){ | |
echo "201 created - file $file is now in the archive."; | |
http_response_code(201); | |
} | |
else{ | |
echo "500 internal server error - cannot save file into archive"; | |
http_response_code(500); | |
} | |
} | |
else{ | |
echo "403 forbidden - the commit does not match the result from GitHub API"; | |
http_response_code(403); | |
} | |
} | |
} | |
} | |
function match_github_commit($commit, $url, $branch, $pr = "false"){ | |
if($pr === false or $pr === "false"){ | |
$data = cj_get("$url/branches/$branch"); | |
$real = $data["commit"]["sha"]; | |
return substr($real, 0, strlen($commit)) === $commit | |
or substr($commit, 0, strlen($real)) === $real; | |
} | |
else{ | |
$pr = cj_get("$url/pulls/$pr"); | |
$real = $pr["head"]["sha"]; | |
return substr($real, 0, strlen($commit)) === $commit | |
or substr($commit, 0, strlen($real)) === $real; | |
} | |
} | |
function cj_get($link){ | |
$ch = curl_init($link); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
return json_decode(curl_exec($link)); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head><title> | |
Downloads | |
</title></head> | |
<body> | |
<table> | |
<tr> | |
<th>Pull request ID</th> | |
<th>Branch</th> | |
<th>Commit</th> | |
<th>Download link</th> | |
</tr> | |
<?php | |
$ext = "phar"; | |
if(!isset($_GET["repo"])){ | |
$repo_name = "StatsCore"; | |
} | |
else{ | |
$repo_name = $_GET["repo"]; | |
} | |
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . "builds" . DIRECTORY_SEPARATOR . $repo_name . DIRECTORY_SEPARATOR; | |
if(is_dir($dir)){ | |
$directory = dir($dir); | |
$files = array(); | |
while(($file = $directory->read()) !== false){ | |
if(is_file($dir . $file) and strtolower(substr($file, -1 - strlen($ext))) === strtolower($ext)){ | |
$at = strpos($file, "@"); | |
$hash = strpos($file, "#"); | |
$pr = substr($file, 0, $at); | |
$branch = substr($file, $at + 1, $hash); | |
$commit = strstr(substr($file, $hash + 1), ".", true); | |
if(isset($_GET["pr"])){ | |
if(!in_array($pr, explode(",", $_GET["pr"]))){ | |
continue; | |
} | |
} | |
if(isset($_GET["branches"])){ | |
if(!in_array($branch, explode(",", $_GET["branches"]))){ | |
continue; | |
} | |
} | |
$files[filemtime($dir . $file)] = ["pr" => $pr, "branch" => $branch, "commit" => $commit]; | |
} | |
} | |
$directory->close(); | |
ksort($files); | |
foreach($files as $file){ | |
$pr = $file["pr"]; | |
$branch = $file["branch"]; | |
$commit = $file["commit"]; | |
echo "<tr>"; | |
echo "<td>" . (is_numeric($pr) ? "$pr":"N/A") . "</td>"; | |
echo "<td>$branch</td>"; | |
echo "<td>$commit</td>"; | |
echo "<td><a href=\"builds/$file\">Download</a></td>"; | |
echo "</tr>"; | |
} | |
} | |
?> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Main configuration file for PocketMine-MP | |
# These settings are the ones that cannot be included in server.properties | |
# Some of these settings are safe, others can break your server if modified incorrectly | |
settings: | |
shutdown-message: "Server closed" | |
#Allow listing plugins via Query | |
query-plugins: true | |
#Show a console message when a plugin uses deprecated API methods | |
deprecated-verbose: true | |
#Enable plugin and core profiling by default | |
enable-profiling: false | |
advanced-cache: false | |
upnp-forwarding: false | |
#Sends anonymous statistics to create usage reports | |
send-usage: true | |
#Number of AsyncTask workers | |
async-workers: 4 | |
debug: | |
#If > 1, it will show debug messages in the console | |
level: 1 | |
#Enables /status | |
commands: true | |
level-settings: | |
#The default format that levels will use when created | |
default-format: mcregion | |
#If true, converts from a format that is not the default to the default format on load | |
convert-format: false | |
chunk-sending: | |
#Amount of chunks sent to players per tick | |
per-tick: 4 | |
#Compression level used when sending chunks. Higher = more CPU, less bandwidth usage | |
compression-level: 7 | |
#Amount of chunks loaded around a player by the server, min. 56 as MC: PE 0.9.5 | |
#Increasing this more than 96 (as of MC: PE 0.9.5) can cause issues with the client ignoring chunks | |
max-chunks: 96 | |
chunk-ticking: | |
#Max amount of chunks processed each tick | |
per-tick: 80 | |
#Radius of chunks around a player to tick | |
tick-radius: 2 | |
light-updates: false | |
clear-tick-list: false | |
chunk-gc: | |
period-in-ticks: 600 | |
ticks-per: | |
animal-spawns: 400 | |
monster-spawns: 1 | |
autosave: 6000 | |
cache-cleanup: 900 | |
spawn-limits: | |
monsters: 70 | |
animals: 15 | |
water-animals: 5 | |
ambient: 15 | |
auto-report: | |
#Send crash reports for processing | |
enabled: true | |
send-code: true | |
send-settings: true | |
send-phpinfo: true | |
host: crash.pocketmine.net | |
auto-updater: | |
enabled: true | |
on-update: | |
warn-console: true | |
warn-ops: true | |
#Can be development, beta or stable. | |
preferred-channel: development | |
#If using a development version, it will suggest changing the channel | |
suggest-channels: false | |
host: www.pocketmine.net | |
aliases: | |
#Examples: | |
#showtheversion: version | |
#savestop: [save-all, stop] | |
worlds: | |
#These settings will override the generator set in server.properties and allows loading multiple levels | |
#Example: | |
#world: | |
# seed: 404 | |
# generator: FLAT:2;7,59x1,3x3,2;1;decoration(treecount=80 grasscount=45) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Properties Config file | |
#Thu Sep 4 18:23:08 CST 2014 | |
type=0 | |
server-name=LegendOfMCPE test server | |
server-port=19132 | |
memory-limit=512M | |
gamemode=0 | |
max-players=1 | |
spawn-protection=0 | |
white-list=off | |
enable-query=off | |
enable-rcon=off | |
send-usage=on | |
motd=LegendOfMCPE test server | |
announce-player-achievements=off | |
view-distance=8 | |
allow-flight=on | |
spawn-animals=on | |
spawn-mobs=on | |
hardcore=off | |
pvp=on | |
difficulty=1 | |
generator-settings= | |
level-name=world | |
level-seed= | |
level-type=DEFAULT | |
rcon.password=nk6jSjYjKU | |
auto-save=on | |
force-gamemode=off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$opts = getopt("", ["target:", "file:", "commit:", "branch::", "pr::"]); | |
$msg = "Parameters required: file, target, commit"; | |
$targetSite = isset($opts["target"]) ? $opts["target"] : die($msg); | |
$file = (isset($opts["file"]) and is_file($opts["file"])) ? realpath($opts["file"]) : die($msg); | |
$commit = isset($opts["commit"]) ? $opts["commit"] : die($msg); | |
$branch = isset($opts["branch"]) ? $opts["branch"] : "master"; | |
$pr = isset($opts["pr"]) ? $opts["pr"] : "false"; | |
$ch = curl_init($targetSite); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, ["build" => "@$file", "commit" => $commit, "branch" => $branch, "pr" => $pr, "repo_id" => "0"]); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 7500); | |
echo "Reply: "; | |
echo "\rGot reply! Result string below:" . curl_exec($ch); | |
curl_close($ch); | |
exit(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$DIR = dirname(__FILE__); | |
$XECON_DIR = getopt("", ["xecon:"])["xecon"]; | |
echo "Running in directory $DIR, xEcon directory $XECON_DIR...\n"; | |
echo "Compiling AutoKiller...\n"; | |
makePhar("$DIR/AutoKiller_container/AutoKiller", "$DIR/ServerDir/plugins/AutoKiller.phar", false); | |
echo "Compiling xEcon (Main)...\n"; | |
makePhar("$XECON_DIR/main/", "$DIR/ServerDir/plugins/xEcon_main.phar", false); | |
echo "Compiling xEcon (Tax)...\n"; | |
makePhar("$XECON_DIR/tax/", "$DIR/xEcon_tax.phar", false); | |
echo "Compiling xEcon (Shops)...\n"; | |
makePhar("$XECON_DIR/shops/", "$DIR/xEcon_shops.phar", false); | |
echo "Compiling xEcon (Jobs)...\n"; | |
makePhar("$XECON_DIR/jobs/", "$DIR/xEcon_jobs.phar", false); | |
echo "Testing vanilla xEcon...\n"; | |
exec($cmd = "php ServerDir/src/pocketmine/PocketMine.php"); | |
$list = [ | |
// "Tax" => "tax", | |
// "Shops" => "shops", | |
// "Jobs" => "jobs", | |
]; | |
foreach($list as $name => $fname){ | |
echo "Testing xEcon with $name...\n"; | |
$tempPath = "$DIR/ServerDir/plugins/xEcon_$fname.phar"; | |
copy("$DIR/xEcon_$fname.phar", $tempPath); | |
exec($cmd); | |
unlink($tempPath); | |
} | |
function makePhar($folderPath, $outputPath, $msg = true){ | |
$folderPath = realpath($folderPath); | |
$outputPath = realpath($outputPath); | |
@unlink($outputPath); | |
@mkdir(dirname($outputPath)); | |
$phar = new Phar($outputPath); | |
$phar->setStub('<?php __HALT_COMPILER();'); | |
$phar->setSignatureAlgorithm(Phar::SHA1); | |
$phar->startBuffering(); | |
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folderPath)) as $file){ | |
$path = rtrim(str_replace(["\\", $relativePath], ["/", ""], $file), "/"); | |
if($path{0} === "." or strpos($path, "/.") !== false){ | |
continue; | |
} | |
$phar->addFile($file, $path); | |
} | |
$phar->stopBuffering(); | |
if($msg){ | |
echo "Compiled $folderPath to $outputPath!\n"; | |
} | |
} |
What does this do? It looks cool, but I have no idea what it does :P .
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
holy cow :O