Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
117e761
updated latest neverthrow
fightbulc Mar 12, 2025
c6d5368
preparation for adopting storage types
fightbulc Mar 12, 2025
322ccd8
kv and turso are in
fightbulc Mar 12, 2025
32f74a7
added missing parts for the turso store
fightbulc Mar 12, 2025
cd2fbf4
added integration tests; started to add zod
fightbulc Mar 13, 2025
d23b603
updated integration tests and Message state
fightbulc Mar 13, 2025
2dfc537
added better auth handling; added system routes and tests
fightbulc Mar 13, 2025
af217ba
Implement comprehensive storage-specific logging system
fightbulc May 25, 2025
978ecb7
Add comprehensive CI/CD workflows for GitHub Actions and Deno Deploy
fightbulc May 25, 2025
ecf13d6
Update GitHub workflows to use Deno v2.3.3
fightbulc May 25, 2025
1785a9b
Fix code formatting issues
fightbulc May 25, 2025
c71e9ca
Fix Deno unstable API flags for CI/CD and deployment
fightbulc May 25, 2025
dfa2184
Use KV-only storage for CI tests to avoid libsql issues
fightbulc May 26, 2025
306cfed
Require explicit TURSO_DB_URL configuration
fightbulc May 26, 2025
f8899a4
Fix security audit false positive for SQL commands
fightbulc May 26, 2025
cd81773
Add required OIDC permissions for Deno Deploy workflows
fightbulc May 26, 2025
c7f93da
Fix Deno Deploy project names to use 'done-light'
fightbulc May 26, 2025
1963c57
Use src/main.ts directly and add required environment variables
fightbulc May 26, 2025
8af1cbf
Remove preview workflow in favor of Deno Deploy's branch model
fightbulc May 26, 2025
31ebe1e
Add required permissions for CI notification comments
fightbulc May 26, 2025
1a6b0b4
Update all dependencies to latest versions
fightbulc May 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APP_URL=http://localhost:3000
AUTH_TOKEN=1234567890
STORAGE_TYPE=turso
TURSO_DB_URL=:memory:
TURSO_AUTH_TOKEN=
ENABLE_LOGS=false
7 changes: 5 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
APP_URL=
AUTH_TOKEN=
APP_URL=http://localhost:3000
AUTH_TOKEN=1234567890
STORAGE_TYPE=turso
TURSO_DB_URL=:memory:
TURSO_AUTH_TOKEN=
ENABLE_LOGS=false
6 changes: 6 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APP_URL=http://localhost:3000
AUTH_TOKEN=test_token
STORAGE_TYPE=turso
TURSO_DB_URL=:memory:
TURSO_DB_AUTH_TOKEN=test_token
ENABLE_LOGS=false
261 changes: 261 additions & 0 deletions .github/DEPLOYMENT_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
# 🚀 Deployment Setup Guide

This guide explains how to set up GitHub workflows for automated CI/CD with Deno Deploy.

## 📋 Prerequisites

1. **GitHub Repository** with admin access
2. **Deno Deploy Account** ([signup](https://deno.com/deploy))
3. **Turso Account** for production database ([signup](https://turso.tech))

## 🔐 Required Secrets

Configure these secrets in your GitHub repository settings (`Settings > Secrets and variables > Actions`):

### **Repository Secrets**

```bash
# Deno Deploy Integration
DENO_DEPLOY_TOKEN=ddp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Production Environment
PRODUCTION_AUTH_TOKEN=your-secure-production-auth-token-here
PRODUCTION_TURSO_DB_URL=libsql://your-database-url.turso.io
PRODUCTION_TURSO_DB_AUTH_TOKEN=your-turso-auth-token-here
PRODUCTION_TEST_TOKEN=token-for-post-deployment-testing

# Staging Environment
STAGING_AUTH_TOKEN=your-staging-auth-token-here
STAGING_TURSO_DB_URL=libsql://your-staging-database-url.turso.io
STAGING_TURSO_DB_AUTH_TOKEN=your-staging-turso-auth-token-here

# Preview Environment
PREVIEW_AUTH_TOKEN=preview-token-12345
```

### **Repository Variables**

Configure these variables in `Settings > Secrets and variables > Actions > Variables`:

```bash
# Production Configuration
PRODUCTION_STORAGE_TYPE=TURSO
PRODUCTION_ENABLE_LOGS=true
PRODUCTION_ENABLE_AUTH=true

# Staging Configuration
STAGING_STORAGE_TYPE=KV
STAGING_ENABLE_LOGS=true
STAGING_ENABLE_AUTH=true
```

## 🏗️ Deno Deploy Setup

### 1. Create Deno Deploy Projects

Create these projects in your [Deno Deploy dashboard](https://dash.deno.com):

- `done-production` - Production environment
- `done-staging` - Staging environment
- `done-preview-pr-{number}` - Created automatically for PR previews

### 2. Get Deno Deploy Token

1. Go to [Deno Deploy Settings](https://dash.deno.com/account/settings)
2. Create a new **Access Token**
3. Copy the token and add it as `DENO_DEPLOY_TOKEN` secret in GitHub

### 3. Configure Project Settings

For each project, configure:

**Production Project (`done-production`):**
- **Custom Domain**: `done.yourdomain.com` (optional)
- **Environment Variables**: Set via GitHub workflow (automatic)

**Staging Project (`done-staging`):**
- **Custom Domain**: `done-staging.yourdomain.com` (optional)
- **Environment Variables**: Set via GitHub workflow (automatic)

## 🗄️ Database Setup

### Turso Database Configuration

1. **Create Turso Databases:**
```bash
# Production database
turso db create done-production

# Staging database
turso db create done-staging
```

2. **Get Connection Details:**
```bash
# Get database URLs
turso db show done-production
turso db show done-staging

# Create auth tokens
turso db tokens create done-production
turso db tokens create done-staging
```

3. **Run Migrations:**
```bash
# Production
turso db shell done-production < migrations/000_create_migrations_table.sql
turso db shell done-production < migrations/001_create_messages_table.sql
turso db shell done-production < migrations/002_create_logs_table.sql

# Staging
turso db shell done-staging < migrations/000_create_migrations_table.sql
turso db shell done-staging < migrations/001_create_messages_table.sql
turso db shell done-staging < migrations/002_create_logs_table.sql
```

## ⚙️ GitHub Repository Settings

### Branch Protection Rules

Set up branch protection for `main` branch (`Settings > Branches`):

```yaml
Protection Rules for 'main':
✅ Require a pull request before merging
✅ Require approvals: 1
✅ Dismiss stale PR approvals when new commits are pushed
✅ Require review from code owners

✅ Require status checks to pass before merging
✅ Require branches to be up to date before merging
Required Status Checks:
- Test & Lint
- Security Scan
- API Validation

✅ Require conversation resolution before merging
✅ Include administrators (recommended)
```

### Environment Protection Rules

Configure environment protection (`Settings > Environments`):

**Production Environment:**
- ✅ Required reviewers: [Your GitHub username]
- ✅ Wait timer: 5 minutes
- ✅ Deployment branches: `main` only

**Staging Environment:**
- ✅ Deployment branches: All branches

## 🔄 Workflow Overview

### **CI Workflow** (`ci.yml`)
**Triggers:** PRs to main, pushes to main
**Steps:**
1. Format & lint checks
2. Type checking
3. Run tests (KV + Turso)
4. Security scanning
5. API validation
6. PR status comments

### **Deployment Workflow** (`deploy.yml`)
**Triggers:** CI success, manual dispatch
**Steps:**
1. Run comprehensive tests
2. Deploy to staging/production
3. Health checks
4. Smoke tests (production)
5. Rollback on failure

### **Preview Workflow** (`preview.yml`)
**Triggers:** PR opened/updated
**Steps:**
1. Deploy PR to preview environment
2. Health check
3. Comment PR with preview URL
4. Cleanup on PR close

## 🧪 Testing the Setup

### 1. Test CI Pipeline
Create a test PR:
```bash
git checkout -b test/ci-setup
echo "# Test CI" >> TEST.md
git add TEST.md
git commit -m "test: verify CI pipeline"
git push origin test/ci-setup
```

### 2. Test Deployment
Merge to main or trigger manual deployment:
```bash
# Via GitHub UI: Actions > Deploy to Deno Deploy > Run workflow
```

### 3. Verify Deployments
Check your deployed applications:
- **Production**: `https://done-production.deno.dev/v1/system/ping`
- **Staging**: `https://done-staging.deno.dev/v1/system/ping`

## 🚨 Troubleshooting

### Common Issues

**❌ "DENO_DEPLOY_TOKEN not found"**
- Verify token is set in repository secrets
- Ensure token has correct permissions

**❌ "Database connection failed"**
- Check Turso URL and auth token
- Verify database exists and migrations ran

**❌ "Tests failing in CI"**
- Run tests locally: `deno task test`
- Check environment variables
- Verify all dependencies are available

**❌ "Deployment health check failed"**
- Check Deno Deploy logs
- Verify environment variables are set
- Test endpoints manually

### Getting Help

1. **Check workflow logs** in GitHub Actions tab
2. **Review Deno Deploy logs** in dashboard
3. **Test locally** with same environment variables
4. **Check documentation** for latest updates

## 🔧 Maintenance

### Regular Tasks

1. **Monitor deployments** via Deno Deploy dashboard
2. **Review dependency updates** from Dependabot
3. **Rotate secrets** every 90 days
4. **Update environment variables** as needed
5. **Review and update workflows** quarterly

### Security Best Practices

- ✅ Use environment-specific tokens
- ✅ Rotate secrets regularly
- ✅ Limit token permissions
- ✅ Review access logs
- ✅ Monitor for unauthorized deployments

---

## 📚 Additional Resources

- [Deno Deploy Documentation](https://deno.com/deploy/docs)
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
- [Turso Documentation](https://docs.turso.tech)
- [Repository Settings Guide](https://docs.github.com/en/repositories)

✅ **Your CI/CD pipeline is now ready for production!** 🎉
62 changes: 62 additions & 0 deletions .github/WORKFLOW_BADGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 📊 Workflow Status Badges

Add these badges to your README.md to show the status of your workflows:

## Copy-Paste Ready Badges

```markdown
[![CI](https://github.com/dnl-fm/done/actions/workflows/ci.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/ci.yml)
[![Deploy](https://github.com/dnl-fm/done/actions/workflows/deploy.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/deploy.yml)
[![Code Quality](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml)
```

## Individual Badges

### CI Pipeline
```markdown
[![CI](https://github.com/dnl-fm/done/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/dnl-fm/done/actions/workflows/ci.yml)
```

### Deployment Status
```markdown
[![Deploy](https://github.com/dnl-fm/done/actions/workflows/deploy.yml/badge.svg?branch=main)](https://github.com/dnl-fm/done/actions/workflows/deploy.yml)
```

### Code Quality
```markdown
[![Code Quality](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml)
```

### Preview Deployments
```markdown
[![Preview](https://github.com/dnl-fm/done/actions/workflows/preview.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/preview.yml)
```

## Custom Status Section

```markdown
## 🚀 Project Status

| Service | Status | Environment | URL |
|---------|--------|-------------|-----|
| Production | [![Deploy](https://github.com/dnl-fm/done/actions/workflows/deploy.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/deploy.yml) | Production | [done.deno.dev](https://done.deno.dev) |
| Staging | [![Deploy](https://github.com/dnl-fm/done/actions/workflows/deploy.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/deploy.yml) | Staging | [done-staging.deno.dev](https://done-staging.deno.dev) |
| Tests | [![CI](https://github.com/dnl-fm/done/actions/workflows/ci.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/ci.yml) | - | - |
| Code Quality | [![Code Quality](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml) | - | - |
```

## Recommendation

Add this section to the top of your README.md after the title:

```markdown
# Done - Webhook Queue Service

[![CI](https://github.com/dnl-fm/done/actions/workflows/ci.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/ci.yml)
[![Deploy](https://github.com/dnl-fm/done/actions/workflows/deploy.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/deploy.yml)
[![Code Quality](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml/badge.svg)](https://github.com/dnl-fm/done/actions/workflows/code-quality.yml)

> A reliable webhook delivery service with dual storage support (Deno KV + Turso)
```

**Note:** Replace `dnl-fm/done` with your actual GitHub repository path if different.
31 changes: 31 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2
updates:
# Enable version updates for Deno dependencies
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "09:00"
reviewers:
- "dnl-fm" # Replace with your GitHub username
assignees:
- "dnl-fm" # Replace with your GitHub username
commit-message:
prefix: "chore"
include: "scope"
labels:
- "dependencies"
- "github-actions"
open-pull-requests-limit: 5

# Monitor workflow changes
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "dnl-fm"
labels:
- "dependencies"
- "submodule"
Loading