# Deployment Configuration

## GitHub Actions Workflow

The CI/CD pipeline is configured in `.github/workflows/test.yml`.

### Workflow Triggers

| Event | Branch | Action |
|-------|--------|--------|
| Push | master, main, daybook | Run tests |
| Pull Request | master, main | Run tests + coverage |
| Merge to master | master | Run tests + deploy |

### Jobs

1. **test**: Run PHPUnit test suite
   - MySQL 8.0 and Redis 7 services
   - Composer dependency caching
   - Coverage report on PRs

2. **lint**: PHP syntax validation
   - Parallel syntax checking

3. **deploy**: Production deployment
   - Only runs after test and lint pass
   - Only on merge to master
   - Triggers Envoyer webhook

### Required Secrets

Configure these secrets in GitHub repository settings:

| Secret | Description |
|--------|-------------|
| `ENVOYER_WEBHOOK_URL` | Envoyer deployment webhook URL |

## PR Merge Requirements

To configure branch protection rules:

1. Go to **Settings > Branches > Branch protection rules**
2. Add rule for `master` branch
3. Enable:
   - **Require status checks to pass before merging**
   - Select: `PHPUnit Tests`, `PHP Syntax Check`
   - **Require branches to be up to date before merging**

## Manual Override Process

For emergency deployments when tests are failing:

### Option 1: Bypass Branch Protection (Admin Only)

1. Admin navigates to PR
2. Click "Merge pull request"
3. In the dropdown, select "Merge without waiting for requirements"
4. Confirm with admin credentials

### Option 2: Manual Envoyer Trigger

1. Log into Envoyer dashboard
2. Select the project
3. Click "Deploy" button
4. Monitor deployment progress

### Option 3: Command Line Deployment

```bash
# From project root
./deploy.sh
```

Note: This bypasses GitHub checks entirely. Only use in emergencies.

## Coverage Reporting

- **Threshold**: 80% for changed files (warning only)
- **Target**: 90% overall coverage
- **Reports**: Available as artifacts on PR checks

### Viewing Coverage

1. Open a Pull Request
2. Wait for workflow to complete
3. Click "Details" on the test check
4. Download "coverage-report" artifact

## Troubleshooting

### Tests timing out

The workflow has a 10-minute timeout. If tests exceed this:
- Profile slow tests with `--testsuite unit` vs `--testsuite integration`
- Consider parallelizing test execution

### MySQL connection failures

Check that the MySQL service is healthy:
- Wait for health check to pass
- Verify credentials match test environment

### Redis connection failures

Similar to MySQL - verify health check passes before tests run.
