Skip to content

Commit 68d302c

Browse files
authored
Merge pull request #1156 from benno5020/gh-pages
Make the PHAR "website" a little more fancy
2 parents e2414e2 + d37c885 commit 68d302c

File tree

198 files changed

+481
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+481
-13
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#
2+
# Auto detect text files and perform LF normalization
3+
#
4+
* text=auto eol=lf

.github/workflows/publish-website.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Deploy gh-pages branch to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- "gh-pages"
7+
# Do a dry-run (update, no deploy) for PRs.
8+
pull_request:
9+
# Allow running this workflow manually from the Actions tab.
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build:
26+
# Don't run on forks.
27+
if: github.event.repository.fork == false
28+
runs-on: ubuntu-latest
29+
steps:
30+
# By default use the `gh-pages` branch.
31+
# For testing changes to the workflow or the scripts, use the PR branch
32+
# to have access to the latest version of the workflow/scripts.
33+
- name: Determine branch to use
34+
id: base_branch
35+
env:
36+
REF: ${{ github.ref }}
37+
run: |
38+
if [ "${{ github.event_name }}" == "pull_request" ]; then
39+
echo "BRANCH=$REF" >> "$GITHUB_OUTPUT"
40+
else
41+
echo 'BRANCH=gh-pages' >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
- name: Checkout code
45+
uses: actions/checkout@v4
46+
with:
47+
ref: ${{ steps.base_branch.outputs.BRANCH }}
48+
49+
- name: Install PHP
50+
uses: shivammathur/setup-php@v2
51+
with:
52+
php-version: '8.4'
53+
ini-values: error_reporting=-1, display_errors=On, log_errors_max_len=0
54+
coverage: none
55+
56+
- name: Generate /phars/index.html
57+
run: php build/generate_phars_list.php
58+
59+
- name: Check GitHub Pages status
60+
uses: crazy-max/ghaction-github-status@v4
61+
with:
62+
pages_threshold: major_outage
63+
64+
- name: Setup Pages
65+
uses: actions/configure-pages@v5
66+
67+
- name: Upload artifact
68+
uses: actions/upload-pages-artifact@v3
69+
with:
70+
path: './src'
71+
72+
deploy:
73+
needs: build
74+
# Don't run on forks.
75+
if: github.repository == 'PHPCSStandards/PHP_CodeSniffer' && github.event_name != 'pull_request' && needs.build.result == 'success'
76+
77+
name: "Deploy the website"
78+
runs-on: ubuntu-latest
79+
80+
environment:
81+
name: github-pages
82+
url: ${{ steps.deployment.outputs.page_url }}
83+
84+
steps:
85+
- name: Deploy to GitHub Pages
86+
id: deployment
87+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
.phpunit.result.cache
3+
src/phars/index.html

.nojekyll

Whitespace-only changes.

build/generate_phars_list.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* Script to auto-generate the `phars/index.html` page for the GH Pages website.
5+
*
6+
* {@internal This script has a minimum PHP requirement of PHP 7.0.}
7+
*
8+
* @copyright 2025 PHPCSStandards and contributors
9+
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
10+
*/
11+
12+
// A directory containing files that are named {phpcs,phpcbf}-*.{phar,phar.asc}.
13+
$pharDir = __DIR__ . '/../src/phars';
14+
15+
$allFiles = array_filter(scandir($pharDir), function (string $file) {
16+
return preg_match('/\.phar(\.asc)?$/', $file);
17+
});
18+
19+
$filesGroupedByVersion = [];
20+
21+
foreach ($allFiles as $file) {
22+
$matches = [];
23+
24+
if (preg_match('/^(?:phpcs|phpcbf)-(.*?)(\.phar(?:\.asc)?)$/', $file, $matches)) {
25+
$version = $matches[1];
26+
27+
if (!isset($filesGroupedByVersion[$version])) {
28+
$filesGroupedByVersion[$version] = [];
29+
}
30+
31+
$filesGroupedByVersion[$version][] = $file;
32+
}
33+
}
34+
35+
uksort($filesGroupedByVersion, function ($a, $b) {
36+
return version_compare($b, $a);
37+
});
38+
39+
function indent(int $level): string
40+
{
41+
$indentSpaces = ' ';
42+
43+
$output = '';
44+
45+
for ($i = 0; $i < $level; $i++) {
46+
$output .= $indentSpaces;
47+
}
48+
49+
return $output;
50+
}
51+
52+
function humanReadableFilesize(string $file): string
53+
{
54+
$bytes = filesize($file);
55+
56+
$units = ['B', 'K', 'M', 'G'];
57+
$factor = floor((strlen($bytes) - 1) / 3);
58+
return sprintf('%.1f', $bytes / pow(1024, $factor)) . $units[(int) $factor];
59+
}
60+
61+
$html = "<ul class=\"phar-list\">\n";
62+
63+
foreach ($filesGroupedByVersion as $version => $files) {
64+
sort($files);
65+
66+
$html .= indent(3) . "<li class=\"phar-list__version\">\n"
67+
. indent(4) . '<h2 class="phar-list__version-label">' . $version . "</h2>\n"
68+
. indent(4) . "<ul class=\"phar-list__files\">\n";
69+
70+
foreach ($files as $file) {
71+
$fileSize = humanReadableFilesize($pharDir . '/' . $file);
72+
73+
$html .= indent(5) . '<li><a download href="/phars/' . htmlspecialchars($file) . '">' . htmlspecialchars($file)
74+
. '</a> <span class="phar-list__filesize">' . htmlspecialchars($fileSize) . "</span></li>\n";
75+
}
76+
77+
$html .= indent(4) . "</ul>\n"
78+
. indent(3) . "</li>\n";
79+
}
80+
81+
$html .= indent(2) . "</li>\n"
82+
. "</ul>\n";
83+
84+
$template = file_get_contents(__DIR__ . '/phars.html.template');
85+
86+
$output = str_replace('<!-- {{ PHARS }} -->', $html, $template);
87+
88+
file_put_contents($pharDir . '/index.html', $output);
89+
90+
echo $pharDir . "/index.html generated successfully.\n";

build/phars.html.template

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="stylesheet" href="../styles.css" />
8+
<title>PHP_CodeSniffer - PHAR Archive</title>
9+
<link rel="canonical" href="https://phars.phpcodesniffer.com/phars/" />
10+
</head>
11+
12+
<body>
13+
<main class="container">
14+
<h1 class="heading">PHAR Archive</h1>
15+
<a href=".." class="link">See latest PHAR files</a>
16+
<!-- {{ PHARS }} -->
17+
<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>
18+
</main>
19+
</body>
20+
21+
</html>

index.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/index.html

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="stylesheet" href="./styles.css" />
8+
<title>PHP_CodeSniffer PHAR - Latest PHAR files</title>
9+
<link rel="canonical" href="https://phars.phpcodesniffer.com/" />
10+
</head>
11+
12+
<body>
13+
<main class="container">
14+
<h1 class="heading">Download the latest PHAR files</h1>
15+
<div class="download-section">
16+
<article class="download-box">
17+
<h2 class="download-box__title">PHPCS</h2>
18+
<div class="download-box__description">
19+
Tokenizes PHP, JavaScript and CSS files to detect violations of a
20+
defined coding standard.
21+
</div>
22+
<a href="phpcs.phar" download class="button button--download"><svg xmlns="http://www.w3.org/2000/svg"
23+
class="icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
24+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
25+
class="feather feather-download">
26+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
27+
<polyline points="7 10 12 15 17 10"></polyline>
28+
<line x1="12" y1="15" x2="12" y2="3"></line>
29+
</svg><span>Download PHPCS</span></a>
30+
<a href="phpcs.phar.asc" class="download-box__secondary-link">Signature (.asc)</a>
31+
</article>
32+
<article class="download-box">
33+
<h2 class="download-box__title">PHPCBF</h2>
34+
<div class="download-box__description">
35+
Automatically corrects coding standard violations.
36+
</div>
37+
<a href="phpcbf.phar" download class="button button--download"><svg xmlns="http://www.w3.org/2000/svg"
38+
class="icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
39+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
40+
class="feather feather-download">
41+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
42+
<polyline points="7 10 12 15 17 10"></polyline>
43+
<line x1="12" y1="15" x2="12" y2="3"></line>
44+
</svg><span>Download PHPCBF</span></a>
45+
<a href="phpcbf.phar.asc" class="download-box__secondary-link">Signature (.asc)</a>
46+
</article>
47+
</div>
48+
<aside class="additional-info">
49+
<a href="./phars/">
50+
Find more versions in the PHAR archive
51+
</a>
52+
53+
</aside>
54+
<aside class="external-links">
55+
<a href="https://github.com/PHPCSStandards/PHP_CodeSniffer"><svg width="98" height="96" viewBox="0 0 98 96"
56+
xmlns="http://www.w3.org/2000/svg" class="icon icon--github">
57+
<path fill-rule="evenodd" clip-rule="evenodd"
58+
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" />
59+
</svg>
60+
GitHub
61+
</a> | <a href="https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki">
62+
Documentation
63+
</a>
64+
</aside>
65+
</main>
66+
</body>
67+
68+
</html>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)