From 45afb84d887f908cbbdc2e6dc372d78f75e6d3ee Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:18:37 +0200 Subject: [PATCH 01/53] Create build-git-history-graph.php --- monorepo/scripts/build-git-history-graph.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 monorepo/scripts/build-git-history-graph.php diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php new file mode 100644 index 00000000000..b3d9bbc7f37 --- /dev/null +++ b/monorepo/scripts/build-git-history-graph.php @@ -0,0 +1 @@ + Date: Tue, 9 Jul 2024 13:18:48 +0200 Subject: [PATCH 02/53] Add base documentation --- monorepo/scripts/build-git-history-graph.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index b3d9bbc7f37..52650257679 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -1 +1,8 @@ Date: Tue, 9 Jul 2024 13:19:36 +0200 Subject: [PATCH 03/53] Add job to build the Git history graph --- .github/workflows/continuous-integration.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 708fa4f6925..a21dfcae6e8 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -410,6 +410,26 @@ jobs: path: '_site' + + build-git-history-graph: + runs-on: ubuntu-latest + needs: run-smoke-tests + + steps: + - uses: actions/checkout@v4 + with: + # We need to fetch all history to generate the graph + fetch-depth: 0 + + - name: Generate Git history graph + run: php monorepo/scripts/build-git-history-graph.php + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: 'git-history-graph' + + upload-generated-reports: environment: name: live-reports From fddc59b503a774047aedbad3364d7c6905360f09 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:19:52 +0200 Subject: [PATCH 04/53] Deploy the Git history graph --- .github/workflows/continuous-integration.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a21dfcae6e8..e8ef26215ef 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -443,6 +443,7 @@ jobs: - build-upcoming-documentation - build-preview-site - build-test-fixture-docs + - build-git-history-graph steps: - uses: actions/checkout@v4 @@ -456,6 +457,7 @@ jobs: rm -rf master/api-docs && mkdir master/api-docs rm -rf master/preview && mkdir master/preview rm -rf master/test-fixtures && mkdir master/test-fixtures + rm -rf master/git && mkdir master/git - name: Download coverage report artifact uses: actions/download-artifact@v4 @@ -487,6 +489,11 @@ jobs: name: test-fixture-docs path: master/test-fixtures/docs + - name: Download Git history graph artifact + uses: actions/download-artifact@v4 + with: + name: git-history-graph + - name: Create README.md run: echo '# CI/CD generated reports for [${{ github.sha }}](https://github.com/hydephp/develop/commit/${{ github.sha }})' > master/README.md From 37956ba445340a9de208d5a012f4d48debb50b01 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:21:15 +0200 Subject: [PATCH 05/53] Add strict types declaration --- monorepo/scripts/build-git-history-graph.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 52650257679..3a2c14a7443 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -1,5 +1,7 @@ Date: Tue, 9 Jul 2024 13:25:13 +0200 Subject: [PATCH 06/53] Fix formatting --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e8ef26215ef..86698303a11 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -410,7 +410,6 @@ jobs: path: '_site' - build-git-history-graph: runs-on: ubuntu-latest needs: run-smoke-tests From b72fd758e220cbeab504b87b1cb818082845845b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:25:17 +0200 Subject: [PATCH 07/53] Set the path --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 86698303a11..48326a19669 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -427,6 +427,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: 'git-history-graph' + path: 'monorepo/scripts/graphs' upload-generated-reports: From e588a0d4027b82c00850280c636d4d12be8a0701 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:25:39 +0200 Subject: [PATCH 08/53] Add temporary job to test the workflow --- .github/workflows/static-analysis.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 8912950308e..ff156da73b2 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -40,3 +40,22 @@ jobs: - name: Run Pest Type Coverage run: ./vendor/bin/pest --type-coverage + + + build-git-history-graph: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + # We need to fetch all history to generate the graph + fetch-depth: 0 + + - name: Generate Git history graph + run: php monorepo/scripts/build-git-history-graph.php + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: 'git-history-graph' + path: 'monorepo/scripts/graphs' From 6509e451c1b39d9aafa82fde887a62c864ed1ae6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:29:10 +0200 Subject: [PATCH 09/53] Create the graphs --- monorepo/scripts/build-git-history-graph.php | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 3a2c14a7443..e11f0815639 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -8,3 +8,33 @@ * @link https://hydephp.github.io/develop/master/git/history-graph.html * @link https://hydephp.github.io/develop/master/git/history-graph.txt */ + +echo 'Building the Git history graph...' . PHP_EOL; + +if (!file_exists(__DIR__ . '/graphs')) { + mkdir(__DIR__ . '/graphs'); +} + +echo 'Building the plaintext Git history graph... (This may take a while)' . PHP_EOL; +$text = shell_exec('git log --graph --oneline --all'); +echo 'Saving the plaintext Git history graph...' . PHP_EOL; +file_put_contents(__DIR__ . '/graphs/history-graph.txt', $text); + +echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; +$html = shell_exec('git log --graph --oneline --all --color=always'); +echo 'Converting ANSI color codes to HTML...' . PHP_EOL; +$html = ansiToHtml($html); +echo 'Saving the HTML Git history graph...' . PHP_EOL; +file_put_contents(__DIR__ . '/graphs/history-graph.html', $html); + +echo 'Git history graphs built successfully!' . PHP_EOL; + +function ansiToHtml(string $ansi): string +{ + $ansi = htmlspecialchars($ansi, ENT_QUOTES | ENT_HTML5, 'UTF-8'); + $ansi = preg_replace('/\e\[(\d+)(;\d+)*m/', '', $ansi); + $ansi = preg_replace('/\n/', '
', $ansi); + $ansi = '' . $ansi . ''; + + return $ansi; +} From 3604bd30d8c13df4c99da1d8657c6af41596f503 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:31:25 +0200 Subject: [PATCH 10/53] Extract helper --- monorepo/scripts/build-git-history-graph.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index e11f0815639..6a3975e6fa1 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -23,12 +23,17 @@ echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); echo 'Converting ANSI color codes to HTML...' . PHP_EOL; -$html = ansiToHtml($html); +$html = processHtml($html); echo 'Saving the HTML Git history graph...' . PHP_EOL; file_put_contents(__DIR__ . '/graphs/history-graph.html', $html); echo 'Git history graphs built successfully!' . PHP_EOL; +function processHtml(string $html): string +{ + return ansiToHtml($html); +} + function ansiToHtml(string $ansi): string { $ansi = htmlspecialchars($ansi, ENT_QUOTES | ENT_HTML5, 'UTF-8'); From 9c188cac3bb536f099c2e528064558205b2aad5b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:31:42 +0200 Subject: [PATCH 11/53] Free up memory --- monorepo/scripts/build-git-history-graph.php | 1 + 1 file changed, 1 insertion(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 6a3975e6fa1..43bfb2b4179 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -19,6 +19,7 @@ $text = shell_exec('git log --graph --oneline --all'); echo 'Saving the plaintext Git history graph...' . PHP_EOL; file_put_contents(__DIR__ . '/graphs/history-graph.txt', $text); +unset($text); // Free up memory echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); From 5368e348fc6a46bc2b28b2c862077c4ac60c646f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:36:56 +0200 Subject: [PATCH 12/53] Process in chunks to prevent memory issues --- monorepo/scripts/build-git-history-graph.php | 37 +++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 43bfb2b4179..85fbb25c13a 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -32,7 +32,42 @@ function processHtml(string $html): string { - return ansiToHtml($html); + // We need to run the ANSI to HTML conversion in chunks to prevent memory issues + + $html = explode("\n", $html); + + $chunks = []; + + $chunk = ''; + + foreach ($html as $line) { + $chunk .= $line . "\n"; + + if (strlen($chunk) > 100000) { + $chunks[] = $chunk; + $chunk = ''; + } + } + + if ($chunk !== '') { + $chunks[] = $chunk; + } + + $html = ''; + + $message = 'Processing '.count($chunks).' chunks...'; + echo $message; + + foreach ($chunks as $index => $chunk) { + // Progress indicator + echo "\033[0K\rProcessing chunk ".($index + 1).' of '.count($chunks).'...'; + + $html .= ansiToHtml($chunk); + } + + echo PHP_EOL; + + return $html; } function ansiToHtml(string $ansi): string From 48667b19d8c0fc6212d7f9db359540a8b90bc290 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:39:10 +0200 Subject: [PATCH 13/53] Wrap the HTML --- monorepo/scripts/build-git-history-graph.php | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 85fbb25c13a..91214148944 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -25,6 +25,7 @@ $html = shell_exec('git log --graph --oneline --all --color=always'); echo 'Converting ANSI color codes to HTML...' . PHP_EOL; $html = processHtml($html); +$html = wrapHtml($html); echo 'Saving the HTML Git history graph...' . PHP_EOL; file_put_contents(__DIR__ . '/graphs/history-graph.html', $html); @@ -79,3 +80,28 @@ function ansiToHtml(string $ansi): string return $ansi; } + +function wrapHtml(string $html): string +{ + return << + + + + Git History Graph + + + + $html + + HTML; +} From eaf185455cb639793e4513c41c4343580f629e99 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 13:39:53 +0200 Subject: [PATCH 14/53] Preserve newlines --- monorepo/scripts/build-git-history-graph.php | 1 - 1 file changed, 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 91214148944..8830b76ad72 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -75,7 +75,6 @@ function ansiToHtml(string $ansi): string { $ansi = htmlspecialchars($ansi, ENT_QUOTES | ENT_HTML5, 'UTF-8'); $ansi = preg_replace('/\e\[(\d+)(;\d+)*m/', '
', $ansi); - $ansi = preg_replace('/\n/', '
', $ansi); $ansi = '' . $ansi . ''; return $ansi; From 2561537e7effbc76f663e874f882f581638e0c30 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:15:40 +0200 Subject: [PATCH 15/53] Improved ANSI formatting --- monorepo/scripts/build-git-history-graph.php | 44 ++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 8830b76ad72..4ce1dbaf507 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -73,9 +73,47 @@ function processHtml(string $html): string function ansiToHtml(string $ansi): string { - $ansi = htmlspecialchars($ansi, ENT_QUOTES | ENT_HTML5, 'UTF-8'); - $ansi = preg_replace('/\e\[(\d+)(;\d+)*m/', '
', $ansi); - $ansi = '' . $ansi . ''; + // extract ansi colors to colored spans + + $ansi = preg_replace('/\x1b\[(\d+)(;\d+)*m/', '', $ansi); + + // replace with real colors (now it's span style="color: 32" etc) + + $colors = [ + 1 => '#800000', + 30 => '#000000', + 31 => '#800000', + 32 => '#008000', + 33 => '#808000', + 34 => '#000080', + 35 => '#800080', + 36 => '#008080', + 37 => '#c0c0c0', + 90 => '#808080', + 91 => '#ff0000', + 92 => '#00ff00', + 93 => '#ffff00', + 94 => '#0000ff', + 95 => '#ff00ff', + 96 => '#00ffff', + 97 => '#ffffff', + ]; + + $ansi = preg_replace_callback('//', function ($matches) use ($colors) { + return ''; + }, $ansi); + + $ansi = str_replace("\033[m", '', $ansi); + + // Clear star formatting +// $ansi = str_replace('| * ', '| * ', $ansi); +// $ansi = str_replace('*', '*', $ansi); + + // Add the opening span tag to the beginning of the string + $ansi = ''.$ansi; + + // Add the closing span tag to the end of the string + $ansi .= ''; return $ansi; } From bf6be8374de1324d0663579610d4800dbbfac48c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:16:18 +0200 Subject: [PATCH 16/53] Cleanup formatting --- monorepo/scripts/build-git-history-graph.php | 37 +++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 4ce1dbaf507..278c8b244fc 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -8,28 +8,27 @@ * @link https://hydephp.github.io/develop/master/git/history-graph.html * @link https://hydephp.github.io/develop/master/git/history-graph.txt */ +echo 'Building the Git history graph...'.PHP_EOL; -echo 'Building the Git history graph...' . PHP_EOL; - -if (!file_exists(__DIR__ . '/graphs')) { - mkdir(__DIR__ . '/graphs'); +if (! file_exists(__DIR__.'/graphs')) { + mkdir(__DIR__.'/graphs'); } -echo 'Building the plaintext Git history graph... (This may take a while)' . PHP_EOL; +echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; $text = shell_exec('git log --graph --oneline --all'); -echo 'Saving the plaintext Git history graph...' . PHP_EOL; -file_put_contents(__DIR__ . '/graphs/history-graph.txt', $text); +echo 'Saving the plaintext Git history graph...'.PHP_EOL; +file_put_contents(__DIR__.'/graphs/history-graph.txt', $text); unset($text); // Free up memory -echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; +echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); -echo 'Converting ANSI color codes to HTML...' . PHP_EOL; +echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); $html = wrapHtml($html); -echo 'Saving the HTML Git history graph...' . PHP_EOL; -file_put_contents(__DIR__ . '/graphs/history-graph.html', $html); +echo 'Saving the HTML Git history graph...'.PHP_EOL; +file_put_contents(__DIR__.'/graphs/history-graph.html', $html); -echo 'Git history graphs built successfully!' . PHP_EOL; +echo 'Git history graphs built successfully!'.PHP_EOL; function processHtml(string $html): string { @@ -42,7 +41,7 @@ function processHtml(string $html): string $chunk = ''; foreach ($html as $line) { - $chunk .= $line . "\n"; + $chunk .= $line."\n"; if (strlen($chunk) > 100000) { $chunks[] = $chunk; @@ -73,12 +72,8 @@ function processHtml(string $html): string function ansiToHtml(string $ansi): string { - // extract ansi colors to colored spans - $ansi = preg_replace('/\x1b\[(\d+)(;\d+)*m/', '', $ansi); - // replace with real colors (now it's span style="color: 32" etc) - $colors = [ 1 => '#800000', 30 => '#000000', @@ -104,15 +99,7 @@ function ansiToHtml(string $ansi): string }, $ansi); $ansi = str_replace("\033[m", '', $ansi); - - // Clear star formatting -// $ansi = str_replace('| * ', '| * ', $ansi); -// $ansi = str_replace('*', '*', $ansi); - - // Add the opening span tag to the beginning of the string $ansi = ''.$ansi; - - // Add the closing span tag to the end of the string $ansi .= ''; return $ansi; From 6ee606b7d7cc54ddb353226344cbff5ef13b461c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:18:45 +0200 Subject: [PATCH 17/53] Introduce local variable --- monorepo/scripts/build-git-history-graph.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 278c8b244fc..0d84c7d4d52 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -40,10 +40,12 @@ function processHtml(string $html): string $chunk = ''; + $chunkSize = 100000; + foreach ($html as $line) { $chunk .= $line."\n"; - if (strlen($chunk) > 100000) { + if (strlen($chunk) > $chunkSize) { $chunks[] = $chunk; $chunk = ''; } From 889f42ab7bd78062b97cbd9147a68b00a610618b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:19:03 +0200 Subject: [PATCH 18/53] Lower chunk size --- monorepo/scripts/build-git-history-graph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 0d84c7d4d52..b61f3f29e6c 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -40,7 +40,7 @@ function processHtml(string $html): string $chunk = ''; - $chunkSize = 100000; + $chunkSize = 10000; foreach ($html as $line) { $chunk .= $line."\n"; From ad6d29ca2574e2d6672bc93e120b8442eda361a3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:19:12 +0200 Subject: [PATCH 19/53] Revert "Lower chunk size" This reverts commit 889f42ab7bd78062b97cbd9147a68b00a610618b. --- monorepo/scripts/build-git-history-graph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index b61f3f29e6c..0d84c7d4d52 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -40,7 +40,7 @@ function processHtml(string $html): string $chunk = ''; - $chunkSize = 10000; + $chunkSize = 100000; foreach ($html as $line) { $chunk .= $line."\n"; From 85483fa7b6950e4806bfc734b4619dc555c37d27 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:22:42 +0200 Subject: [PATCH 20/53] Buffer chunks to disk to free up memory --- monorepo/scripts/build-git-history-graph.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 0d84c7d4d52..79a3e25583c 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -55,8 +55,6 @@ function processHtml(string $html): string $chunks[] = $chunk; } - $html = ''; - $message = 'Processing '.count($chunks).' chunks...'; echo $message; @@ -64,9 +62,17 @@ function processHtml(string $html): string // Progress indicator echo "\033[0K\rProcessing chunk ".($index + 1).' of '.count($chunks).'...'; - $html .= ansiToHtml($chunk); + $chunkHtml = ansiToHtml($chunk); + file_put_contents('chunks.temp', $chunkHtml, FILE_APPEND); + + // Free up memory + unset($chunk); + unset($chunkHtml); } + $html = file_get_contents('chunks.temp'); + unlink('chunks.temp'); + echo PHP_EOL; return $html; From 285d098cdf27f74906306a27685c12938f4165a7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:29:58 +0200 Subject: [PATCH 21/53] Add main element --- monorepo/scripts/build-git-history-graph.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 79a3e25583c..997cee77dcc 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -133,7 +133,9 @@ function wrapHtml(string $html): string +
$html +
HTML; } From bf241417517b0b4519c989d3cf41c5f40952c3b0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:47:53 +0200 Subject: [PATCH 22/53] Generate header --- monorepo/scripts/build-git-history-graph.php | 53 +++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 997cee77dcc..77041984a6e 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -24,8 +24,14 @@ $html = shell_exec('git log --graph --oneline --all --color=always'); echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); -$html = wrapHtml($html); -echo 'Saving the HTML Git history graph...'.PHP_EOL; +echo 'Generating header...'; +$graph = file_get_contents(__DIR__.'/graphs/history-graph.txt'); +$header = generateHeader($graph); +echo ' Done.'.PHP_EOL; +echo 'Wrapping the HTML...'; +$html = wrapHtml($html, $header); +echo ' Done.'.PHP_EOL; +echo 'Saving the HTML Git history graph...'.PHP_EOL; file_put_contents(__DIR__.'/graphs/history-graph.html', $html); echo 'Git history graphs built successfully!'.PHP_EOL; @@ -113,7 +119,7 @@ function ansiToHtml(string $ansi): string return $ansi; } -function wrapHtml(string $html): string +function wrapHtml(string $html, string $header): string { return << @@ -123,19 +129,52 @@ function wrapHtml(string $html): string Git History Graph +
$header
$html
HTML; } + +function generateHeader(string $text): string +{ + $commitCount = countCommitLines($text); + unset($text); // Free up memory + + $head = trim(shell_exec('git rev-parse --short HEAD')); + $date = date('Y-m-d H:i:s'); + return << Date: Tue, 9 Jul 2024 14:48:01 +0200 Subject: [PATCH 23/53] Formatting --- monorepo/scripts/build-git-history-graph.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 77041984a6e..7656e5434e6 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -13,16 +13,18 @@ if (! file_exists(__DIR__.'/graphs')) { mkdir(__DIR__.'/graphs'); } +$html = file_get_contents('H:\monorepo\graph.ansi'); -echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; +echo 'Building the plaintext Git history graph... (This may take a while)' . PHP_EOL; $text = shell_exec('git log --graph --oneline --all'); -echo 'Saving the plaintext Git history graph...'.PHP_EOL; -file_put_contents(__DIR__.'/graphs/history-graph.txt', $text); +echo 'Saving the plaintext Git history graph...' . PHP_EOL; +file_put_contents(__DIR__ . '/graphs/history-graph.txt', $text); unset($text); // Free up memory -echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; +echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); -echo 'Converting ANSI color codes to HTML...'.PHP_EOL; +file_put_contents('H:\monorepo\graph.ansi', $html); +echo 'Converting ANSI color codes to HTML...' . PHP_EOL; $html = processHtml($html); echo 'Generating header...'; $graph = file_get_contents(__DIR__.'/graphs/history-graph.txt'); From 299b6988fc743bb094f35de8701d0c409f4fccbe Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 9 Jul 2024 12:50:57 +0000 Subject: [PATCH 24/53] Apply fixes from StyleCI --- monorepo/scripts/build-git-history-graph.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 7656e5434e6..f86d83e9dfd 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -15,16 +15,16 @@ } $html = file_get_contents('H:\monorepo\graph.ansi'); -echo 'Building the plaintext Git history graph... (This may take a while)' . PHP_EOL; +echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; $text = shell_exec('git log --graph --oneline --all'); -echo 'Saving the plaintext Git history graph...' . PHP_EOL; -file_put_contents(__DIR__ . '/graphs/history-graph.txt', $text); +echo 'Saving the plaintext Git history graph...'.PHP_EOL; +file_put_contents(__DIR__.'/graphs/history-graph.txt', $text); unset($text); // Free up memory -echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; +echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); file_put_contents('H:\monorepo\graph.ansi', $html); -echo 'Converting ANSI color codes to HTML...' . PHP_EOL; +echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); echo 'Generating header...'; $graph = file_get_contents(__DIR__.'/graphs/history-graph.txt'); @@ -156,6 +156,7 @@ function generateHeader(string $text): string $head = trim(shell_exec('git rev-parse --short HEAD')); $date = date('Y-m-d H:i:s'); + return << Date: Tue, 9 Jul 2024 14:52:26 +0200 Subject: [PATCH 25/53] Free up memory --- monorepo/scripts/build-git-history-graph.php | 1 + 1 file changed, 1 insertion(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 7656e5434e6..8faee283f4e 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -29,6 +29,7 @@ echo 'Generating header...'; $graph = file_get_contents(__DIR__.'/graphs/history-graph.txt'); $header = generateHeader($graph); +unset($graph); // Free up memory echo ' Done.'.PHP_EOL; echo 'Wrapping the HTML...'; $html = wrapHtml($html, $header); From e85669474aeed7d6432399cdc6655125066d587b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:54:29 +0200 Subject: [PATCH 26/53] Free up memory --- monorepo/scripts/build-git-history-graph.php | 1 + 1 file changed, 1 insertion(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 8faee283f4e..991c148d4e2 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -36,6 +36,7 @@ echo ' Done.'.PHP_EOL; echo 'Saving the HTML Git history graph...'.PHP_EOL; file_put_contents(__DIR__.'/graphs/history-graph.html', $html); +unset($html); // Free up memory echo 'Git history graphs built successfully!'.PHP_EOL; From 1cb0d9476d06370a75f525727eaad5ac413f7d73 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 14:54:43 +0200 Subject: [PATCH 27/53] Print the header --- monorepo/scripts/build-git-history-graph.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 991c148d4e2..e58d6742da4 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -40,6 +40,8 @@ echo 'Git history graphs built successfully!'.PHP_EOL; +echo $header; + function processHtml(string $html): string { // We need to run the ANSI to HTML conversion in chunks to prevent memory issues From 9e2b591fdbe6e26fe68d6308acc0f95fa1fc608b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 15:00:07 +0200 Subject: [PATCH 28/53] Remove debug --- monorepo/scripts/build-git-history-graph.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 9ed34000a3e..65e534c9899 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -13,8 +13,6 @@ if (! file_exists(__DIR__.'/graphs')) { mkdir(__DIR__.'/graphs'); } -$html = file_get_contents('H:\monorepo\graph.ansi'); - echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; $text = shell_exec('git log --graph --oneline --all'); echo 'Saving the plaintext Git history graph...'.PHP_EOL; From 95de47c9bf18dd5ee7b06b4832e06c095faa0761 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 15:05:38 +0200 Subject: [PATCH 29/53] Unfetch pages branch --- .github/workflows/static-analysis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index ff156da73b2..342cc002288 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -51,6 +51,9 @@ jobs: # We need to fetch all history to generate the graph fetch-depth: 0 + - name: Remove gh-pages branch + run: git fetch --prune origin +refs/heads/*:refs/remotes/origin/* && git branch -D gh-pages || true + - name: Generate Git history graph run: php monorepo/scripts/build-git-history-graph.php From 866c66a8fb08aacb3a9acce696391627f1f8af11 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 15:05:42 +0200 Subject: [PATCH 30/53] Revert "Unfetch pages branch" This reverts commit 95de47c9bf18dd5ee7b06b4832e06c095faa0761. --- .github/workflows/static-analysis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 342cc002288..ff156da73b2 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -51,9 +51,6 @@ jobs: # We need to fetch all history to generate the graph fetch-depth: 0 - - name: Remove gh-pages branch - run: git fetch --prune origin +refs/heads/*:refs/remotes/origin/* && git branch -D gh-pages || true - - name: Generate Git history graph run: php monorepo/scripts/build-git-history-graph.php From bb679af0a1c2474de7d76749f43ee00a3df41412 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 15:05:47 +0200 Subject: [PATCH 31/53] Prune pages --- monorepo/scripts/build-git-history-graph.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 65e534c9899..50a5ff03685 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -14,13 +14,14 @@ mkdir(__DIR__.'/graphs'); } echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; -$text = shell_exec('git log --graph --oneline --all'); +$prune = " $(git for-each-ref --format='%(refname:short)' refs/heads/ | grep -v gh-pages)"; +$text = shell_exec('git log --graph --oneline --all' . $prune); echo 'Saving the plaintext Git history graph...'.PHP_EOL; file_put_contents(__DIR__.'/graphs/history-graph.txt', $text); unset($text); // Free up memory echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; -$html = shell_exec('git log --graph --oneline --all --color=always'); +$html = shell_exec('git log --graph --oneline --all --color=always' . $prune); file_put_contents('H:\monorepo\graph.ansi', $html); echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); From a7e74d57111b342c6fa6191525bb7ab3e55e8d5b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 15:05:51 +0200 Subject: [PATCH 32/53] Revert "Prune pages" This reverts commit bb679af0a1c2474de7d76749f43ee00a3df41412. --- monorepo/scripts/build-git-history-graph.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 50a5ff03685..65e534c9899 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -14,14 +14,13 @@ mkdir(__DIR__.'/graphs'); } echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; -$prune = " $(git for-each-ref --format='%(refname:short)' refs/heads/ | grep -v gh-pages)"; -$text = shell_exec('git log --graph --oneline --all' . $prune); +$text = shell_exec('git log --graph --oneline --all'); echo 'Saving the plaintext Git history graph...'.PHP_EOL; file_put_contents(__DIR__.'/graphs/history-graph.txt', $text); unset($text); // Free up memory echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; -$html = shell_exec('git log --graph --oneline --all --color=always' . $prune); +$html = shell_exec('git log --graph --oneline --all --color=always'); file_put_contents('H:\monorepo\graph.ansi', $html); echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); From 0bf0dd7540be3454214ace6ace96335fc105eb13 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 15:06:44 +0200 Subject: [PATCH 33/53] Remove cache --- monorepo/scripts/build-git-history-graph.php | 1 - 1 file changed, 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 65e534c9899..5a86b177dbe 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -21,7 +21,6 @@ echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); -file_put_contents('H:\monorepo\graph.ansi', $html); echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); echo 'Generating header...'; From 95c907f62cb64c38c8edb7e041e8fa37bec74410 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:16:16 +0200 Subject: [PATCH 34/53] Post process to reduce browser rendering load --- monorepo/scripts/build-git-history-graph.php | 88 +++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 5a86b177dbe..e96b218d9a7 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -72,6 +72,9 @@ function processHtml(string $html): string echo "\033[0K\rProcessing chunk ".($index + 1).' of '.count($chunks).'...'; $chunkHtml = ansiToHtml($chunk); + + $chunkHtml = postProcessChunk($chunkHtml); + file_put_contents('chunks.temp', $chunkHtml, FILE_APPEND); // Free up memory @@ -116,10 +119,8 @@ function ansiToHtml(string $ansi): string }, $ansi); $ansi = str_replace("\033[m", '', $ansi); - $ansi = ''.$ansi; - $ansi .= ''; - return $ansi; + return trim($ansi); } function wrapHtml(string $html, string $header): string @@ -183,3 +184,84 @@ function countCommitLines(string $text): int return $count; } + +function postProcessChunk(string $chunk): string +{ + $lines = explode("\n", $chunk); + + foreach ($lines as $index => $line) { + // Remove stray closing span tags + // Replace with + $line = str_replace('', '', $line); + $line = str_replace(' ', ' ', $line); + $line = str_replace(' ', ' ', $line); + $line = str_replace(' ', ' ', $line); + + // replace * with * + $line = str_replace(' * ', ' * ', $line); + $line = str_replace(' * ', ' * ', $line); + + // If str starts with then remove it + if (str_starts_with($line, '')) { + $line = substr($line, 7); + } + if (str_starts_with($line, ' ')) { + $line = substr($line, 8) . ' '; + } + + // If str starts with * just use * + if (str_starts_with($line, '* ')) { + $line = '* '.substr($line, 9); + } + if (str_starts_with($line, '* ')) { + $line = '* '.substr($line, 10); + } + if (str_starts_with($line, '* ')) { + $line = '* '.substr($line, 11); + } + + // assert trimmed line does not start with closing span tag + $strStartsWith = str_starts_with(trim($line), ''); + if ($strStartsWith) { + echo PHP_EOL.$line.PHP_EOL; + + // write chunk to disk + $nextThreeLines = array_slice($lines, $index, 4); + unset($nextThreeLines[0]); + file_put_contents('chunk.html', $chunk); + file_put_contents('failed-chunk.html', sprintf("
%s\n%s\n^^^\n%s
", implode("\n", $lines), $line, implode("\n", $nextThreeLines))); + } + assert(! $strStartsWith, "Line $index starts with closing span tag"); + + // assert line has equal number of opening and closing span tags + $open = substr_count($line, ''); + if ($open !== $close) { + echo PHP_EOL.$line.PHP_EOL; + } + assert($open === $close, "Line $index has $open opening and $close closing span tags"); + + // if line contains any of these, ignore: + $ignore = [ + 'Upload documentation preview for PR', + 'Upload live reports from test suite run', + 'Upload site preview from test suite run with ref', + 'Upload coverage report from test suite run with ref', + 'Upload API documentation from test suite run with ref', + ]; + + foreach ($ignore as $str) { + if (str_contains($line, $str)) { + $line = ''; + break; + } + } + + $lines[$index] = trim($line); + } + + unset($chunk); + $lines = array_filter($lines); + + return implode("\n", $lines); +} From e637acd61d02b144d556dde1b0e602d082196d7e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:16:36 +0200 Subject: [PATCH 35/53] Formatting --- monorepo/scripts/build-git-history-graph.php | 1 + 1 file changed, 1 insertion(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index e96b218d9a7..69b508c5c27 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -8,6 +8,7 @@ * @link https://hydephp.github.io/develop/master/git/history-graph.html * @link https://hydephp.github.io/develop/master/git/history-graph.txt */ + echo 'Building the Git history graph...'.PHP_EOL; if (! file_exists(__DIR__.'/graphs')) { From 92390feb41e7f755e128b58ce7c8f71e81eec665 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 9 Jul 2024 14:16:46 +0000 Subject: [PATCH 36/53] Apply fixes from StyleCI --- monorepo/scripts/build-git-history-graph.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 69b508c5c27..77e89b6384f 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -8,7 +8,6 @@ * @link https://hydephp.github.io/develop/master/git/history-graph.html * @link https://hydephp.github.io/develop/master/git/history-graph.txt */ - echo 'Building the Git history graph...'.PHP_EOL; if (! file_exists(__DIR__.'/graphs')) { @@ -207,7 +206,7 @@ function postProcessChunk(string $chunk): string $line = substr($line, 7); } if (str_starts_with($line, ' ')) { - $line = substr($line, 8) . ' '; + $line = substr($line, 8).' '; } // If str starts with * just use * From 25a6c802d8085c9c14555f22bd3658f54e02c4be Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:20:59 +0200 Subject: [PATCH 37/53] Revert "Add temporary job to test the workflow" This reverts commit e588a0d4027b82c00850280c636d4d12be8a0701. --- .github/workflows/static-analysis.yml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index ff156da73b2..8912950308e 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -40,22 +40,3 @@ jobs: - name: Run Pest Type Coverage run: ./vendor/bin/pest --type-coverage - - - build-git-history-graph: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - # We need to fetch all history to generate the graph - fetch-depth: 0 - - - name: Generate Git history graph - run: php monorepo/scripts/build-git-history-graph.php - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: 'git-history-graph' - path: 'monorepo/scripts/graphs' From d72508be86f92b6040266297edaff68890cd8048 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:27:00 +0200 Subject: [PATCH 38/53] Update internal documentation --- monorepo/docs/hydefront.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/monorepo/docs/hydefront.md b/monorepo/docs/hydefront.md index 756d128cded..377f920e6e0 100644 --- a/monorepo/docs/hydefront.md +++ b/monorepo/docs/hydefront.md @@ -8,6 +8,26 @@ - Make sure you have authorization to publish the package to NPM and push to the HydeFront repository. - **Make sure that you have linked the local HydeFront package to the monorepo with `npm link`.** +If you need to set up the "submodule", run the following commands: + +```bash +cd packages/hydefront +git init +git remote add origin git@github.com:hydephp/hydefront.git +git fetch +git checkout master --force +``` + +If you need to set up the NPM link, run the following commands: + +```bash +cd packages/hydefront +npm link + +cd ../../ +npm link hydefront +``` + ### Build and setup ```bash From cac1506dbf5e18552706b13d74c7bd39b00aa458 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:29:47 +0200 Subject: [PATCH 39/53] Add missing download path --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 48326a19669..fef0caf7fea 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -493,6 +493,7 @@ jobs: uses: actions/download-artifact@v4 with: name: git-history-graph + path: master/git - name: Create README.md run: echo '# CI/CD generated reports for [${{ github.sha }}](https://github.com/hydephp/develop/commit/${{ github.sha }})' > master/README.md From 02f6256e3e897a978f32adca6bae22df6c78b33a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:44:28 +0200 Subject: [PATCH 40/53] Compile subdirectory listings --- .github/workflows/continuous-integration.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index fef0caf7fea..37f2bd69f91 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -519,6 +519,17 @@ jobs: - name: Compile static master directory listing run: cp .build.php master/.build.php && cd master && php .build.php + - name: Compile subdirectory listings + run: | + cd master + for dir in media test-fixtures git; do + mkdir $dir + cp .build.php $dir/.build.php + cd $dir + php .build.php + cd .. + done + # End directory listing - name: Commit changes From ae44b59cafdb363a01472c47adb3e7b10883697c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:44:47 +0200 Subject: [PATCH 41/53] Remove mkdir call --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 37f2bd69f91..398133ebc00 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -523,7 +523,6 @@ jobs: run: | cd master for dir in media test-fixtures git; do - mkdir $dir cp .build.php $dir/.build.php cd $dir php .build.php From 5177429d7534233ae55cc756afdb9d3800f647a8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:50:52 +0200 Subject: [PATCH 42/53] Add todo --- monorepo/scripts/build-git-history-graph.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 77e89b6384f..5b93c9f9fe2 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -5,6 +5,8 @@ /** * @internal This script is used to build the Git history graphs. * + * @todo The HTML page has serious memory issues and may need pagination. + * * @link https://hydephp.github.io/develop/master/git/history-graph.html * @link https://hydephp.github.io/develop/master/git/history-graph.txt */ From 88171a7375333193f5ad6294cd6ef8d9a5bd64f4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:51:53 +0200 Subject: [PATCH 43/53] Remove memory comments --- monorepo/scripts/build-git-history-graph.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 5b93c9f9fe2..612af8b4c65 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -19,7 +19,7 @@ $text = shell_exec('git log --graph --oneline --all'); echo 'Saving the plaintext Git history graph...'.PHP_EOL; file_put_contents(__DIR__.'/graphs/history-graph.txt', $text); -unset($text); // Free up memory +unset($text); echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); @@ -28,14 +28,14 @@ echo 'Generating header...'; $graph = file_get_contents(__DIR__.'/graphs/history-graph.txt'); $header = generateHeader($graph); -unset($graph); // Free up memory +unset($graph); echo ' Done.'.PHP_EOL; echo 'Wrapping the HTML...'; $html = wrapHtml($html, $header); echo ' Done.'.PHP_EOL; echo 'Saving the HTML Git history graph...'.PHP_EOL; file_put_contents(__DIR__.'/graphs/history-graph.html', $html); -unset($html); // Free up memory +unset($html); echo 'Git history graphs built successfully!'.PHP_EOL; @@ -79,7 +79,7 @@ function processHtml(string $html): string file_put_contents('chunks.temp', $chunkHtml, FILE_APPEND); - // Free up memory + unset($chunk); unset($chunkHtml); } @@ -156,7 +156,7 @@ function wrapHtml(string $html, string $header): string function generateHeader(string $text): string { $commitCount = countCommitLines($text); - unset($text); // Free up memory + unset($text); $head = trim(shell_exec('git rev-parse --short HEAD')); $date = date('Y-m-d H:i:s'); @@ -182,7 +182,7 @@ function countCommitLines(string $text): int $count++; } } - unset($lines); // Free up memory + unset($lines); return $count; } From 139b5e0ba44e1a53eaa776d0c2b6ecda311cf249 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:53:41 +0200 Subject: [PATCH 44/53] Clean up the script with Claude This cleaned-up version: 1. Organizes the code into smaller, more focused functions 2. Uses constants for repeated values 3. Improves naming for better readability 4. Removes unnecessary comments and whitespace 5. Simplifies some of the logic in the post-processing step The core functionality remains the same, but the code is now more organized and easier to maintain. --- monorepo/scripts/build-git-history-graph.php | 271 +++++++++---------- 1 file changed, 121 insertions(+), 150 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 612af8b4c65..e242b8bdfc1 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -10,116 +10,106 @@ * @link https://hydephp.github.io/develop/master/git/history-graph.html * @link https://hydephp.github.io/develop/master/git/history-graph.txt */ -echo 'Building the Git history graph...'.PHP_EOL; -if (! file_exists(__DIR__.'/graphs')) { - mkdir(__DIR__.'/graphs'); -} -echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; -$text = shell_exec('git log --graph --oneline --all'); -echo 'Saving the plaintext Git history graph...'.PHP_EOL; -file_put_contents(__DIR__.'/graphs/history-graph.txt', $text); -unset($text); - -echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; -$html = shell_exec('git log --graph --oneline --all --color=always'); -echo 'Converting ANSI color codes to HTML...'.PHP_EOL; -$html = processHtml($html); -echo 'Generating header...'; -$graph = file_get_contents(__DIR__.'/graphs/history-graph.txt'); -$header = generateHeader($graph); -unset($graph); -echo ' Done.'.PHP_EOL; -echo 'Wrapping the HTML...'; -$html = wrapHtml($html, $header); -echo ' Done.'.PHP_EOL; -echo 'Saving the HTML Git history graph...'.PHP_EOL; -file_put_contents(__DIR__.'/graphs/history-graph.html', $html); -unset($html); - -echo 'Git history graphs built successfully!'.PHP_EOL; - -echo $header; - -function processHtml(string $html): string -{ - // We need to run the ANSI to HTML conversion in chunks to prevent memory issues - - $html = explode("\n", $html); +const CHUNK_SIZE = 100000; +const GRAPHS_DIR = __DIR__ . '/graphs'; +const TEMP_FILE = 'chunks.temp'; - $chunks = []; - - $chunk = ''; +echo 'Building the Git history graph...' . PHP_EOL; - $chunkSize = 100000; +createGraphsDirectoryIfNotExists(); +buildPlainTextGraph(); +buildHtmlGraph(); - foreach ($html as $line) { - $chunk .= $line."\n"; +echo 'Git history graphs built successfully!' . PHP_EOL; - if (strlen($chunk) > $chunkSize) { - $chunks[] = $chunk; - $chunk = ''; - } +function createGraphsDirectoryIfNotExists(): void +{ + if (!file_exists(GRAPHS_DIR)) { + mkdir(GRAPHS_DIR); } +} - if ($chunk !== '') { - $chunks[] = $chunk; - } +function buildPlainTextGraph(): void +{ + echo 'Building the plaintext Git history graph... (This may take a while)' . PHP_EOL; + $text = shell_exec('git log --graph --oneline --all'); + echo 'Saving the plaintext Git history graph...' . PHP_EOL; + file_put_contents(GRAPHS_DIR . '/history-graph.txt', $text); +} - $message = 'Processing '.count($chunks).' chunks...'; +function buildHtmlGraph(): void +{ + echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; + $html = shell_exec('git log --graph --oneline --all --color=always'); + echo 'Converting ANSI color codes to HTML...' . PHP_EOL; + $html = processHtml($html); + echo 'Generating header...'; + $graph = file_get_contents(GRAPHS_DIR . '/history-graph.txt'); + $header = generateHeader($graph); + echo ' Done.' . PHP_EOL; + echo 'Wrapping the HTML...'; + $html = wrapHtml($html, $header); + echo ' Done.' . PHP_EOL; + echo 'Saving the HTML Git history graph...' . PHP_EOL; + file_put_contents(GRAPHS_DIR . '/history-graph.html', $html); +} + +function processHtml(string $html): string +{ + $chunks = chunkHtml($html); + $message = 'Processing ' . count($chunks) . ' chunks...'; echo $message; foreach ($chunks as $index => $chunk) { - // Progress indicator - echo "\033[0K\rProcessing chunk ".($index + 1).' of '.count($chunks).'...'; - + echo "\033[0K\rProcessing chunk " . ($index + 1) . ' of ' . count($chunks) . '...'; $chunkHtml = ansiToHtml($chunk); - $chunkHtml = postProcessChunk($chunkHtml); + file_put_contents(TEMP_FILE, $chunkHtml, FILE_APPEND); + } - file_put_contents('chunks.temp', $chunkHtml, FILE_APPEND); + $html = file_get_contents(TEMP_FILE); + unlink(TEMP_FILE); + echo PHP_EOL; + return $html; +} - unset($chunk); - unset($chunkHtml); - } +function chunkHtml(string $html): array +{ + $lines = explode("\n", $html); + $chunks = []; + $chunk = ''; - $html = file_get_contents('chunks.temp'); - unlink('chunks.temp'); + foreach ($lines as $line) { + $chunk .= $line . "\n"; + if (strlen($chunk) > CHUNK_SIZE) { + $chunks[] = $chunk; + $chunk = ''; + } + } - echo PHP_EOL; + if ($chunk !== '') { + $chunks[] = $chunk; + } - return $html; + return $chunks; } function ansiToHtml(string $ansi): string { - $ansi = preg_replace('/\x1b\[(\d+)(;\d+)*m/', '', $ansi); - $colors = [ - 1 => '#800000', - 30 => '#000000', - 31 => '#800000', - 32 => '#008000', - 33 => '#808000', - 34 => '#000080', - 35 => '#800080', - 36 => '#008080', - 37 => '#c0c0c0', - 90 => '#808080', - 91 => '#ff0000', - 92 => '#00ff00', - 93 => '#ffff00', - 94 => '#0000ff', - 95 => '#ff00ff', - 96 => '#00ffff', + 1 => '#800000', 30 => '#000000', 31 => '#800000', 32 => '#008000', + 33 => '#808000', 34 => '#000080', 35 => '#800080', 36 => '#008080', + 37 => '#c0c0c0', 90 => '#808080', 91 => '#ff0000', 92 => '#00ff00', + 93 => '#ffff00', 94 => '#0000ff', 95 => '#ff00ff', 96 => '#00ffff', 97 => '#ffffff', ]; + $ansi = preg_replace('/\x1b\[(\d+)(;\d+)*m/', '', $ansi); $ansi = preg_replace_callback('//', function ($matches) use ($colors) { - return ''; + return ''; }, $ansi); - $ansi = str_replace("\033[m", '', $ansi); return trim($ansi); @@ -156,8 +146,6 @@ function wrapHtml(string $html, string $header): string function generateHeader(string $text): string { $commitCount = countCommitLines($text); - unset($text); - $head = trim(shell_exec('git rev-parse --short HEAD')); $date = date('Y-m-d H:i:s'); @@ -182,88 +170,71 @@ function countCommitLines(string $text): int $count++; } } - unset($lines); - return $count; } function postProcessChunk(string $chunk): string { $lines = explode("\n", $chunk); + $ignore = [ + 'Upload documentation preview for PR', + 'Upload live reports from test suite run', + 'Upload site preview from test suite run with ref', + 'Upload coverage report from test suite run with ref', + 'Upload API documentation from test suite run with ref', + ]; foreach ($lines as $index => $line) { - // Remove stray closing span tags - // Replace with - $line = str_replace('', '', $line); - $line = str_replace(' ', ' ', $line); - $line = str_replace(' ', ' ', $line); - $line = str_replace(' ', ' ', $line); - - // replace * with * - $line = str_replace(' * ', ' * ', $line); - $line = str_replace(' * ', ' * ', $line); - - // If str starts with then remove it - if (str_starts_with($line, '')) { - $line = substr($line, 7); - } - if (str_starts_with($line, ' ')) { - $line = substr($line, 8).' '; - } + $line = cleanSpanTags($line); + $line = cleanAsterisk($line); + assertValidLine($line, $index); - // If str starts with * just use * - if (str_starts_with($line, '* ')) { - $line = '* '.substr($line, 9); - } - if (str_starts_with($line, '* ')) { - $line = '* '.substr($line, 10); - } - if (str_starts_with($line, '* ')) { - $line = '* '.substr($line, 11); + if (shouldIgnoreLine($line, $ignore)) { + $line = ''; } - // assert trimmed line does not start with closing span tag - $strStartsWith = str_starts_with(trim($line), ''); - if ($strStartsWith) { - echo PHP_EOL.$line.PHP_EOL; + $lines[$index] = trim($line); + } - // write chunk to disk - $nextThreeLines = array_slice($lines, $index, 4); - unset($nextThreeLines[0]); - file_put_contents('chunk.html', $chunk); - file_put_contents('failed-chunk.html', sprintf("
%s\n%s\n^^^\n%s
", implode("\n", $lines), $line, implode("\n", $nextThreeLines))); - } - assert(! $strStartsWith, "Line $index starts with closing span tag"); + return implode("\n", array_filter($lines)); +} - // assert line has equal number of opening and closing span tags - $open = substr_count($line, ''); - if ($open !== $close) { - echo PHP_EOL.$line.PHP_EOL; - } - assert($open === $close, "Line $index has $open opening and $close closing span tags"); - - // if line contains any of these, ignore: - $ignore = [ - 'Upload documentation preview for PR', - 'Upload live reports from test suite run', - 'Upload site preview from test suite run with ref', - 'Upload coverage report from test suite run with ref', - 'Upload API documentation from test suite run with ref', - ]; - - foreach ($ignore as $str) { - if (str_contains($line, $str)) { - $line = ''; - break; - } - } +function cleanSpanTags(string $line): string +{ + $line = str_replace(['', ' ', ' ', ' '], ['', ' ', ' ', ' '], $line); + if (str_starts_with($line, '')) { + $line = substr($line, 7); + } + if (str_starts_with($line, ' ')) { + $line = substr($line, 8) . ' '; + } + return $line; +} - $lines[$index] = trim($line); +function cleanAsterisk(string $line): string +{ + if (preg_match('/^\*\s*<\/span>/', $line)) { + $line = '* ' . preg_replace('/^\*\s*<\/span>/', '', $line); } + return $line; +} - unset($chunk); - $lines = array_filter($lines); +function assertValidLine(string $line, int $index): void +{ + $trimmedLine = trim($line); + assert(!str_starts_with($trimmedLine, ''), "Line $index starts with closing span tag"); - return implode("\n", $lines); + $openTags = substr_count($line, ''); + assert($openTags === $closeTags, "Line $index has $openTags opening and $closeTags closing span tags"); +} + +function shouldIgnoreLine(string $line, array $ignore): bool +{ + foreach ($ignore as $str) { + if (str_contains($line, $str)) { + return true; + } + } + return false; } From 9ff4f3b1c8ff9c5ee51cb5a5a8e7935fd49c41c7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 16:54:17 +0200 Subject: [PATCH 45/53] Reformat file --- monorepo/scripts/build-git-history-graph.php | 47 +++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index e242b8bdfc1..e81c384e01b 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -10,59 +10,58 @@ * @link https://hydephp.github.io/develop/master/git/history-graph.html * @link https://hydephp.github.io/develop/master/git/history-graph.txt */ - const CHUNK_SIZE = 100000; -const GRAPHS_DIR = __DIR__ . '/graphs'; +const GRAPHS_DIR = __DIR__.'/graphs'; const TEMP_FILE = 'chunks.temp'; -echo 'Building the Git history graph...' . PHP_EOL; +echo 'Building the Git history graph...'.PHP_EOL; createGraphsDirectoryIfNotExists(); buildPlainTextGraph(); buildHtmlGraph(); -echo 'Git history graphs built successfully!' . PHP_EOL; +echo 'Git history graphs built successfully!'.PHP_EOL; function createGraphsDirectoryIfNotExists(): void { - if (!file_exists(GRAPHS_DIR)) { + if (! file_exists(GRAPHS_DIR)) { mkdir(GRAPHS_DIR); } } function buildPlainTextGraph(): void { - echo 'Building the plaintext Git history graph... (This may take a while)' . PHP_EOL; + echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; $text = shell_exec('git log --graph --oneline --all'); - echo 'Saving the plaintext Git history graph...' . PHP_EOL; - file_put_contents(GRAPHS_DIR . '/history-graph.txt', $text); + echo 'Saving the plaintext Git history graph...'.PHP_EOL; + file_put_contents(GRAPHS_DIR.'/history-graph.txt', $text); } function buildHtmlGraph(): void { - echo 'Building the HTML Git history graph... (This may take a while)' . PHP_EOL; + echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; $html = shell_exec('git log --graph --oneline --all --color=always'); - echo 'Converting ANSI color codes to HTML...' . PHP_EOL; + echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); echo 'Generating header...'; - $graph = file_get_contents(GRAPHS_DIR . '/history-graph.txt'); + $graph = file_get_contents(GRAPHS_DIR.'/history-graph.txt'); $header = generateHeader($graph); - echo ' Done.' . PHP_EOL; + echo ' Done.'.PHP_EOL; echo 'Wrapping the HTML...'; $html = wrapHtml($html, $header); - echo ' Done.' . PHP_EOL; - echo 'Saving the HTML Git history graph...' . PHP_EOL; - file_put_contents(GRAPHS_DIR . '/history-graph.html', $html); + echo ' Done.'.PHP_EOL; + echo 'Saving the HTML Git history graph...'.PHP_EOL; + file_put_contents(GRAPHS_DIR.'/history-graph.html', $html); } function processHtml(string $html): string { $chunks = chunkHtml($html); - $message = 'Processing ' . count($chunks) . ' chunks...'; + $message = 'Processing '.count($chunks).' chunks...'; echo $message; foreach ($chunks as $index => $chunk) { - echo "\033[0K\rProcessing chunk " . ($index + 1) . ' of ' . count($chunks) . '...'; + echo "\033[0K\rProcessing chunk ".($index + 1).' of '.count($chunks).'...'; $chunkHtml = ansiToHtml($chunk); $chunkHtml = postProcessChunk($chunkHtml); file_put_contents(TEMP_FILE, $chunkHtml, FILE_APPEND); @@ -82,7 +81,7 @@ function chunkHtml(string $html): array $chunk = ''; foreach ($lines as $line) { - $chunk .= $line . "\n"; + $chunk .= $line."\n"; if (strlen($chunk) > CHUNK_SIZE) { $chunks[] = $chunk; $chunk = ''; @@ -108,7 +107,7 @@ function ansiToHtml(string $ansi): string $ansi = preg_replace('/\x1b\[(\d+)(;\d+)*m/', '', $ansi); $ansi = preg_replace_callback('//', function ($matches) use ($colors) { - return ''; + return ''; }, $ansi); $ansi = str_replace("\033[m", '', $ansi); @@ -170,6 +169,7 @@ function countCommitLines(string $text): int $count++; } } + return $count; } @@ -206,23 +206,25 @@ function cleanSpanTags(string $line): string $line = substr($line, 7); } if (str_starts_with($line, ' ')) { - $line = substr($line, 8) . ' '; + $line = substr($line, 8).' '; } + return $line; } function cleanAsterisk(string $line): string { if (preg_match('/^\*\s*<\/span>/', $line)) { - $line = '* ' . preg_replace('/^\*\s*<\/span>/', '', $line); + $line = '* '.preg_replace('/^\*\s*<\/span>/', '', $line); } + return $line; } function assertValidLine(string $line, int $index): void { $trimmedLine = trim($line); - assert(!str_starts_with($trimmedLine, ''), "Line $index starts with closing span tag"); + assert(! str_starts_with($trimmedLine, ''), "Line $index starts with closing span tag"); $openTags = substr_count($line, ''); @@ -236,5 +238,6 @@ function shouldIgnoreLine(string $line, array $ignore): bool return true; } } + return false; } From cfa34c171a2d21c8c49cd1bdf52507a9d664e4dd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 17:01:32 +0200 Subject: [PATCH 46/53] Add helper to cache long running processes --- monorepo/scripts/build-git-history-graph.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index e81c384e01b..6461fc078c7 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -32,7 +32,7 @@ function createGraphsDirectoryIfNotExists(): void function buildPlainTextGraph(): void { echo 'Building the plaintext Git history graph... (This may take a while)'.PHP_EOL; - $text = shell_exec('git log --graph --oneline --all'); + $text = cached_shell_exec('git log --graph --oneline --all'); echo 'Saving the plaintext Git history graph...'.PHP_EOL; file_put_contents(GRAPHS_DIR.'/history-graph.txt', $text); } @@ -40,7 +40,7 @@ function buildPlainTextGraph(): void function buildHtmlGraph(): void { echo 'Building the HTML Git history graph... (This may take a while)'.PHP_EOL; - $html = shell_exec('git log --graph --oneline --all --color=always'); + $html = cached_shell_exec('git log --graph --oneline --all --color=always'); echo 'Converting ANSI color codes to HTML...'.PHP_EOL; $html = processHtml($html); echo 'Generating header...'; @@ -241,3 +241,13 @@ function shouldIgnoreLine(string $line, array $ignore): bool return false; } + +function cached_shell_exec(string $command): string +{ + $cacheFile = __DIR__.'/cache/'.sha1($command).'.txt'; + $cache = file_exists($cacheFile) ? file_get_contents($cacheFile) : ''; + $output = $cache ?: shell_exec($command); + file_put_contents($cacheFile, $output); + + return $output; +} From d4cf909c80bdb58f6fc9ba2bef063290d498164e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 17:02:12 +0200 Subject: [PATCH 47/53] Skip validation --- monorepo/scripts/build-git-history-graph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 6461fc078c7..47fb85c306b 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -187,7 +187,7 @@ function postProcessChunk(string $chunk): string foreach ($lines as $index => $line) { $line = cleanSpanTags($line); $line = cleanAsterisk($line); - assertValidLine($line, $index); + // assertValidLine($line, $index); if (shouldIgnoreLine($line, $ignore)) { $line = ''; From 1132ec4e3f4478d581c358f4c79f704ac66c24ce Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 17:04:22 +0200 Subject: [PATCH 48/53] Reformat and cleanup code --- monorepo/scripts/build-git-history-graph.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index 47fb85c306b..b3fdb519811 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -64,6 +64,8 @@ function processHtml(string $html): string echo "\033[0K\rProcessing chunk ".($index + 1).' of '.count($chunks).'...'; $chunkHtml = ansiToHtml($chunk); $chunkHtml = postProcessChunk($chunkHtml); + + // Since this process takes so much memory, we store the chunks on disk instead of memory. file_put_contents(TEMP_FILE, $chunkHtml, FILE_APPEND); } @@ -164,6 +166,7 @@ function countCommitLines(string $text): int { $count = 0; $lines = explode("\n", $text); + foreach ($lines as $line) { if (str_starts_with(ltrim($line, ' /\\|'), '*')) { $count++; @@ -176,6 +179,7 @@ function countCommitLines(string $text): int function postProcessChunk(string $chunk): string { $lines = explode("\n", $chunk); + $ignore = [ 'Upload documentation preview for PR', 'Upload live reports from test suite run', @@ -201,10 +205,16 @@ function postProcessChunk(string $chunk): string function cleanSpanTags(string $line): string { - $line = str_replace(['', ' ', ' ', ' '], ['', ' ', ' ', ' '], $line); + $line = str_replace( + ['', ' ', ' ', ' '], + ['', ' ', ' ', ' '], + $line + ); + if (str_starts_with($line, '')) { $line = substr($line, 7); } + if (str_starts_with($line, ' ')) { $line = substr($line, 8).' '; } From 483cc0e8e600013c25805323b90b4380c4241ad8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 17:05:08 +0200 Subject: [PATCH 49/53] Split comma-separated values into multiple lines --- monorepo/scripts/build-git-history-graph.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index b3fdb519811..d1693e6beda 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -100,10 +100,22 @@ function chunkHtml(string $html): array function ansiToHtml(string $ansi): string { $colors = [ - 1 => '#800000', 30 => '#000000', 31 => '#800000', 32 => '#008000', - 33 => '#808000', 34 => '#000080', 35 => '#800080', 36 => '#008080', - 37 => '#c0c0c0', 90 => '#808080', 91 => '#ff0000', 92 => '#00ff00', - 93 => '#ffff00', 94 => '#0000ff', 95 => '#ff00ff', 96 => '#00ffff', + 1 => '#800000', + 30 => '#000000', + 31 => '#800000', + 32 => '#008000', + 33 => '#808000', + 34 => '#000080', + 35 => '#800080', + 36 => '#008080', + 37 => '#c0c0c0', + 90 => '#808080', + 91 => '#ff0000', + 92 => '#00ff00', + 93 => '#ffff00', + 94 => '#0000ff', + 95 => '#ff00ff', + 96 => '#00ffff', 97 => '#ffffff', ]; From 01948c2bd252f8e354525b31e721026e4396609a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 17:05:25 +0200 Subject: [PATCH 50/53] Strict closure types --- monorepo/scripts/build-git-history-graph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index d1693e6beda..ad4b20df088 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -120,7 +120,7 @@ function ansiToHtml(string $ansi): string ]; $ansi = preg_replace('/\x1b\[(\d+)(;\d+)*m/', '', $ansi); - $ansi = preg_replace_callback('//', function ($matches) use ($colors) { + $ansi = preg_replace_callback('//', function (array $matches) use ($colors): string { return ''; }, $ansi); $ansi = str_replace("\033[m", '', $ansi); From 4641898595e3389e134eb0ee2ebe60525e89bbd6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Jul 2024 17:12:40 +0200 Subject: [PATCH 51/53] Tweak color scheme to match PowerShell See https://learn.microsoft.com/en-us/windows/terminal/customize-settings/color-schemes --- monorepo/scripts/build-git-history-graph.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/monorepo/scripts/build-git-history-graph.php b/monorepo/scripts/build-git-history-graph.php index ad4b20df088..e7b2a97d5b1 100644 --- a/monorepo/scripts/build-git-history-graph.php +++ b/monorepo/scripts/build-git-history-graph.php @@ -100,15 +100,15 @@ function chunkHtml(string $html): array function ansiToHtml(string $ansi): string { $colors = [ - 1 => '#800000', - 30 => '#000000', - 31 => '#800000', - 32 => '#008000', - 33 => '#808000', - 34 => '#000080', - 35 => '#800080', - 36 => '#008080', - 37 => '#c0c0c0', + 1 => '#C50F1F', + 30 => '#0C0C0C', + 31 => '#C50F1F', + 32 => '#13A10E', + 33 => '#C19C00', + 34 => '#0037DA', + 35 => '#881798', + 36 => '#3A96DD', + 37 => '#CCCCCC', 90 => '#808080', 91 => '#ff0000', 92 => '#00ff00', @@ -138,7 +138,7 @@ function wrapHtml(string $html, string $header): string Git History Graph