|
| 1 | +# Continuous Integration Setup Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | +This guide will help you set up GitHub Actions CI/CD for your Java + Maven TodoApp project. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | +- GitHub account |
| 8 | +- Repository hosted on GitHub |
| 9 | +- Maven project with `pom.xml` |
| 10 | + |
| 11 | +## Setup Steps |
| 12 | + |
| 13 | +### 1. Repository Setup |
| 14 | +1. **Push your code to GitHub** (if not already done): |
| 15 | + ```bash |
| 16 | + git add . |
| 17 | + git commit -m "Add CI workflow" |
| 18 | + git push origin main |
| 19 | + ``` |
| 20 | + |
| 21 | +### 2. GitHub Actions Workflow Files |
| 22 | +Two workflow files have been created: |
| 23 | + |
| 24 | +#### Option A: Enhanced CI Pipeline (`ci.yml`) |
| 25 | +- **Features**: Caching, artifact uploads, PR comments, multiple triggers |
| 26 | +- **Best for**: Production projects with active development |
| 27 | + |
| 28 | +#### Option B: Simple CI Pipeline (`ci-simple.yml`) |
| 29 | +- **Features**: Basic build, test, and coverage |
| 30 | +- **Best for**: Learning or simple projects |
| 31 | + |
| 32 | +### 3. Activate GitHub Actions |
| 33 | +1. Go to your GitHub repository |
| 34 | +2. Click on the **"Actions"** tab |
| 35 | +3. You should see your workflow files listed |
| 36 | +4. Click on **"CI Pipeline"** or **"Simple CI Pipeline"** |
| 37 | +5. Click **"Enable workflow"** |
| 38 | + |
| 39 | +### 4. Trigger Your First Build |
| 40 | +The CI will automatically run when you: |
| 41 | +- Push code to `main`, `master`, or `develop` branches |
| 42 | +- Create a pull request to these branches |
| 43 | +- Manually trigger from the Actions tab |
| 44 | + |
| 45 | +## Workflow Features |
| 46 | + |
| 47 | +### Enhanced CI Pipeline Features: |
| 48 | +- ✅ **Multi-branch support** (main, master, develop) |
| 49 | +- ✅ **Maven dependency caching** (faster builds) |
| 50 | +- ✅ **Test result artifacts** (downloadable reports) |
| 51 | +- ✅ **Coverage report artifacts** (JaCoCo reports) |
| 52 | +- ✅ **JAR artifact uploads** (built applications) |
| 53 | +- ✅ **PR comments** (automatic test result summaries) |
| 54 | +- ✅ **Java 17 with Temurin distribution** |
| 55 | + |
| 56 | +### Simple CI Pipeline Features: |
| 57 | +- ✅ **Basic build and test** |
| 58 | +- ✅ **Coverage report generation** |
| 59 | +- ✅ **Java 17 setup** |
| 60 | + |
| 61 | +## Monitoring CI Runs |
| 62 | + |
| 63 | +### 1. View Build Status |
| 64 | +- Go to **Actions** tab in your repository |
| 65 | +- Click on any workflow run to see details |
| 66 | +- Green checkmark = Success ✅ |
| 67 | +- Red X = Failure ❌ |
| 68 | +- Yellow circle = In Progress ⏳ |
| 69 | + |
| 70 | +### 2. Download Artifacts |
| 71 | +- Click on a successful build |
| 72 | +- Scroll to **"Artifacts"** section |
| 73 | +- Download: |
| 74 | + - `test-results`: Test execution reports |
| 75 | + - `coverage-reports`: JaCoCo coverage HTML reports |
| 76 | + - `jar-artifacts`: Built JAR files |
| 77 | + |
| 78 | +### 3. View Coverage Reports |
| 79 | +1. Download `coverage-reports` artifact |
| 80 | +2. Extract the ZIP file |
| 81 | +3. Open `index.html` in a web browser |
| 82 | +4. View detailed coverage metrics |
| 83 | + |
| 84 | +## Troubleshooting |
| 85 | + |
| 86 | +### Common Issues: |
| 87 | + |
| 88 | +#### 1. "No workflow file found" |
| 89 | +- Ensure `.github/workflows/` directory exists |
| 90 | +- Check file is named `ci.yml` or `ci-simple.yml` |
| 91 | +- Verify YAML syntax is correct |
| 92 | + |
| 93 | +#### 2. "Java version not found" |
| 94 | +- The workflow uses Java 17 (Temurin distribution) |
| 95 | +- Ensure your `pom.xml` is compatible with Java 17 |
| 96 | +- Check Maven compiler plugin configuration |
| 97 | + |
| 98 | +#### 3. "Tests failing" |
| 99 | +- Check test output in Actions logs |
| 100 | +- Ensure all dependencies are in `pom.xml` |
| 101 | +- Verify test files are in `src/test/java/` |
| 102 | + |
| 103 | +#### 4. "Maven build failing" |
| 104 | +- Check for compilation errors |
| 105 | +- Verify all required dependencies |
| 106 | +- Ensure `pom.xml` is valid |
| 107 | + |
| 108 | +### Debug Steps: |
| 109 | +1. **Check Actions logs**: Click on failed step for detailed error messages |
| 110 | +2. **Test locally**: Run `mvn clean test` on your machine |
| 111 | +3. **Validate YAML**: Use online YAML validators |
| 112 | +4. **Check permissions**: Ensure GitHub Actions is enabled for your repository |
| 113 | + |
| 114 | +## Customization Options |
| 115 | + |
| 116 | +### Modify Triggers: |
| 117 | +```yaml |
| 118 | +on: |
| 119 | + push: |
| 120 | + branches: [ main, develop ] |
| 121 | + paths: [ 'src/**', 'pom.xml' ] # Only trigger on source changes |
| 122 | + pull_request: |
| 123 | + branches: [ main ] |
| 124 | + schedule: |
| 125 | + - cron: '0 2 * * 1' # Weekly on Monday at 2 AM |
| 126 | +``` |
| 127 | +
|
| 128 | +### Add More Steps: |
| 129 | +```yaml |
| 130 | +- name: Run Checkstyle |
| 131 | + run: mvn checkstyle:check |
| 132 | + |
| 133 | +- name: Generate Javadoc |
| 134 | + run: mvn javadoc:javadoc |
| 135 | + |
| 136 | +- name: Deploy to staging |
| 137 | + if: github.ref == 'refs/heads/develop' |
| 138 | + run: echo "Deploy to staging environment" |
| 139 | +``` |
| 140 | +
|
| 141 | +### Environment Variables: |
| 142 | +```yaml |
| 143 | +env: |
| 144 | + MAVEN_OPTS: -Xmx1024m |
| 145 | + JAVA_OPTS: -Dfile.encoding=UTF-8 |
| 146 | +``` |
| 147 | +
|
| 148 | +## Best Practices |
| 149 | +
|
| 150 | +1. **Keep workflows fast**: Use caching for dependencies |
| 151 | +2. **Fail fast**: Run quick checks first (compile, then test) |
| 152 | +3. **Parallel jobs**: Split into multiple jobs for large projects |
| 153 | +4. **Security**: Use GitHub secrets for sensitive data |
| 154 | +5. **Notifications**: Set up email/Slack notifications for failures |
| 155 | +
|
| 156 | +## Next Steps |
| 157 | +
|
| 158 | +1. **Set up branch protection**: Require CI to pass before merging |
| 159 | +2. **Add deployment**: Deploy to staging/production on successful builds |
| 160 | +3. **Code quality gates**: Add SonarQube or similar tools |
| 161 | +4. **Security scanning**: Add dependency vulnerability checks |
| 162 | +5. **Performance testing**: Add load testing to your pipeline |
| 163 | +
|
| 164 | +## Support |
| 165 | +
|
| 166 | +- [GitHub Actions Documentation](https://docs.github.com/en/actions) |
| 167 | +- [Maven GitHub Actions](https://github.com/actions/setup-java) |
| 168 | +- [Java CI/CD Examples](https://github.com/actions/starter-workflows/tree/main/ci) |
0 commit comments