Skip to content

Commit ec94bb4

Browse files
authored
Merge pull request #180 from ichava/fix/catalog-sync-docs-table
Update the installation guide's pack table in the catalogue sync
2 parents f33747a + bea239d commit ec94bb4

4 files changed

Lines changed: 86 additions & 3 deletions

File tree

‎.github/workflows/sync-icon-sets.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ jobs:
7373
# the first run after a merge passed and every run after it failed.
7474
git fetch origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" || true
7575
git checkout -B "$BRANCH"
76-
git add icon-sets.json
76+
# The sync sets docs/installation.md's pack-table counts from the catalogue too.
77+
git add icon-sets.json docs/installation.md
7778
git commit -m 'docs: sync icon-sets catalog' || true
7879
# Lease kept rather than dropped for --force: it still refuses to clobber a
7980
# push that arrived after the fetch above, which is the case it exists for.

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ All notable changes to `ichava/core` follow [Keep a Changelog](https://keepachan
3030

3131
### Fixed
3232

33+
- **The nightly catalogue sync updates the installation guide's pack table with the catalogue.** `bin/sync-icon-sets.php` rewrote `icon-sets.json` alone, so a count change opened a pull request that `InstallationPackTableTest` failed: #179 moved tabler to 6,287 and openmoji to 8,990 while `docs/installation.md` still said 6,257 and 8,568. After writing the catalogue, the script now sets each table row's count from it with `withPackTableCounts()`, and the workflow commits both files. Rows, order and repositories are left as written, so a set added or removed still fails the table test. `tests/Unit/SyncIconSetsDocTableTest.php` covers it (proven red by leaving the counts alone).
3334
- **The nightly catalogue sync no longer puts Twemoji's pre-split values back.** `bin/sync-icon-sets.php` reads each pack at its latest tag, and `icon-sets-twemoji`'s `v0.1.0` still holds OpenMoji, so #176 proposed 10,567 "Emoji Sets" over the recorded 3,435 "Twemoji". A set in `icon-sets.json` may now carry a `hold` (`tag`, `commit`, `reason`): while that tag is the latest release at that commit the sync keeps the set's snapshot, and the hold drops itself once a newer tag is cut or the tag moves. The twemoji set is held at `v0.1.0`. `tests/Unit/SyncIconSetsHoldTest.php` covers it (proven red by ignoring the commit).
3435
- **A pack listed with the application boots again.** `PackConfigCache` resolved the cache store when it was built, and a pack's constants class builds it while the providers are still registering, before the store exists, so every pack failed to boot with `Target class [cache] does not exist` (found running the packs against #172). The store is now resolved when it is used. Core's own pack tests registered their fixture after boot, which is why none saw it; `tests/Feature/PackBootsInProviderListTest.php` lists the fixture with the application.
3536
- **`InformationService::discoverPackages()` finds the installed packs.** It globbed `vendor/*/ichava-*`, which matches no pack (packs install as `vendor/ichava/icon-sets-*`), and reported `registered` through `IconRegistry::has()`, which looks up an icon, not a package, so `ichava::ichava-core.info discover` listed nothing. It now asks `Composer\InstalledVersions` for every package of type `ichava-icon-set` and reports `registered` through `IconRegistry::isRegistered()`. The signature and return shape are unchanged. A pack is identified by its composer type and nothing else (owner, 2026-11-05): the `vendor/*/ichava-*` directory glob is removed, since no pack in the estate matched it, and the `platform/ichava` scan now keeps only a directory whose composer.json declares `ichava-icon-set`, keyed by that file's `name` instead of `ichava/<directory>`. A checkout there without the type is no longer listed. `tests/Feature/InstalledPackDiscoveryTest.php`.

‎bin/sync-icon-sets.php‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
// Run only when executed as a script, so the functions below can be loaded and tested on their own.
3333
if (realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
34-
exit(main(dirname(__DIR__) . '/icon-sets.json'));
34+
exit(main(dirname(__DIR__) . '/icon-sets.json', dirname(__DIR__) . '/docs/installation.md'));
3535
}
3636

37-
function main(string $manifestPath): int
37+
function main(string $manifestPath, ?string $docPath = null): int
3838
{
3939
$raw = @file_get_contents($manifestPath);
4040

@@ -113,9 +113,48 @@ function main(string $manifestPath): int
113113
file_put_contents($manifestPath, $encoded . "\n");
114114
echo "Wrote {$manifestPath}\n";
115115

116+
// docs/installation.md shows each set's count, and InstallationPackTableTest fails when it
117+
// disagrees with the catalogue. Writing the catalogue alone opened a pull request that
118+
// could never go green (core#179), so the table moves with it.
119+
if ($docPath !== null && is_file($docPath)) {
120+
$doc = (string) file_get_contents($docPath);
121+
$updated = withPackTableCounts($doc, $manifest['sets']);
122+
123+
if ($updated !== $doc) {
124+
file_put_contents($docPath, $updated);
125+
echo "Wrote {$docPath}\n";
126+
}
127+
}
128+
116129
return 0;
117130
}
118131

132+
/**
133+
* The installation guide with each pack-table row's count set from the catalogue.
134+
*
135+
* Only the count cell of a row whose package is in the catalogue changes; rows, order and
136+
* repositories are left as written, so a set added or removed still fails the table test
137+
* rather than being papered over here.
138+
*
139+
* @param list<array<string, mixed>> $sets
140+
*/
141+
function withPackTableCounts(string $doc, array $sets): string
142+
{
143+
$counts = [];
144+
145+
foreach ($sets as $set) {
146+
if (isset($set['package'], $set['icon_count']) && is_int($set['icon_count'])) {
147+
$counts[(string) $set['package']] = number_format($set['icon_count']);
148+
}
149+
}
150+
151+
return (string) preg_replace_callback(
152+
'/^(\| `(ichava\/[\w-]+)` \| )([^|]+?)( \| `https:\/\/github\.com\/[\w\/.-]+` \|)$/m',
153+
static fn (array $m): string => isset($counts[$m[2]]) ? $m[1] . $counts[$m[2]] . $m[4] : $m[0],
154+
$doc,
155+
);
156+
}
157+
119158
/**
120159
* The catalogue without its sync timestamp, for comparing two runs.
121160
*
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
// bin/sync-icon-sets.php rewrote icon-sets.json alone, so a count change opened a
6+
// pull request that InstallationPackTableTest failed (core#179: tabler 6,257 -> 6,287,
7+
// openmoji 8,568 -> 8,990). The sync now sets the guide's count cells from the
8+
// catalogue it writes.
9+
10+
require_once dirname(__DIR__, 2) . '/bin/sync-icon-sets.php';
11+
12+
function docTable(string $tabler, string $openmoji): string
13+
{
14+
return "Intro.\n\n| Package | Icons | Repository |\n|---|---|---|\n"
15+
. "| `ichava/icon-sets-tabler` | {$tabler} | `https://github.com/ichava/icon-sets-tabler` |\n"
16+
. "| `ichava/icon-sets-openmoji` | {$openmoji} | `https://github.com/ichava/icon-sets-openmoji` |\n"
17+
. "\nOutro mentions 6,257 icons.\n";
18+
}
19+
20+
it('sets each row count from the catalogue', function () {
21+
$sets = [
22+
['package' => 'ichava/icon-sets-tabler', 'icon_count' => 6287],
23+
['package' => 'ichava/icon-sets-openmoji', 'icon_count' => 8990],
24+
];
25+
26+
expect(withPackTableCounts(docTable('6,257', '8,568'), $sets))->toBe(docTable('6,287', '8,990'));
27+
});
28+
29+
it('leaves a row the catalogue does not name, and the prose around the table', function () {
30+
$doc = docTable('6,257', '8,568');
31+
32+
expect(withPackTableCounts($doc, [['package' => 'ichava/icon-sets-tabler', 'icon_count' => 6257]]))->toBe($doc)
33+
->and(withPackTableCounts($doc, []))->toBe($doc);
34+
});
35+
36+
it('keeps the real guide in step with the real catalogue', function () {
37+
$root = dirname(__DIR__, 2);
38+
$sets = json_decode((string) file_get_contents($root . '/icon-sets.json'), true, flags: JSON_THROW_ON_ERROR)['sets'];
39+
$doc = (string) file_get_contents($root . '/docs/installation.md');
40+
41+
expect(withPackTableCounts($doc, $sets))->toBe($doc);
42+
});

0 commit comments

Comments
 (0)