diff --git a/.husky/pre-commit b/.husky/pre-commit index 25e1c0de..80913585 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -70,34 +70,32 @@ print_result() { run_command() { print_task "$1" start_time=$(date +%s.%N) - output=$($2 2>&1) || true + output=$($2 2>&1) exit_code=$? end_time=$(date +%s.%N) duration=$(echo "$end_time - $start_time" | bc) # Debug: Print full command output -# echo "Debug: Command output for $1:" >&2 -# echo "$output" >&2 -# echo "Debug: End of command output for $1" >&2 + #echo "Debug: Command output for $1:" >&2 + #echo "$output" >&2 + #echo "Debug: End of command output for $1" >&2 - if [ "$1" = "Running static analysis" ]; then - if echo "$output" | grep -q "\[ERROR\]"; then + if [ "$1" = "Running Static Analysis" ]; then + if [ $exit_code -ne 0 ] || echo "$output" | grep -q "\[ERROR\]"; then print_result 1 printf " ${RED}(%.2fs)${NC}\n" "$duration" printf "\n${RED}Static Analysis Error:${NC}\n" + echo "$output" | sed -n '/^-----/,/^-----/p' | while IFS= read -r line; do + printf "${YELLOW}%s${NC}\n" "$line" + done echo "$output" | grep "\[ERROR\]" | while IFS= read -r line; do printf "${RED}%s${NC}\n" "$line" done return 1 - elif [ $exit_code -eq 0 ]; then + else print_result 0 printf " ${GREEN}(%.2fs) No errors found${NC}\n" "$duration" return 0 - else - print_result 1 - printf " ${RED}(%.2fs)${NC}\n" "$duration" - printf "\n${RED}Error output:${NC}\n%s\n\n" "$output" - return 1 fi elif [ "$1" = "Running Pest tests" ] || [ "$1" = "Running Dusk tests" ]; then if echo "$output" | grep -q "No \"dirty\" tests found"; then diff --git a/app/Console/Commands/RefreshApplicationForDeployment.php b/app/Console/Commands/RefreshApplicationForDeployment.php index 618e32bf..89d4ae22 100644 --- a/app/Console/Commands/RefreshApplicationForDeployment.php +++ b/app/Console/Commands/RefreshApplicationForDeployment.php @@ -1,5 +1,7 @@ components->task('Checking version cache', function () { + $this->components->task('Checking version cache', function (): string|true { $currentVersion = $this->getCurrentVersion(); $cachedVersion = Cache::get($this->versionCacheKey); @@ -156,7 +158,7 @@ private function getCurrentVersion(): ?string $version = trim(File::get($path)); - if (empty($version)) { + if ($version === '' || $version === '0') { $this->components->warn("Version file is empty: {$this->versionFile}"); return null; @@ -231,13 +233,13 @@ private function optimizeApplication(): void /** * Run an Artisan command and handle its output. * - * @param string $description The description of the task - * @param string $command The Artisan command to run - * @param array $parameters The parameters for the Artisan command + * @param string $description The description of the task + * @param string $command The Artisan command to run + * @param array $parameters The parameters for the Artisan command */ private function runArtisanCommand(string $description, string $command, array $parameters = []): void { - $this->components->task($description, function () use ($command, $parameters) { + $this->components->task($description, function () use ($command, $parameters): bool { try { $this->info("Running Artisan command: {$command}"); Artisan::call($command, $parameters); diff --git a/tests/Feature/Console/Commands/RefreshApplicationForDeploymentTest.php b/tests/Feature/Console/Commands/RefreshApplicationForDeploymentTest.php index 1e4a1e96..3bd8747f 100644 --- a/tests/Feature/Console/Commands/RefreshApplicationForDeploymentTest.php +++ b/tests/Feature/Console/Commands/RefreshApplicationForDeploymentTest.php @@ -1,32 +1,34 @@ command = new RefreshApplicationForDeployment; // Create a new array cache store for testing $this->cache = Cache::store('array'); }); -it('fails when in debug mode without force option', function () { +it('fails when in debug mode without force option', function (): void { config(['app.debug' => true]); $this->artisan(RefreshApplicationForDeployment::class) ->assertFailed(); }); -it('succeeds when not in debug mode', function () { +it('succeeds when not in debug mode', function (): void { config(['app.debug' => false]); $this->artisan(RefreshApplicationForDeployment::class) ->assertSuccessful(); }); -it('skips migrations when --skip-migrations option is used', function () { +it('skips migrations when --skip-migrations option is used', function (): void { config(['app.debug' => false]); $this->artisan(RefreshApplicationForDeployment::class, ['--skip-migrations' => true]) @@ -34,7 +36,7 @@ ->assertSuccessful(); }); -it('skips cache operations when --skip-cache option is used', function () { +it('skips cache operations when --skip-cache option is used', function (): void { config(['app.debug' => false]); $this->artisan(RefreshApplicationForDeployment::class, ['--skip-cache' => true]) @@ -42,7 +44,7 @@ ->assertSuccessful(); }); -it('clears version cache when versions do not match', function () { +it('clears version cache when versions do not match', function (): void { config(['app.debug' => false]); File::shouldReceive('exists')->andReturn(true); @@ -55,7 +57,7 @@ expect($this->cache->has('vanguard_version'))->toBeFalse(); }); -it('does not clear version cache when versions match', function () { +it('does not clear version cache when versions match', function (): void { config(['app.debug' => false]); File::shouldReceive('exists')->andReturn(true); @@ -68,14 +70,14 @@ expect($this->cache->has('vanguard_version'))->toBeTrue(); }); -it('logs deployment details', function () { +it('logs deployment details', function (): void { config(['app.debug' => false]); File::shouldReceive('exists')->andReturn(true); File::shouldReceive('get')->andReturn('1.0.0'); Log::shouldReceive('info') ->once() - ->withArgs(fn ($message) => str_contains($message, 'Deployment completed. Version: 1.0.0')); + ->withArgs(fn ($message): bool => str_contains((string) $message, 'Deployment completed. Version: 1.0.0')); $this->artisan(RefreshApplicationForDeployment::class)->assertSuccessful(); });