Skip to content

Commit

Permalink
Merge pull request #174 from photonle/development
Browse files Browse the repository at this point in the history
Push the new builders because we kinda need them for the next release thanks.
  • Loading branch information
JoshPiper authored Nov 21, 2020
2 parents f4afc26 + 19c66b0 commit 343f49e
Show file tree
Hide file tree
Showing 12 changed files with 514 additions and 35 deletions.
9 changes: 0 additions & 9 deletions .github/builder/composer.json

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include __DIR__ . '/vendor/autoload.php';
use GmodStore\GMad\{AddonWriter, AddonMeta};

$photon = realpath(__DIR__ . '/../../');
$photon = realpath(__DIR__ . '/../../../');
$pl = strlen($photon) + 1;
$folders = ['lua', 'materials', 'models', 'sound'];

Expand Down
5 changes: 5 additions & 0 deletions .github/builder/gma/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"gmodstore/php-gmad": "dev-master"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .github/builder/update/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.phar
/vendor/
/.idea/workspace.xml
156 changes: 156 additions & 0 deletions .github/builder/update/build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env php
<?php

use Symfony\Component\Yaml\Yaml;

require __DIR__ . '/vendor/autoload.php';

$types = json_decode(file_get_contents(__DIR__ . '/types.json'), true);
$categories = json_decode(file_get_contents(__DIR__ . '/categories.json'), true);
$release = json_decode($_SERVER['RELEASE_CONTEXT'], true);

$body = $release['body'];
$title = $release['name'];
$date = $release['published_at'];
$tag = $release['tag_name'];
if (stripos($tag, 'v') === 0){
$tag = substr($tag, 1);
}

$lines = explode("\n", $body);
$lines = array_map('trim', $lines);
$lines = array_filter($lines);

$titleMatch = '';
$subTitleMatch = '';
$itemMatch = '-';

$header = $lines[0];
if (stripos($header, '**') === 0){
// We start with a **.
$titleMatch = '**';
} elseif (stripos($header, '*') === 0){
$titleMatch = '*';
}
if ($titleMatch === ''){
$titleMatch = false;
echo "Assuming single-category operation.";
} elseif ($titleMatch === '**'){
$subTitleMatch = '*';
}
$titleMatchLen = $titleMatch ? strlen($titleMatch) : 0;
$itemMatchLen = strlen($itemMatch);

function strcontains(string $haystack, string $needle): bool {
return stripos($haystack, $needle) !== false;
}

function resolveLine($line){
global $types;

$powers = $types['powers'];

$calc = [];
$classes = $line['class'];

$category = $classes['category'];
if (isset($types['category'][$category])){
$type = $types['category'][$category];
$calc[$type] = ($calc[$type] ?? 0) + $powers['category'];
}

if (isset($classes['tag'], $types['class'][$classes['tag']])){
$class = $types['class'][$classes['tag']];
foreach ($class as $type){
$calc[$type] = ($calc[$type] ?? 0) + $powers['class'];
}
}

foreach ($classes['words'] as $type){
$calc[$type] = ($calc[$type] ?? 0) + $powers['word'];
}

if (empty($calc)){
$line['class'] = $types['default'];
echo "'{$line['text']}' failed automatic resolution, fell back to default {$line['class']}\n";
} else {
$keys = array_keys($calc, max($calc));
if (count($keys) === 1){
$line['class'] = $keys[0];
} else {
$keys = array_flip($keys);
$keys = array_intersect_key($types['fallback'], $keys);
$key = min($keys);
$keys = array_flip($keys);
$line['class'] = $keys[$key];
echo "'{$line['text']}' failed automatic resolution, fallback sorting chose {$line['class']}\n";
}
}
$line['change'] = $line['text'];
unset($line['text']);
$line['type'] = $line['class'];
unset($line['class']);

return $line;
}

$output = [];
$category = 'fixes';
foreach ($lines as $line){
if ($titleMatch && stripos($line, $titleMatch) === 0){
$line = substr($line, $titleMatchLen, -$titleMatchLen);
if (substr($line, -1) === ':'){$line = substr($line, 0, -1);}
$line = trim($line);
$category = $categories[$line] ?? $line;
$output[$category] = $output[$category] ?? [];
echo "Set new Category: {$category}\n";
} elseif (stripos($line, $itemMatch) === 0){
$line = substr($line, $itemMatchLen);
$line = trim($line);

$class = [];
if (stripos($line, '[') === 0){
$end = stripos($line, ']');
if ($end !== false){
$class['tag'] = substr($line, 1, $end - 1);
$line = substr($line, $end + 1);
$line = trim($line);
}
}
$class['category'] = $category;
$class['words'] = [];

foreach ($types['words'] as $word => $type){
if (strcontains($line, $word)){
$class['words'][] = $type;
}
}

$output[$category][] = ['class' => $class, 'text' => $line];
} /** @noinspection PhpStatementHasEmptyBodyInspection */ elseif ($subTitleMatch !== '' && stripos($line, $subTitleMatch) === 0){
// Ignore Subtitles.
} else {
echo "\tUnknown Line Type! {$line}\n";
}
}

foreach ($output as &$category){
foreach ($category as &$change){
$change = resolveLine($change);
}
}

$yml = [];
if ($title && $title !== ''){$yml['name'] = $title;}
$yml['date'] = DateTime::createFromFormat(DateTime::RFC3339, $date)->format('Y-m-d H:i');
if (!empty($output)){$yml['changes'] = $output;}

$yml = Yaml::dump($yml, 2, 2, Yaml::DUMP_OBJECT_AS_MAP);
$yml = trim($yml);
$html = <<<EOF
---
{$yml}
---
EOF;

file_put_contents(__DIR__ . '/' . $tag . '.html', $html);
14 changes: 14 additions & 0 deletions .github/builder/update/categories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Breaking Changes": "breaking",
"Deprecation Warnings": "deprecated",
"Features": "features",
"Commands & Settings": "commands",
"Commands": "commands",
"Settings": "commands",
"Bug Fixes": "fixes",
"Fixes": "fixes",
"Core Library": "library",
"Library": "library",
"GitHub": "github",
"Changes": "changes"
}
16 changes: 16 additions & 0 deletions .github/builder/update/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "photonle/update-builder",
"description": "A builder to build photon menu files from github releases.",
"type": "project",
"require": {
"symfony/yaml": "^5.1"
},
"license": "ISC",
"authors": [
{
"name": "John Internet",
"email": "[email protected]"
}
],
"minimum-stability": "stable"
}
Loading

0 comments on commit 343f49e

Please sign in to comment.