|
| 1 | +# GitHub Actions Quick Start |
| 2 | + |
| 3 | +Get automated testing running in **30 seconds**! No signup required. |
| 4 | + |
| 5 | +## ⚡ 30-Second Setup |
| 6 | + |
| 7 | +```bash |
| 8 | +# Your workflow is already configured! |
| 9 | +# Just push to GitHub: |
| 10 | + |
| 11 | +git add .github/workflows/ci.yml |
| 12 | +git commit -m "Add GitHub Actions CI" |
| 13 | +git push origin main |
| 14 | +``` |
| 15 | + |
| 16 | +**That's it!** Go to your repository → **Actions** tab to watch it run. |
| 17 | + |
| 18 | +## What Just Happened? |
| 19 | + |
| 20 | +GitHub Actions will now automatically: |
| 21 | + |
| 22 | +1. ✅ **Run on every push** to any branch |
| 23 | +2. ✅ **Run on every pull request** |
| 24 | +3. ✅ **Test your code** (all 46 tests) |
| 25 | +4. ✅ **Report results** in PR comments |
| 26 | +5. ✅ **Cache dependencies** for faster builds |
| 27 | + |
| 28 | +## First Build |
| 29 | + |
| 30 | +### Expected Timeline |
| 31 | + |
| 32 | +``` |
| 33 | +0:00 - Checkout code (5 seconds) |
| 34 | +0:05 - Set up Java 17 (10 seconds) |
| 35 | +0:15 - Download dependencies (2-3 minutes) ⏱️ |
| 36 | +3:00 - Run tests (30 seconds) |
| 37 | +3:30 - Upload reports (10 seconds) |
| 38 | +✅ Done! (~4 minutes total) |
| 39 | +``` |
| 40 | + |
| 41 | +### Next Builds (With Cache) |
| 42 | + |
| 43 | +``` |
| 44 | +0:00 - Checkout code (5 seconds) |
| 45 | +0:05 - Set up Java 17 (10 seconds) |
| 46 | +0:15 - Restore cache (30 seconds) ⚡ |
| 47 | +0:45 - Run tests (30 seconds) |
| 48 | +1:15 - Upload reports (10 seconds) |
| 49 | +✅ Done! (~1.5 minutes total) |
| 50 | +``` |
| 51 | + |
| 52 | +## Viewing Your Build |
| 53 | + |
| 54 | +### In the Actions Tab |
| 55 | + |
| 56 | +1. Go to your GitHub repository |
| 57 | +2. Click **Actions** tab (top menu) |
| 58 | +3. See your workflow runs |
| 59 | + |
| 60 | +### In Pull Requests |
| 61 | + |
| 62 | +Test results appear automatically in PR comments: |
| 63 | + |
| 64 | +``` |
| 65 | +✅ All checks have passed |
| 66 | +• test — 46 tests passed |
| 67 | +• integration-test — 15 tests passed |
| 68 | +• build — Build successful |
| 69 | +``` |
| 70 | + |
| 71 | +## Understanding the Workflow |
| 72 | + |
| 73 | +### What Runs When |
| 74 | + |
| 75 | +``` |
| 76 | +Every push/PR: |
| 77 | +├─ test job |
| 78 | +│ └─ Runs all 46 tests |
| 79 | +│ |
| 80 | +├─ integration-test job |
| 81 | +│ └─ Runs repository tests |
| 82 | +│ |
| 83 | +└─ build job (main/develop only) |
| 84 | + └─ Builds JAR file |
| 85 | +``` |
| 86 | + |
| 87 | +### Jobs Run in Parallel |
| 88 | + |
| 89 | +``` |
| 90 | + test (1-2 min) |
| 91 | + ↓ |
| 92 | + integration-test (1-2 min) |
| 93 | + ↓ |
| 94 | + build (30 sec) ← Only on main/develop |
| 95 | +``` |
| 96 | + |
| 97 | +## Adding a Status Badge |
| 98 | + |
| 99 | +Show your build status in README.md: |
| 100 | + |
| 101 | +```markdown |
| 102 | + |
| 103 | +``` |
| 104 | + |
| 105 | +Replace `YOUR_USERNAME` with your GitHub username. |
| 106 | + |
| 107 | +**Result:** |
| 108 | + |
| 109 | + ← Shows build status |
| 110 | + |
| 111 | +## Common Scenarios |
| 112 | + |
| 113 | +### Scenario 1: Push to Feature Branch |
| 114 | + |
| 115 | +```bash |
| 116 | +git checkout -b feature/new-feature |
| 117 | +git commit -m "Add new feature" |
| 118 | +git push origin feature/new-feature |
| 119 | +``` |
| 120 | + |
| 121 | +**What happens:** |
| 122 | +- ✅ Tests run automatically |
| 123 | +- ✅ Results shown in GitHub |
| 124 | +- ❌ Build job DOES NOT run (not main/develop) |
| 125 | + |
| 126 | +### Scenario 2: Create Pull Request |
| 127 | + |
| 128 | +```bash |
| 129 | +# Create PR on GitHub |
| 130 | +``` |
| 131 | + |
| 132 | +**What happens:** |
| 133 | +- ✅ Tests run on PR |
| 134 | +- ✅ Results posted as PR comment |
| 135 | +- ✅ PR shows ✅ or ❌ status |
| 136 | +- ❌ Build job DOES NOT run (not merged yet) |
| 137 | + |
| 138 | +### Scenario 3: Merge to Main |
| 139 | + |
| 140 | +```bash |
| 141 | +git checkout main |
| 142 | +git merge feature/new-feature |
| 143 | +git push origin main |
| 144 | +``` |
| 145 | + |
| 146 | +**What happens:** |
| 147 | +- ✅ Tests run |
| 148 | +- ✅ Integration tests run |
| 149 | +- ✅ Build job runs (creates JAR) |
| 150 | +- ✅ JAR stored as artifact |
| 151 | + |
| 152 | +## Downloading Build Artifacts |
| 153 | + |
| 154 | +1. Go to **Actions** → Select a completed run |
| 155 | +2. Scroll down to **Artifacts** section |
| 156 | +3. Download available artifacts: |
| 157 | + - `test-reports` - Test HTML reports |
| 158 | + - `integration-test-reports` - Integration test reports |
| 159 | + - `library-management-jar` - Built JAR (main/develop only) |
| 160 | + |
| 161 | +## Troubleshooting |
| 162 | + |
| 163 | +### ❌ Build Failed: Tests Failed |
| 164 | + |
| 165 | +**Check what failed:** |
| 166 | +1. Click on the failed workflow |
| 167 | +2. Click on the failed job |
| 168 | +3. Expand the "Run tests" step |
| 169 | +4. See which test failed |
| 170 | + |
| 171 | +**Fix locally:** |
| 172 | +```bash |
| 173 | +mvn clean test |
| 174 | +``` |
| 175 | + |
| 176 | +### ❌ Build Failed: Workflow Syntax Error |
| 177 | + |
| 178 | +**Validate syntax:** |
| 179 | +```bash |
| 180 | +# Check YAML is valid |
| 181 | +cat .github/workflows/ci.yml |
| 182 | +``` |
| 183 | + |
| 184 | +**Common issues:** |
| 185 | +- Incorrect indentation (use 2 spaces) |
| 186 | +- Missing quotes around values |
| 187 | +- Typos in action names |
| 188 | + |
| 189 | +### ⚠️ Build is Slow |
| 190 | + |
| 191 | +**First build:** 3-4 minutes is normal (downloading deps) |
| 192 | +**Second build:** Should be ~1-2 minutes (cache working) |
| 193 | + |
| 194 | +**If still slow:** |
| 195 | +- Check cache is working (look for "Cache restored" in logs) |
| 196 | +- Maven might be re-downloading dependencies |
| 197 | + |
| 198 | +## Next Steps |
| 199 | + |
| 200 | +### Optional Enhancements |
| 201 | + |
| 202 | +1. **Add code coverage** (see `ci-coverage.yml`): |
| 203 | + ```bash |
| 204 | + mv .github/workflows/ci-coverage.yml .github/workflows/ci.yml |
| 205 | + ``` |
| 206 | + |
| 207 | +2. **Set up Codecov** for coverage tracking: |
| 208 | + - Sign up at codecov.io |
| 209 | + - Add `CODECOV_TOKEN` to GitHub secrets |
| 210 | + - Uncomment Codecov step in `ci-coverage.yml` |
| 211 | + |
| 212 | +3. **Add notifications:** |
| 213 | + - Slack integration |
| 214 | + - Discord webhooks |
| 215 | + - Email on failure only |
| 216 | + |
| 217 | +4. **Deploy on success:** |
| 218 | + - Heroku deployment |
| 219 | + - Docker image build |
| 220 | + - AWS/GCP deployment |
| 221 | + |
| 222 | +## Cheat Sheet |
| 223 | + |
| 224 | +### View Logs |
| 225 | +``` |
| 226 | +Repository → Actions → Select run → Click job → View logs |
| 227 | +``` |
| 228 | + |
| 229 | +### Re-run Failed Build |
| 230 | +``` |
| 231 | +Failed run → Re-run all jobs button (top right) |
| 232 | +``` |
| 233 | + |
| 234 | +### Cancel Running Build |
| 235 | +``` |
| 236 | +Running build → Cancel workflow button (top right) |
| 237 | +``` |
| 238 | + |
| 239 | +### Download Artifacts |
| 240 | +``` |
| 241 | +Completed run → Scroll to Artifacts → Click to download |
| 242 | +``` |
| 243 | + |
| 244 | +### View Test Results |
| 245 | +``` |
| 246 | +Completed run → See test summary at top |
| 247 | +Pull Request → See checks section |
| 248 | +``` |
| 249 | + |
| 250 | +## Free Tier Limits |
| 251 | + |
| 252 | +**Private repos:** 2,000 minutes/month |
| 253 | +- Your usage: ~2 min/build |
| 254 | +- **You can run ~1,000 builds/month** ✅ |
| 255 | + |
| 256 | +**Public repos:** **UNLIMITED** ✅ |
| 257 | + |
| 258 | +## Why GitHub Actions > CircleCI |
| 259 | + |
| 260 | +For your project: |
| 261 | + |
| 262 | +| Aspect | GitHub Actions | CircleCI | |
| 263 | +|--------|----------------|----------| |
| 264 | +| Setup | ✅ Zero config | ❌ Signup + OAuth | |
| 265 | +| Cost | ✅ 2,000 min free | 6,000 min free | |
| 266 | +| Integration | ✅ Native | ❌ Third-party | |
| 267 | +| PR Comments | ✅ Built-in | ❌ Requires setup | |
| 268 | +| Artifacts | ✅ Free | ⚠️ Limited | |
| 269 | +| UI | ✅ In GitHub | ❌ Separate site | |
| 270 | + |
| 271 | +**GitHub Actions is the clear winner!** ✅ |
| 272 | + |
| 273 | +## Success Checklist |
| 274 | + |
| 275 | +After your first build: |
| 276 | + |
| 277 | +- [ ] Workflow runs successfully |
| 278 | +- [ ] All 46 tests pass |
| 279 | +- [ ] Test results visible in Actions tab |
| 280 | +- [ ] Cache works on second build (faster) |
| 281 | +- [ ] Status badge shows in README (if added) |
| 282 | +- [ ] Artifacts available for download |
| 283 | + |
| 284 | +## What's Running? |
| 285 | + |
| 286 | +Your current setup tests: |
| 287 | + |
| 288 | +``` |
| 289 | +✅ 16 UserRepository tests |
| 290 | +✅ 15 BookRepository tests |
| 291 | +✅ 15 BorrowingRepository tests |
| 292 | +───────────────────────────── |
| 293 | +✅ 46 total tests |
| 294 | +``` |
| 295 | + |
| 296 | +**All running automatically on every commit!** 🎉 |
| 297 | + |
| 298 | +## Get Help |
| 299 | + |
| 300 | +- **Not working?** Check workflow logs in Actions tab |
| 301 | +- **Syntax error?** Validate YAML indentation |
| 302 | +- **Tests failing?** Run `mvn test` locally first |
| 303 | +- **Need more?** Check [README.md](.github/workflows/README.md) |
| 304 | + |
| 305 | +--- |
| 306 | + |
| 307 | +**You're all set! Push your code and watch the magic happen.** ✨ |
0 commit comments