Skip to content

Make the PHAR "website" a little more fancy #1156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
88 changes: 88 additions & 0 deletions .github/workflows/publish-website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Deploy gh-pages branch to GitHub Pages

on:
push:
branches:
- "gh-pages"
# Do a dry-run (update, no deploy) for PRs.
pull_request:
# Allow running this workflow manually from the Actions tab.
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
# Don't run on forks.
if: github.repository == 'PHPCSStandards/PHP_CodeSniffer'
runs-on: ubuntu-latest
steps:
# By default use the `gh-pages` branch.
# For testing changes to the workflow or the scripts, use the PR branch
# to have access to the latest version of the workflow/scripts.
- name: Determine branch to use
id: base_branch
env:
REF: ${{ github.ref }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "BRANCH=$REF" >> "$GITHUB_OUTPUT"
else
echo 'BRANCH=gh-pages' >> "$GITHUB_OUTPUT"
fi

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ steps.base_branch.outputs.BRANCH }}

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
ini-values: error_reporting=-1, display_errors=On, log_errors_max_len=0
coverage: none

- name: Generate /phars/index.html
run: php build/generate_phars_list.php

- name: Check GitHub Pages status
uses: crazy-max/ghaction-github-status@v4
with:
pages_threshold: major_outage

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './src'

deploy:
needs: build
# Don't run on forks.
if: github.repository == 'PHPCSStandards/PHP_CodeSniffer' && github.event_name != 'pull_request' && needs.build.result == 'success'

name: "Deploy the website"
runs-on: ubuntu-latest

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
.phpunit.result.cache
src/phars/index.html
Empty file removed .nojekyll
Empty file.
87 changes: 87 additions & 0 deletions build/generate_phars_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env php
<?php
/**
* Script to auto-generate the `phars/index.html` page for the GH Pages website.
*
* @copyright 2025 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

// A directory containing files that are named {phpcs,phpcbf}-*.{phar,phar.asc}.
$pharDir = __DIR__ . '/../src/phars';

$allFiles = array_filter(scandir($pharDir), function ($file) {
return preg_match('/\.phar(\.asc)?$/', $file);
});

$filesGroupedByVersion = [];

foreach ($allFiles as $file) {
$matches = [];

if (preg_match('/^(?:phpcs|phpcbf)-(.*?)(\.phar(?:\.asc)?)$/', $file, $matches)) {
$version = $matches[1];

if (!isset($filesGroupedByVersion[$version])) {
$filesGroupedByVersion[$version] = [];
}

$filesGroupedByVersion[$version][] = $file;
}
}

uksort($filesGroupedByVersion, function ($a, $b) {
return version_compare($b, $a);
});

function indent (int $level): string
{
$indentSpaces = ' ';

$output = "";

for ($i = 0; $i < $level; $i++) {
$output .= $indentSpaces;
}

return $output;
}

function humanReadableFilesize($file) {
$bytes = filesize($file);

$units = ['B', 'K', 'M', 'G'];
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.1f", $bytes / pow(1024, $factor)) . $units[(int) $factor];
}

$html = "<ul class=\"phar-list\">\n";

foreach ($filesGroupedByVersion as $version => $files) {
sort($files);

$html .= indent(3) . "<li class=\"phar-list__version\">\n" .
indent(4) . "<h2 class=\"phar-list__version-label\">" . $version . "</h2>\n" .
indent(4) . "<ul class=\"phar-list__files\">\n";

foreach ($files as $file) {
$fileSize = humanReadableFilesize($pharDir . '/' . $file);
$lastModifiedDate = shell_exec(escapeshellcmd("git log -1 --pretty=\"format:%cs\" -- " . $pharDir . '/' . $file));

$html .= indent(5) . "<li><a download href=\"/phars/" . htmlspecialchars($file) . '">' . htmlspecialchars($file) . "</a> <span class=\"phar-list__filesize\">" . htmlspecialchars($fileSize) . " | " . htmlspecialchars($lastModifiedDate) . "</span></li>\n";
}

$html .= indent(4) . "</ul>\n" .
indent(3) . "</li>\n";
}

$html .= indent(2) . "</li>\n" .
"</ul>\n";

$template = file_get_contents(__DIR__ . '/phars.html.template');

$output = str_replace('<!-- {{ PHARS }} -->', $html, $template);

file_put_contents($pharDir . '/index.html', $output);

echo $pharDir . "/index.html generated successfully.\n";
21 changes: 21 additions & 0 deletions build/phars.html.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../styles.css" />
<title>PHP_CodeSniffer - PHAR Archive</title>
<link rel="canonical" href="https://phars.phpcodesniffer.com/phars/" />
</head>

<body>
<main class="container">
<h1 class="heading">PHAR Archive</h1>
<a href=".." class="link">See latest PHAR files</a>
<!-- {{ PHARS }} -->
<div class="footnote">Note: The PHAR archive does not contain all previously released PHAR files. Only the ones released since PHIVE support was added (and the PHAR files started to be signed).</div>
</main>
</body>

</html>
13 changes: 0 additions & 13 deletions index.html

This file was deleted.

68 changes: 68 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./styles.css" />
<title>PHP_CodeSniffer PHAR - Latest PHAR files</title>
<link rel="canonical" href="https://phars.phpcodesniffer.com/" />
</head>

<body>
<main class="container">
<h1 class="heading">Download the latest PHAR files</h1>
<div class="download-section">
<article class="download-box">
<h2 class="download-box__title">PHPCS</h2>
<div class="download-box__description">
Tokenizes PHP, JavaScript and CSS files to detect violations of a
defined coding standard.
</div>
<a href="phpcs.phar" download class="button button--download"><svg xmlns="http://www.w3.org/2000/svg"
class="icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
class="feather feather-download">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
<polyline points="7 10 12 15 17 10"></polyline>
<line x1="12" y1="15" x2="12" y2="3"></line>
</svg><span>Download PHPCS</span></a>
<a href="phpcs.phar.asc" class="download-box__secondary-link">Signature (.asc)</a>
</article>
<article class="download-box">
<h2 class="download-box__title">PHPCBF</h2>
<div class="download-box__description">
Automatically corrects coding standard violations.
</div>
<a href="phpcbf.phar" download class="button button--download"><svg xmlns="http://www.w3.org/2000/svg"
class="icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
class="feather feather-download">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
<polyline points="7 10 12 15 17 10"></polyline>
<line x1="12" y1="15" x2="12" y2="3"></line>
</svg><span>Download PHPCBF</span></a>
<a href="phpcbf.phar.asc" class="download-box__secondary-link">Signature (.asc)</a>
</article>
</div>
<aside class="additional-info">
<a href="./phars/">
See more versions in our PHAR archive
</a>

</aside>
<aside class="external-links">
<a href="https://github.com/PHPCSStandards/PHP_CodeSniffer"><svg width="98" height="96" viewBox="0 0 98 96"
xmlns="http://www.w3.org/2000/svg" class="icon icon--github">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" />
</svg>
GitHub
</a> | <a href="https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki">
Wiki
</a>
</aside>
</main>
</body>

</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading