Files
jpexs-decompiler/travis/format_release_info.php
2018-01-14 22:45:06 +01:00

192 lines
5.5 KiB
PHP

<?php
function print_usage()
{
fwrite(STDERR,
"USAGE:\n"
. " php format_release_info.php -filever filever_tag changelog_section, version_tag, changelog_path, github_repo\n"
. " OR \n"
. " php format_release_info.php -json jsondatafile changelog_section, version_tag, changelog_path, github_repo\n"
);
}
if ($argc < 7) {
fwrite(STDERR, "Invalid arguments:\n");
print_usage();
exit(1);
}
$load_from = $argv[1];
if(!in_array($load_from,["-filever","-json"]))
{
print_usage();
exit(1);
}
if($load_from == "-filever")
{
$filever_tag = $argv[2]; //10.0.0 or 10.0.0_nightly123
$files = [
[
"file_name" => "ffdec_${filever_tag}_setup.exe",
"ossupport" => ["windows"],
"type_name" => "Installer (Windows)",
"type_icon" => "setup"
],
[
"file_name" => "ffdec_${filever_tag}.zip",
"ossupport" => ["windows", "linux", "macosx"],
"type_name" => "ZIP (Windows, Linux, Mac OS)",
"type_icon" => "zip"
],
[
"file_name" => "ffdec_${filever_tag}.deb",
"ossupport" => ["linux"],
"type_name" => "DEB package (Linux)",
"type_icon" => "deb"
],
[
"file_name" => "ffdec_${filever_tag}.pkg",
"ossupport" => ["macosx"],
"type_name" => "Mac OS X Installer (pkg)",
"type_icon" => "osx"
],
[
"file_name" => "ffdec_${filever_tag}_macosx.zip",
"ossupport" => ["macosx"],
"type_name" => "Mac OS X Application (zipped)",
"type_icon" => "zip"
],
[
"file_name" => "ffdec_${filever_tag}_lang.zip",
"ossupport" => ["java"],
"type_name" => "Language pack for translators (zipped)",
"type_icon" => "zip"
],
[
"file_name" => "ffdec_lib_${filever_tag}.zip",
"ossupport" => ["java"],
"type_name" => "Library only (Java SE) - Zipped",
"type_icon" => "zip"
],
];
}
else //-json
{
$json_file = $argv[2];
if(!file_exists($json_file)){
fwrite(STDERR,"Datafile $json_file does not exist\n");
exit(1);
}
$files = json_decode(file_get_contents($json_file));
if($files === null)
{
fwrite(STDERR,"Cannot load data from $json_file\n");
exit(1);
}
}
$changelog_section = $argv[3]; //10.0.0 or "alpha 1" or "Unreleased" or "1.5.0 update 1"
$version_tag = $argv[4]; //"version10.0.0" or "nightly165" or "alpha1" or "version1.8.8u2"
$changelog_path = $argv[5]; // ./CHANGELOG.md
$github_repo = $argv[6]; // "jindrapetrik/jpexs-decompiler"
function get_string_between($x, $before, $after) {
$pos_before = strpos($x, $before);
if ($pos_before === false) {
return false;
}
$x = substr($x, $pos_before + strlen($before));
$pos_after = strpos($x, $after);
if ($pos_after === false) {
return false;
}
$x = substr($x, 0, $pos_after);
return $x;
}
function get_string_between_multiple_after($x, $before, array $afters) {
$ret = false;
foreach ($afters as $after) {
$ret = get_string_between($x, $before, $after);
if ($ret !== false) {
break;
}
}
return $ret;
}
function get_changelog_section($changelog_file, $section_name) {
if (!file_exists($changelog_file)) {
return false;
}
$txt = file_get_contents($changelog_file);
$txt = str_replace("\r\n", "\n", $txt) . "--EOF--";
$afters = ["\n## [", "\n[", "--EOF--"];
$x = get_string_between_multiple_after($txt, "\n## [$section_name]", $afters);
if ($x === false) {
return false;
}
$x = substr($x, strpos($x, "\n") + 1); //from start of the line
return $x;
}
$ossupport_map=[
"windows" => "Works on Windows",
"linux" => "Works on Linux",
"macosx" => "Works with Mac OSX",
"java" => "Works on java"
];
$ICONS_URL = "https://github.com/jindrapetrik/jpexs-decompiler/wiki/images";
$body = "";
$body .= "## Downloads:\n".
"\n".
"| Name | File | OS |\n".
"|---|---|---|\n";
$footer_links = [];
foreach ($files as $f) {
$footer_links[$f["type_icon"]."_icon"] = $ICONS_URL."/downloads/16/".$f["type_icon"].".png";
$footer_links[$f["file_name"]] = 'https://github.com/'.$github_repo.'/releases/download/'.$version_tag.'/'.$f["file_name"];
$body .= "| **".$f["type_name"]."** | ![".$f["type_name"]."][".$f["type_icon"]."_icon] [".$f["file_name"]."] | ";
foreach ($f["ossupport"] as $ossupport)
{
$footer_links[$ossupport."_icon"] = $ICONS_URL."/os/24/".$ossupport.".png";
$ossupport_title = $ossupport_map[$ossupport];
$body .= "![".$ossupport_title."][".$ossupport."_icon]";
}
$body .= " |\n";
}
$all_ossupport = [];
foreach ($files as $f) {
if (!in_array($f["ossupport"], $all_ossupport)) {
$all_ossupport[] = $f["ossupport"];
}
}
$changelog_data = get_changelog_section($changelog_path,$changelog_section);
if($changelog_data === false)
{
fwrite(STDERR, "Cannot load changelog data\n");
exit(1);
}
$body .= "\n";
$body .= "## What's new:\n";
$body .= $changelog_data;
$body .= "\n";
foreach($footer_links as $title=>$link)
{
$body .= "[$title]: $link\n";
}
echo $body;