Skip to content

Commit ab84912

Browse files
Create script to read current Phel version
1 parent 8024882 commit ab84912

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

build/update-phel-version.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/**
4+
* Update Phel version in config.toml based on installed Phel package version
5+
*/
6+
7+
$versionFinderFile = __DIR__ . '/../vendor/phel-lang/phel-lang/src/php/Console/Application/VersionFinder.php';
8+
$configFile = __DIR__ . '/../config.toml';
9+
10+
if (!file_exists($versionFinderFile)) {
11+
echo "Error: VersionFinder.php not found. Make sure phel-lang/phel-lang is installed.\n";
12+
exit(1);
13+
}
14+
15+
if (!file_exists($configFile)) {
16+
echo "Error: config.toml not found\n";
17+
exit(1);
18+
}
19+
20+
// Read VersionFinder.php to extract LATEST_VERSION constant
21+
$versionFinderContent = file_get_contents($versionFinderFile);
22+
23+
if (!$versionFinderContent) {
24+
echo "Error: Failed to read VersionFinder.php\n";
25+
exit(1);
26+
}
27+
28+
// Extract version from LATEST_VERSION constant
29+
$phelVersion = null;
30+
if (preg_match(
31+
'/public\s+const\s+string\s+LATEST_VERSION\s*=\s*[\'"]v?(\d+\.\d+\.\d+)[\'"]/',
32+
$versionFinderContent,
33+
$matches
34+
)) {
35+
$phelVersion = $matches[1];
36+
}
37+
38+
if (!$phelVersion) {
39+
echo "Warning: Could not determine Phel version from VersionFinder.php\n";
40+
exit(0);
41+
}
42+
43+
// Read config.toml
44+
$configContent = file_get_contents($configFile);
45+
46+
// Update version
47+
$updatedContent = preg_replace(
48+
'/^phel_version\s*=\s*"[^"]*"/m',
49+
'phel_version = "' . $phelVersion . '"',
50+
$configContent
51+
);
52+
53+
if ($updatedContent === $configContent) {
54+
echo "Phel version in config.toml is already up to date: $phelVersion\n";
55+
exit(0);
56+
}
57+
58+
// Write updated config
59+
file_put_contents($configFile, $updatedContent);
60+
61+
echo "Updated Phel version in config.toml to: $phelVersion\n";

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
"php build/api-page.php",
4242
"php build/api-search.php"
4343
],
44-
"test": "./vendor/bin/phpunit"
44+
"test": "./vendor/bin/phpunit",
45+
"post-install-cmd": [
46+
"php build/update-phel-version.php"
47+
],
48+
"post-update-cmd": [
49+
"php build/update-phel-version.php"
50+
]
4551
}
4652
}

0 commit comments

Comments
 (0)