Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
89 changes: 89 additions & 0 deletions .github/workflows/develop-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
permissions:
contents: read
packages: write
pull-requests: write

steps:
- name: Checkout code
Expand Down Expand Up @@ -107,3 +108,91 @@ jobs:
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create deployment summary
run: |
echo "## Stage Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "βœ… Stage deployment completed successfully" >> $GITHUB_STEP_SUMMARY
echo "πŸš€ RC Version: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "🐳 Docker Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:stage" >> $GITHUB_STEP_SUMMARY
echo "🎯 Ready for production deployment" >> $GITHUB_STEP_SUMMARY

- name: Auto-create PR to main
if: success()
run: |
# Set up local tracking branches for comparison
git fetch --all
git checkout develop || git checkout -b develop origin/develop
git branch main origin/main 2>/dev/null || echo "main branch already exists"

# Check if there's already an open PR from develop to main
EXISTING_PR=$(gh pr list --state open --head develop --base main --json number --jq '.[0].number // empty')

if [ -n "$EXISTING_PR" ]; then
echo "βœ“ PR #$EXISTING_PR already exists from develop to main"
echo "πŸ“ Adding comment to existing PR with latest deployment results"
gh pr comment $EXISTING_PR --body "πŸš€ **Stage Deployment Successful**

βœ… New RC version deployed to staging: **${{ steps.version.outputs.version }}**
🐳 Docker images built and pushed successfully
πŸ“Š All tests passed in stage environment
πŸ”— Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
πŸ• Deployed: $(date -u +'%Y-%m-%d %H:%M:%S UTC')

**Ready for production deployment** 🎯"
else
echo "🎯 Creating new PR from develop to main"

# Get deployment info for PR description
LATEST_COMMIT_MSG=$(git log -1 --pretty=format:'%s')
COMMIT_COUNT=$(git rev-list --count origin/main..origin/develop)

# Create the PR
gh pr create \
--base main \
--head develop \
--title "πŸš€ Production Release: Deploy ${{ steps.version.outputs.version }} to Production" \
--body "## 🎯 Production Deployment Request

This PR was automatically created after successful stage deployment and validation.

### βœ… Stage Deployment Summary
- **RC Version**: ${{ steps.version.outputs.version }}
- **Docker Images**: Built and pushed to registry
- **Environment**: Stage deployment completed successfully
- **Tests**: All tests passed (unit, integration, stage validation)
- **Pre-release**: Created with tag v${{ steps.version.outputs.version }}

### πŸ“‹ Changes for Production
- **Commits**: $COMMIT_COUNT new commit(s) since last main branch
- **Latest commit**: $LATEST_COMMIT_MSG
- **Docker Image**: \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:stage\`

### πŸ”— Deployment Details
- **Stage Workflow**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- **Triggered by**: ${{ github.actor }}
- **Deployed**: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
- **Registry**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

### πŸš€ Production Checklist
- [x] Stage deployment successful
- [x] All automated tests passed
- [x] Docker images built and available
- [x] Pre-release created
- [ ] Manual verification in stage environment
- [ ] Production deployment approval

### πŸ“– Rollback Plan
Previous production version can be restored using:
\`\`\`bash
# Rollback to previous Docker image if needed
docker service update --image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:previous-tag product-catalog
\`\`\`

---
*This PR was automatically created by the Develop CI/CD workflow after successful stage deployment*"

echo "βœ… Production PR created successfully"
fi
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_CI || secrets.GITHUB_TOKEN }}
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ For a detailed guide on every aspect of this project, please refer to the docume
This Spring Boot application demonstrates enterprise-grade development practices and is production-ready.

### πŸ”„ **Development Workflow**
This project uses a **three-branch Git Flow strategy**:
- **`integration`** β†’ Feature integration and testing
- **`develop`** β†’ Stage deployment with RC versioning
This project uses a **fully automated three-branch Git Flow strategy**:
- **`integration`** β†’ Feature integration with automated PR creation to develop
- **`develop`** β†’ Stage deployment with RC versioning + automated PR creation to main
- **`main`** β†’ Production deployment with semantic versioning

**Workflow**: Feature branches β†’ `integration` β†’ `develop` β†’ `main`
**Automated Workflow**: Feature branches β†’ `integration` β†’ **auto-PR** β†’ `develop` β†’ **auto-PR** β†’ `main`

Both integration and develop branches automatically create pull requests to the next branch when CI/deployment succeeds, maintaining proper review gates while maximizing development velocity.

### πŸ“‹ **Known Issues / TODOs**
- 3 integration tests temporarily disabled pending investigation into database constraint edge cases. These issues do not affect core functionality or security.
171 changes: 158 additions & 13 deletions docs/06-DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,52 @@ When you push to `integration`, our **Auto-PR System** automatically:
- πŸ“ Includes detailed CI summary and commit information
- πŸ”„ Updates existing PR with new results if one already exists

**5. 🎯 Stage Preparation**
**5. 🎯 Stage Deployment & Auto-PR**
- Review the auto-generated PR from `integration` β†’ `develop`
- Approve and merge to trigger stage deployment
- Test in staging environment
- **Automatic**: Stage deployment creates auto-PR from `develop` β†’ `main`
- Test in staging environment and validate deployment

**6. πŸš€ Production Release**
- Create PR from `develop` β†’ `main`
- Final review and approval
- Review the auto-generated PR from `develop` β†’ `main`
- Final review and approval with production checklist
- Merge triggers production deployment with semantic versioning

## ⚑ Automated CI/CD Workflows

### πŸ€– Auto-PR Creation System
### πŸ€– Dual Auto-PR Creation System

Our **`integration-cd.yml`** workflow revolutionizes the development process:
Our **complete automation chain** revolutionizes the development process with **two automated PR workflows**:

#### How It Works
#### Integration β†’ Develop Workflow (`integration-cd.yml`)
1. **Trigger**: Push to `integration` branch
2. **CI Testing**: Comprehensive validation (unit tests, integration tests, formatting, environment config)
3. **Auto-PR Logic**:
- βœ… **CI Success** β†’ Automatically creates PR to `develop`
- ❌ **CI Failure** β†’ No PR created, developer notified
- πŸ”„ **Existing PR** β†’ Adds update comment instead of creating duplicate

#### Develop β†’ Main Workflow (`develop-cd.yml`)
1. **Trigger**: Successful merge to `develop` branch
2. **Stage Deployment**: RC versioning, Docker build, stage environment deployment
3. **Auto-PR Logic**:
- βœ… **Stage Success** β†’ Automatically creates PR to `main`
- πŸ“Š **Deployment Info** β†’ Includes RC version, Docker tags, test results
- πŸ”„ **Existing PR** β†’ Adds deployment update comment with latest stage results

#### What to Expect

**Auto-Generated PR Title:**
**Integration β†’ Develop PR Title:**
```
πŸš€ Integration β†’ Develop: Auto-promotion after CI success
```

**Auto-Generated PR Description:**
**Develop β†’ Main PR Title:**
```
πŸš€ Production Release: Deploy v1.0.0-RC.123 to Production
```

**Integration β†’ Develop PR Description:**
```markdown
## 🎯 Automated Promotion from Integration

Expand All @@ -113,19 +127,55 @@ This PR was automatically created after successful CI validation.
- Completed: 2024-01-15 14:30:22 UTC
```

**Develop β†’ Main PR Description:**
```markdown
## 🎯 Production Deployment Request

This PR was automatically created after successful stage deployment and validation.

### βœ… Stage Deployment Summary
- **RC Version**: 1.0.0-RC.123
- **Docker Images**: Built and pushed to registry
- **Environment**: Stage deployment completed successfully
- **Tests**: All tests passed (unit, integration, stage validation)
- **Pre-release**: Created with tag v1.0.0-RC.123

### πŸ“‹ Changes for Production
- **Commits**: 5 new commit(s) since last main branch
- **Latest commit**: feat: enhance product filtering capabilities
- **Docker Image**: `ghcr.io/the-dave-stack/product-catalog:stage`

### πŸš€ Production Checklist
- [x] Stage deployment successful
- [x] All automated tests passed
- [x] Docker images built and available
- [x] Pre-release created
- [ ] Manual verification in stage environment
- [ ] Production deployment approval
```

#### Developer Responsibilities

**For Integration β†’ Develop PRs:**
1. **Review Auto-Generated PRs**: Don't just merge automatically
2. **Test in Integration**: Ensure your changes work before pushing
3. **Monitor CI Status**: Check GitHub Actions for any failures
4. **Handle Failures**: Fix issues if CI fails (no PR will be created)

**For Develop β†’ Main PRs:**
1. **Validate Stage Deployment**: Verify the RC version works correctly in stage
2. **Review Production Checklist**: Ensure all deployment criteria are met
3. **Manual Testing**: Perform critical path testing in stage environment
4. **Monitor Deployment Metrics**: Check stage environment health and performance
5. **Rollback Preparation**: Understand rollback procedures before production merge

### πŸ“Š All CI/CD Workflows

| Workflow | Trigger | Purpose | Key Actions |
|----------|---------|---------|-------------|
| **pr-validation.yml** | PRs to main/develop/integration | Validate changes | Tests, formatting, environment validation |
| **integration-cd.yml** ⭐ | Push to integration | Auto-PR creation | CI tests + auto-create PR to develop |
| **develop-cd.yml** | Push to develop | Stage deployment | RC versioning, Docker build, stage deploy |
| **develop-cd.yml** ⭐ | Push to develop | Stage deployment + Auto-PR | RC versioning, Docker build, stage deploy, auto-create PR to main |
| **main-cd.yml** | Push to main | Production deployment | Semantic versioning, production deploy |
| **environment-validation.yml** | Scheduled/manual | Config validation | Environment consistency checks |

Expand Down Expand Up @@ -417,6 +467,70 @@ If you prefer not to use a PAT, you can enable repository-wide permissions:
2. Scroll to "Workflow permissions"
3. Enable "Allow GitHub Actions to create and approve pull requests"

### AI-Assisted Development Workflow (Single Developer)

For **single-developer repositories using AI agents** (like Claude Code), special considerations apply to the automated workflow:

#### Admin Override for AI Workflows

**Problem**: GitHub's branch protection prevents PR creators from approving their own PRs, which blocks AI-assisted development where the same account creates and needs to merge PRs.

**Solution**: Configure branch protection with **admin override enabled**:

**1. Branch Protection Configuration:**
- Both `develop` and `main` branches are configured with `enforce_admins: false`
- This allows repository administrators to override protection rules when needed
- Review requirements remain in place for normal development

**2. Admin Override Process:**
```bash
# When auto-generated PR needs merging after validation
gh pr merge [PR_NUMBER] --admin --merge

# Example: Merge integration β†’ develop PR after AI validation
gh pr merge 36 --admin --merge
```

**3. When to Use Admin Override:**
- βœ… AI-generated changes have been manually reviewed and validated
- βœ… All CI tests pass and code quality checks succeed
- βœ… Changes align with project requirements and security standards
- ❌ Never bypass review for complex or security-sensitive changes

**4. Safety Guidelines:**
```bash
# Always review the PR content before override
gh pr view [PR_NUMBER] --json title,body,additions,deletions

# Check CI status before merge
gh pr checks [PR_NUMBER]

# Verify no conflicts exist
gh pr status --repo [REPO_NAME]
```

**5. Alternative: Manual Review Process**
For critical changes, consider inviting a collaborator for genuine code review:
```bash
# Add temporary collaborator for review
gh api repos/OWNER/REPO/collaborators/USERNAME -X PUT

# Remove after review
gh api repos/OWNER/REPO/collaborators/USERNAME -X DELETE
```

#### AI Agent Validation Checklist

Before using admin override, ensure:
- [ ] **Code Quality**: All formatting and linting checks pass
- [ ] **Tests**: Unit, integration, and E2E tests are successful
- [ ] **Security**: No hardcoded secrets or security vulnerabilities
- [ ] **Functionality**: Changes work as expected in local environment
- [ ] **Documentation**: Any necessary documentation updates included
- [ ] **Rollback Plan**: Confident in ability to revert changes if needed

This workflow maintains code quality while enabling efficient AI-assisted development in single-developer environments.

## πŸ”§ Troubleshooting & FAQ

### Common Development Issues
Expand All @@ -427,6 +541,29 @@ Solution: This is actually expected behavior! Check the existing PR
from integration β†’ develop for an update comment with your latest CI results.
```

**❌ Problem: Develop deployment successful but no PR to main created**
```bash
# Check if stage deployment actually completed successfully
gh run list --branch develop --limit 3

# Look for develop-cd.yml workflow failure
gh run view [RUN_ID] --log

# Common causes:
# 1. Stage deployment failed (check Docker build/push steps)
# 2. PAT_FOR_CI secret missing or expired
# 3. Pre-release creation failed
# 4. No changes since last main merge
```

**❌ Problem: Production PR created but missing deployment information**
```
Solution: Check the develop-cd.yml workflow logs. The PR creation
step runs after successful stage deployment, so missing info usually
indicates a workflow step failure during RC version generation or
Docker image creation.
```

**❌ Problem: "GitHub Actions is not permitted to create pull requests"**
```bash
# Error message in workflow logs
Expand Down Expand Up @@ -575,14 +712,22 @@ mvn spotless:apply
# Check CI status
gh run list --branch integration

# Check auto-PR status
# Check auto-PR status (integration β†’ develop)
gh pr list --head integration --base develop

# Check auto-PR status (develop β†’ main)
gh pr list --head develop --base main

# Monitor complete automation chain
gh pr list --state open # Shows all active PRs

# Create feature branch
git checkout integration && git pull && git checkout -b feature/my-feature

# Test auto-PR workflow (push to integration)
git push origin integration # Triggers auto-PR creation if CI passes
# Complete automated workflow chain:
git push origin integration # 1. Triggers integration CI β†’ auto-PR to develop
# (Review & merge PR) β†’ 2. Triggers stage deployment β†’ auto-PR to main
# (Review & merge PR) β†’ 3. Triggers production deployment
```

**Important URLs:**
Expand Down
Loading