forked from jindrapetrik/jpexs-decompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_release_info.php
264 lines (237 loc) · 6.96 KB
/
format_release_info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?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),true);
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;
}
if(trim($x) === "") { //No Unreleased version data for example
return "";
}
$x = substr($x, strpos($x, "\n") + 1); //from start of the line
return $x;
}
$do_images = true;
if($do_images)
{
$ossupport_map=[
"windows" => "Works on Windows",
"linux" => "Works on Linux",
"macosx" => "Works with Mac OSX",
"java" => "Works on java"
];
}else{
$ossupport_map=[
"windows" => "Win",
"linux" => "Lin",
"macosx" => "Mac",
"java" => "Java"
];
}
$ICONS_URL = "https://github.com/jindrapetrik/jpexs-decompiler/wiki/images";
$body = "";
$is_prerelease = $changelog_section === "Unreleased";
if($is_prerelease) {
$body .= "## Prerelease WARNING\n".
"**This is prerelease nightly version. It should *NOT* be considered as stable.**\n\n";
}
$body .= "## Downloads:\n".
"\n".
"| Name | File | OS |\n".
"|---|---|---|\n";
$footer_links = [];
foreach ($files as $f) {
if($do_images) {
$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"]."** | ";
if($do_images)
{
$body .= "![".$f["type_name"]."][".$f["type_icon"]."_icon]";
}
$body .= " [".$f["file_name"]."] | ";
$ossup_titles = [];
foreach ($f["ossupport"] as $ossupport)
{
if($do_images)
{
$footer_links[$ossupport."_icon"] = $ICONS_URL."/os/24/".$ossupport.".png";
}
$ossupport_title = $ossupport_map[$ossupport];
$ossup_titles[] = $ossupport_title;
if($do_images)
{
$body .= "![".$ossupport_title."][".$ossupport."_icon]";
}
}
if(!$do_images)
{
$body .= implode(", ",$ossup_titles);
}
$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)
{
if($is_prerelease)
{
//[Unreleased section may be missing]
$changelog_data = "";
}
else
{
fwrite(STDERR, "Cannot load changelog data\n");
exit(1);
}
}
$full_changelog = file_get_contents($changelog_path);
if(preg_match_all('/\[([^\]]+)\][^(]/', $changelog_data."\n",$m))
{
$references = $m[1];
foreach($references as $r)
{
if(preg_match("/\[".preg_quote($r,"/")."\]:(.*)/", $full_changelog,$m2)){
$referenced_link = trim($m2[1]);
$footer_links[$r] = $referenced_link;
}
}
}
$body .= "\n";
if($is_prerelease)
{
$body .= "## What's new since last stable version:\n";
}else{
$body .= "## What's new:\n";
}
if($changelog_data === "")
{
$body .= "No notable changes yet\n";
}
$body .= $changelog_data;
$body .= "\n";
foreach($footer_links as $title=>$link)
{
$body .= "[$title]: $link\n";
}
echo $body;