#!/usr/bin/env bash
# One release, built in its own folder before it goes live (plan CORE §3.17; TuteDesk's, reji/docs/DEPLOYMENT.md). A
# zero-downtime deployer (Forge, Envoyer, Deployer) runs it from the new release's folder, after the release is made
# and before it is activated; the workers are restarted after activation (`php artisan queue:restart`), never here.
# Any failure stops the deployment and the previous release stays live.
set -Eeuo pipefail

PHP="${FORGE_PHP:-php}"
COMPOSER="${FORGE_COMPOSER:-composer}"

# shellcheck disable=SC2086   # a deployer's composer may be "php8.5 /usr/local/bin/composer"
$COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader
npm ci --no-audit --no-fund
npm run build
$PHP artisan backup:run --kind=predeploy   # the database as it was, before this release changes it (says so if backups aren't set up)
$PHP artisan app:deploy
