# Namecheap VPS CI CD Setup

This project now uses one GitHub Actions workflow for CI and deployment on the `main` branch.

## Files

- `.github/workflows/deploy.yml`
- `scripts/deploy.sh`

## How It Works

- Push to `main` runs tests and builds assets.
- GitHub uploads the deployment package to your VPS.
- GitHub runs `scripts/deploy.sh` on the VPS.
- The script creates missing Laravel directories, copies the uploaded `.env` file into the project root, extracts the new release into the same project directory, and runs Laravel optimization commands.

## GitHub Secrets Required

- `SSH_HOST`: VPS public IP or hostname
- `SSH_USER`: VPS SSH user
- `SSH_PRIVATE_KEY`: private key for that user
- `SSH_PORT`: optional, defaults to `22`
- `APP_ENV_FILE`: full production `.env` file contents
- `DEPLOY_PATH`: optional absolute path on VPS (recommended)

## Server Path

The deployment target is:

- `DEPLOY_PATH` secret value, if provided.
- Otherwise fallback: `$HOME/qhub.backend.api.qverselearning.org` for your SSH user.

Your web server should point to:

`<DEPLOY_PATH>/public`

## Notes

- No manual deployment commands are needed on the VPS.
- The `.env` file is kept in the project root as requested.
- Set `APP_DEBUG=false` inside `APP_ENV_FILE` for production.
- If deployment path permissions are wrong, the script exits with a clear message.
- The deploy script auto-attempts non-interactive `sudo` when the path is not writable.
- If `sudo -n` is unavailable and the path is not writable, use a writable `DEPLOY_PATH` or an SSH user that owns the path.
