Files
speedBB/scripts/hooks/pre-commit
tracer 79f8077bd4
All checks were successful
CI/CD Pipeline / deploy (push) Successful in 24s
CI/CD Pipeline / promote_stable (push) Successful in 2s
Sync build to 100 and stage build update in pre-commit hook
2026-02-24 23:47:09 +01:00

29 lines
839 B
Bash

#!/usr/bin/env bash
set -euo pipefail
# 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");
'
git add composer.json