Skip to content

fix: support Laravel 9+ in deploy script and composer setup action #5

@tonyputi

Description

@tonyputi

Context

Two bugs discovered while investigating a failed deployment on tonyputi/sikaniaimmobiliare-com (run #23714054528).


Bug 1 — --graceful flag breaks Laravel 9 deployments (blocker)

File: scripts/deploy-laravel-app.sh, line 49

sudo -u $APP_USER php $RELEASE_PATH/artisan migrate --force --graceful --ansi -qn

The --graceful flag was introduced in Laravel 10. Any repo using Laravel 9 will fail at the migration step with:

The "--graceful" option does not exist.

Fix: auto-detect the Laravel major version at runtime and conditionally apply the flag:

echo "🗄️ Running migrations..."
GRACEFUL=""
LARAVEL_MAJOR=$(php $RELEASE_PATH/artisan --version 2>/dev/null | grep -oP 'Laravel Framework \K\d+' || echo "0")
if [ "${LARAVEL_MAJOR:-0}" -ge 10 ]; then
  GRACEFUL="--graceful"
fi
sudo -u $APP_USER php $RELEASE_PATH/artisan migrate --force $GRACEFUL --ansi -qn

Bug 2 — composer config cache-files-dir runs without working directory (non-blocking)

File: actions/setup/composer/action.yml, step Get composer cache directory

echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

Composer requires a composer.json in the current directory unless -g (global) or -d <dir> is passed. The runner's working directory is the repo root (not build/), so this step prints:

File "./composer.json" cannot be found in the current directory

The error is non-fatal (the workflow continues), but the cache path key ends up containing the error string instead of the actual cache directory, making the cache step ineffective.

Fix: add -d ${{ inputs.working_directory }} to the command:

echo "dir=$(composer config -d ${{ inputs.working_directory }} cache-files-dir)" >> $GITHUB_OUTPUT

Acceptance Criteria

  • scripts/deploy-laravel-app.sh detects Laravel version at runtime and applies --graceful only on Laravel 10+
  • actions/setup/composer/action.yml passes the correct working directory to composer config cache-files-dir
  • Deployments succeed for repos using Laravel 9.x
  • No regression for repos using Laravel 10+

Entry Points

  • scripts/deploy-laravel-app.sh — line 49
  • actions/setup/composer/action.yml — step Get composer cache directory

Test / Verification

  1. Trigger a deployment on a Laravel 9 repo — migration step must complete without errors
  2. Trigger a deployment on a Laravel 10+ repo — --graceful must still be applied
  3. Check that the composer cache key in the workflow log contains a valid directory path (e.g. /home/runner/.composer/cache/files)

Constraints

  • Do NOT add a workflow-level input for graceful_migrate — this is an implementation detail of the deploy script, not a caller concern
  • Do NOT break existing callers

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions