|
| 1 | +# GitHub Workflows |
| 2 | + |
| 3 | +This directory contains GitHub Actions workflows for CI/CD automation. |
| 4 | + |
| 5 | +## Workflows |
| 6 | + |
| 7 | +### CI (`ci.yml`) |
| 8 | + |
| 9 | +Runs on every pull request to `main` and on pushes to `main`. |
| 10 | + |
| 11 | +**What it does:** |
| 12 | +- Runs multiple quality checks in parallel for speed |
| 13 | +- Compiles the project once and shares build artifacts |
| 14 | +- Checks code formatting with `erlfmt` |
| 15 | +- Runs `xref` (cross-reference analysis) |
| 16 | +- Runs `dialyzer` (type checking) |
| 17 | +- Runs all `eunit` tests |
| 18 | +- Uses PostgreSQL 16 service container for testing |
| 19 | +- Caches dependencies and PLT for faster builds |
| 20 | +- Uploads test results as artifacts |
| 21 | + |
| 22 | +**Test Environment:** |
| 23 | +- Erlang/OTP: 28.3.1 |
| 24 | +- rebar3: 3.26.0 |
| 25 | +- PostgreSQL: 16 |
| 26 | + |
| 27 | +**Job Execution Flow:** |
| 28 | +``` |
| 29 | +┌─────────────┐ |
| 30 | +│ Format │ (runs independently) |
| 31 | +└─────────────┘ |
| 32 | +
|
| 33 | +┌─────────────┐ |
| 34 | +│ Compile │ (compiles and uploads artifacts) |
| 35 | +└─────────────┘ |
| 36 | + │ |
| 37 | + ├──────────────┬──────────────┬──────────────┐ |
| 38 | + ▼ ▼ ▼ ▼ |
| 39 | +┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ |
| 40 | +│ Xref │ │ Dialyzer │ │ Tests │ (parallel) |
| 41 | +└──────────┘ └──────────┘ └──────────┘ |
| 42 | +``` |
| 43 | + |
| 44 | +**Quality Checks (run in parallel after compile):** |
| 45 | +1. **Code Formatting** - Runs independently (fastest) |
| 46 | +2. **Compile** - Builds project once, shares with other jobs |
| 47 | +3. **Xref** - Cross-reference analysis (parallel) |
| 48 | +4. **Dialyzer** - Type checking (parallel, uses PLT cache) |
| 49 | +5. **Tests** - Full test suite with PostgreSQL (parallel) |
| 50 | + |
| 51 | +### Release (`release.yml`) |
| 52 | + |
| 53 | +**Automatically creates releases** when code is merged to `main` (excluding documentation-only changes). |
| 54 | + |
| 55 | +**What it does:** |
| 56 | +1. Gets the latest git tag (or `v0.0.0` if none exists) |
| 57 | +2. Determines version bump type based on commit messages: |
| 58 | + - **Major bump** (1.0.0 → 2.0.0): Breaking changes |
| 59 | + - **Minor bump** (1.0.0 → 1.1.0): New features |
| 60 | + - **Patch bump** (1.0.0 → 1.0.1): Bug fixes and other changes |
| 61 | +3. Calculates new version number |
| 62 | +4. Updates `src/dram.app.src` with new version |
| 63 | +5. Generates categorized release notes from commits |
| 64 | +6. Creates git tag and GitHub release |
| 65 | +7. Commits version bump back to main |
| 66 | + |
| 67 | +**Version Bump Logic:** |
| 68 | +- `feat!:` or `BREAKING CHANGE:` → **Major** bump |
| 69 | +- `feat:` or `feature:` → **Minor** bump |
| 70 | +- `fix:`, `bugfix:`, or any other commit → **Patch** bump |
| 71 | + |
| 72 | +**Automatic Release Notes:** |
| 73 | +- Categorizes commits: Breaking Changes, Features, Bug Fixes, Other Changes |
| 74 | +- Includes installation instructions |
| 75 | +- Adds link to full changelog |
| 76 | + |
| 77 | +## Creating a Release |
| 78 | + |
| 79 | +### Simple Workflow (Recommended) |
| 80 | + |
| 81 | +Just merge your PR to `main` - releases happen automatically! |
| 82 | + |
| 83 | +1. **Create a feature branch:** |
| 84 | + ```bash |
| 85 | + git checkout -b feature/my-awesome-feature |
| 86 | + ``` |
| 87 | + |
| 88 | +2. **Make your changes and commit using conventional commits:** |
| 89 | + ```bash |
| 90 | + # For a new feature (minor version bump) |
| 91 | + git commit -m "feat: add unique jobs support" |
| 92 | + |
| 93 | + # For a bug fix (patch version bump) |
| 94 | + git commit -m "fix: correct pattern matching in job claiming" |
| 95 | + |
| 96 | + # For a breaking change (major version bump) |
| 97 | + git commit -m "feat!: change job insertion API" |
| 98 | + # or |
| 99 | + git commit -m "feat: new API |
| 100 | +
|
| 101 | + BREAKING CHANGE: The insert function now requires an options map" |
| 102 | + ``` |
| 103 | + |
| 104 | +3. **Push and create PR:** |
| 105 | + ```bash |
| 106 | + git push origin feature/my-awesome-feature |
| 107 | + ``` |
| 108 | + |
| 109 | +4. **Merge the PR:** |
| 110 | + - CI tests will run automatically |
| 111 | + - Once merged, the release workflow automatically: |
| 112 | + - Bumps version based on commits |
| 113 | + - Creates tag `vX.Y.Z` |
| 114 | + - Publishes GitHub release with notes |
| 115 | + - Updates `src/dram.app.src` |
| 116 | + |
| 117 | +### Conventional Commit Format |
| 118 | + |
| 119 | +Use these prefixes to control version bumping: |
| 120 | + |
| 121 | +**Major version bump (breaking changes):** |
| 122 | +```bash |
| 123 | +feat!: change job insertion API |
| 124 | +fix!: remove deprecated cancel_all function |
| 125 | +``` |
| 126 | + |
| 127 | +**Minor version bump (new features):** |
| 128 | +```bash |
| 129 | +feat: add unique jobs feature |
| 130 | +feature: implement job priorities |
| 131 | +``` |
| 132 | + |
| 133 | +**Patch version bump (fixes and other):** |
| 134 | +```bash |
| 135 | +fix: correct timeout handling |
| 136 | +bugfix: resolve connection pool issue |
| 137 | +docs: update README |
| 138 | +chore: update dependencies |
| 139 | +refactor: simplify queue logic |
| 140 | +test: add more test cases |
| 141 | +``` |
| 142 | + |
| 143 | +### Release Notes Example |
| 144 | + |
| 145 | +For commits: |
| 146 | +``` |
| 147 | +feat: add unique jobs support |
| 148 | +fix: correct pattern matching bug |
| 149 | +chore: update dependencies |
| 150 | +``` |
| 151 | + |
| 152 | +The workflow generates: |
| 153 | +```markdown |
| 154 | +# Dram 0.2.0 |
| 155 | + |
| 156 | +## What's Changed |
| 157 | + |
| 158 | +### ✨ Features |
| 159 | +- feat: add unique jobs support (a1b2c3d) |
| 160 | + |
| 161 | +### 🐛 Bug Fixes |
| 162 | +- fix: correct pattern matching bug (d4e5f6g) |
| 163 | + |
| 164 | +### 📝 Other Changes |
| 165 | +- chore: update dependencies (h8i9j0k) |
| 166 | + |
| 167 | +## Installation |
| 168 | +... |
| 169 | +``` |
| 170 | + |
| 171 | +## Manual Version Override (Advanced) |
| 172 | + |
| 173 | +If you need to set a specific version manually: |
| 174 | + |
| 175 | +1. **Update `src/dram.app.src`:** |
| 176 | + ```erlang |
| 177 | + {vsn, "2.0.0"} |
| 178 | + ``` |
| 179 | + |
| 180 | +2. **Commit with `[skip ci]` to prevent duplicate releases:** |
| 181 | + ```bash |
| 182 | + git commit -m "chore: bump version to 2.0.0 [skip ci]" |
| 183 | + ``` |
| 184 | + |
| 185 | +3. **Merge to main** - workflow will detect the existing version and create the release |
| 186 | + |
| 187 | +## Skipping Releases |
| 188 | + |
| 189 | +The release workflow automatically skips if: |
| 190 | +- Only documentation files changed (`.md`, `docs/`) |
| 191 | +- Changes only affect workflow files (`.github/`) |
| 192 | +- Commit message contains `[skip ci]` or `[skip release]` |
| 193 | + |
| 194 | +## Example Workflow |
| 195 | + |
| 196 | +```bash |
| 197 | +# 1. Create feature branch |
| 198 | +git checkout -b feat/add-scheduling |
| 199 | + |
| 200 | +# 2. Make changes and commit |
| 201 | +git add . |
| 202 | +git commit -m "feat: add job scheduling support" |
| 203 | + |
| 204 | +# 3. Push and create PR |
| 205 | +git push origin feat/add-scheduling |
| 206 | + |
| 207 | +# 4. CI runs tests automatically |
| 208 | + |
| 209 | +# 5. Merge PR to main |
| 210 | +# → Release workflow runs |
| 211 | +# → Version bumps from 0.1.0 to 0.2.0 (minor bump for "feat:") |
| 212 | +# → Tag v0.2.0 created |
| 213 | +# → GitHub release published |
| 214 | +# → src/dram.app.src updated automatically |
| 215 | +``` |
| 216 | + |
| 217 | +## Running CI Checks Locally |
| 218 | + |
| 219 | +Before pushing your PR, run the same checks that CI runs: |
| 220 | + |
| 221 | +```bash |
| 222 | +# Run all quality checks |
| 223 | +make check |
| 224 | + |
| 225 | +# Or run individually |
| 226 | +make format # Check code formatting |
| 227 | +make xref # Cross-reference analysis |
| 228 | +make dialyzer # Type checking |
| 229 | +make test # Run tests |
| 230 | +``` |
| 231 | + |
| 232 | +**Pre-commit checklist:** |
| 233 | +```bash |
| 234 | +# 1. Format your code |
| 235 | +rebar3 fmt |
| 236 | + |
| 237 | +# 2. Run all checks |
| 238 | +make check |
| 239 | + |
| 240 | +# 3. Run tests |
| 241 | +make test |
| 242 | + |
| 243 | +# 4. Commit and push |
| 244 | +git add . |
| 245 | +git commit -m "feat: my awesome feature" |
| 246 | +git push |
| 247 | +``` |
| 248 | + |
| 249 | +## Requirements |
| 250 | + |
| 251 | +The workflows require: |
| 252 | +- **Repository permissions:** `contents: write` for creating releases |
| 253 | +- **No secrets needed:** Uses `GITHUB_TOKEN` (automatic) |
| 254 | + |
| 255 | +## Troubleshooting |
| 256 | + |
| 257 | +### Release not created after merge |
| 258 | + |
| 259 | +**Check:** |
| 260 | +1. Did you use conventional commit format? (`feat:`, `fix:`, etc.) |
| 261 | +2. Does your commit contain `[skip ci]`? |
| 262 | +3. Did you only change documentation? |
| 263 | +4. Check the Actions tab for workflow run details |
| 264 | + |
| 265 | +### Wrong version bump |
| 266 | + |
| 267 | +**Fix:** |
| 268 | +- Use correct commit prefix: |
| 269 | + - `feat:` for features (minor bump) |
| 270 | + - `fix:` for fixes (patch bump) |
| 271 | + - `feat!:` for breaking changes (major bump) |
| 272 | + |
| 273 | +### Multiple commits in PR |
| 274 | + |
| 275 | +The workflow examines the **merge commit message**, so: |
| 276 | +- Squash commits before merging, OR |
| 277 | +- Use a descriptive merge commit message with proper prefix |
| 278 | + |
| 279 | +### Tests failing on PR |
| 280 | + |
| 281 | +**Check:** |
| 282 | +1. Do tests pass locally? (`make test`) |
| 283 | +2. Is PostgreSQL service starting correctly in CI? |
| 284 | +3. Check Actions tab for detailed error logs |
0 commit comments