# CI/CD Integration Guide

Integrate Provisioning with CI/CD pipelines for automated deployments.

## GitHub Actions Integration

Automate infrastructure deployment:

```yaml
name: Deploy Infrastructure

on:
  push:
    branches: [main]
    paths:
      - 'infrastructure/**'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Install Provisioning
        run: cargo install provisioning

      - name: Validate configuration
        run: provisioning infra validate

      - name: Plan deployment
        run: provisioning infra plan --output plan.json

      - name: Apply deployment
        run: provisioning infra apply --auto-approve

      - name: Run smoke tests
        run: provisioning test smoke-tests

      - name: Notify on failure
        if: failure()
        run: |
          curl -X POST ${{ secrets.SLACK_WEBHOOK }} \
            -d "{\"text\": \"❌ Infrastructure deployment failed\"}"
```

## GitOps Workflow

Use Git as source of truth:

```bash
#!/usr/bin/env nu

def gitops-deploy [commit-sha] {
  # Checkout specific commit
  git checkout $commit-sha

  # Apply infrastructure
  provisioning infra apply --from-git-commit $commit-sha

  # Verify deployment
  provisioning test smoke-tests
}
```

## Automated Rollback

Rollback on test failures:

```bash
#!/usr/bin/env nu

def deploy-with-rollback [] {
  let previous = (provisioning deployment current)

  try {
    provisioning infra apply
    provisioning test smoke-tests
  } catch { | err |
    print "Tests failed, rolling back..."
    provisioning deployment rollback --to $previous.id
    error "Deployment rolled back"
  }
}
```

## Related Documentation

- [CI/CD Pipeline Examples](../examples/cicd-pipeline-examples.md)
- [Testing Infrastructure](../development/testing-infrastructure.md)
- [Deployment Strategies](../operations/deployment-strategies.md)
