Make local master canonical for build metadata
All checks were successful
CI/CD Pipeline / deploy (push) Successful in 24s
CI/CD Pipeline / promote_stable (push) Successful in 2s

This commit is contained in:
2026-02-24 23:10:16 +01:00
parent 60c6718645
commit 86190c9718
2 changed files with 25 additions and 44 deletions

View File

@@ -1,8 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail
# Keep commits possible when local DB is offline.
if ! php artisan version:fetch >/dev/null 2>&1; then
echo "pre-commit: skipped 'php artisan version:fetch' (database unreachable)." >&2
echo "pre-commit: start MySQL and run it manually when needed." >&2
fi
# Stamp composer.json build from local git commit count on master/HEAD.
BUILD="$(git rev-list --count master 2>/dev/null || git rev-list --count HEAD)"
BUILD="$BUILD" php -r '
$path = "composer.json";
$data = json_decode(file_get_contents($path), true);
if (!is_array($data)) {
fwrite(STDERR, "pre-commit: invalid composer.json\n");
exit(1);
}
$build = getenv("BUILD");
if ($build === false || $build === "") {
fwrite(STDERR, "pre-commit: missing BUILD value\n");
exit(1);
}
$current = (string)($data["build"] ?? "");
if ($current === $build) {
exit(0);
}
$data["build"] = $build;
file_put_contents($path, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
fwrite(STDOUT, "pre-commit: composer.json build updated to {$build}\n");
'