Make local master canonical for build metadata
This commit is contained in:
@@ -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");
|
||||
'
|
||||
|
||||
Reference in New Issue
Block a user