Files
kosipov c5580833f6
All checks were successful
Deploy back2 / deploy (push) Successful in 33s
fix deploy
2026-04-03 01:32:07 +03:00

88 lines
2.6 KiB
YAML

name: Deploy back2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup SSH key
run: |
set -euo pipefail
mkdir -p ~/.ssh
chmod 700 ~/.ssh
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "${DEPLOY_PORT:-22}" -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
- name: Deploy Laravel
run: |
set -euo pipefail
ssh -p "${DEPLOY_PORT:-22}" "$DEPLOY_USER@$DEPLOY_HOST" "DEPLOY_PATH='$DEPLOY_PATH' bash -s" <<'EOF'
set -euo pipefail
if [ -z "${DEPLOY_PATH:-}" ]; then
echo "DEPLOY_PATH is not set"
exit 1
fi
cd "$DEPLOY_PATH"
if [ ! -d .git ]; then
echo "Expected a git repository at $DEPLOY_PATH"
exit 1
fi
git fetch origin main
git checkout main
git reset --hard origin/main
PHP_BIN="/opt/php84/bin/php"
if [ ! -x "$PHP_BIN" ]; then
PHP_BIN="$(command -v php || true)"
fi
if [ -z "$PHP_BIN" ] || [ ! -x "$PHP_BIN" ]; then
echo "PHP binary not found"
exit 1
fi
COMPOSER_BIN="$(command -v composer || true)"
if [ -z "$COMPOSER_BIN" ]; then
echo "Composer binary not found"
exit 1
fi
if [ -f composer.json ]; then
"$PHP_BIN" "$COMPOSER_BIN" install --no-interaction --prefer-dist --optimize-autoloader --no-dev --no-scripts
fi
if [ -f artisan ]; then
rm -f bootstrap/cache/packages.php bootstrap/cache/services.php bootstrap/cache/config.php bootstrap/cache/events.php bootstrap/cache/routes-*.php
"$PHP_BIN" artisan down --retry=60 || true
trap '"$PHP_BIN" artisan up || true' EXIT
"$PHP_BIN" artisan optimize:clear
"$PHP_BIN" artisan package:discover --ansi
"$PHP_BIN" artisan migrate --force
"$PHP_BIN" artisan storage:link || true
"$PHP_BIN" artisan config:cache
"$PHP_BIN" artisan view:cache
"$PHP_BIN" artisan queue:restart || true
fi
EOF