|
| 1 | +# Commit Process and Pre-commit Checks |
| 2 | + |
| 3 | +This document outlines the commit process, including required pre-commit checks and conventions for the Torrust Testing Infrastructure project. |
| 4 | + |
| 5 | +## 📝 Conventional Commits |
| 6 | + |
| 7 | +We follow the [Conventional Commits](https://www.conventionalcommits.org/) specification for commit messages. |
| 8 | + |
| 9 | +### Commit Message Format |
| 10 | + |
| 11 | +```text |
| 12 | +<type>[optional scope]: <description> |
| 13 | +
|
| 14 | +[optional body] |
| 15 | +
|
| 16 | +[optional footer(s)] |
| 17 | +``` |
| 18 | + |
| 19 | +### Issue Number Convention |
| 20 | + |
| 21 | +When working on a branch with an issue number, include the issue number in your commit messages: |
| 22 | + |
| 23 | +- **Structure**: `{type}: [#{issue}] {description}` |
| 24 | +- **Examples**: |
| 25 | + |
| 26 | + ```text |
| 27 | + feat: [#42] add MySQL database support |
| 28 | + fix: [#15] resolve SSL certificate renewal issue |
| 29 | + docs: [#8] update deployment guide |
| 30 | + ci: [#23] add infrastructure validation tests |
| 31 | + ``` |
| 32 | + |
| 33 | +### Commit Types |
| 34 | + |
| 35 | +| Type | Description | Example | |
| 36 | +| ---------- | ------------------------------------- | ------------------------------------------------------ | |
| 37 | +| `feat` | New feature or enhancement | `feat: [#42] add LXD container provisioning` | |
| 38 | +| `fix` | Bug fix | `fix: [#15] resolve ansible inventory parsing error` | |
| 39 | +| `docs` | Documentation changes | `docs: [#8] update installation guide` | |
| 40 | +| `style` | Code style changes (formatting, etc.) | `style: [#31] apply rustfmt to all source files` | |
| 41 | +| `refactor` | Code refactoring | `refactor: [#45] simplify linting script structure` | |
| 42 | +| `test` | Adding or updating tests | `test: [#67] add e2e tests for multipass provisioning` | |
| 43 | +| `chore` | Maintenance tasks | `chore: [#89] update dependencies to latest versions` | |
| 44 | +| `ci` | CI/CD related changes | `ci: [#23] add workflow for testing provisioning` | |
| 45 | +| `perf` | Performance improvements | `perf: [#52] optimize container startup time` | |
| 46 | + |
| 47 | +### Commit Examples |
| 48 | + |
| 49 | +```bash |
| 50 | +# Feature addition with issue number |
| 51 | +git commit -m "feat: [#42] add support for Ubuntu 22.04 in cloud-init" |
| 52 | + |
| 53 | +# Bug fix with issue number |
| 54 | +git commit -m "fix: [#15] resolve ansible inventory parsing error" |
| 55 | + |
| 56 | +# Documentation update with issue number |
| 57 | +git commit -m "docs: [#8] add troubleshooting section to README" |
| 58 | + |
| 59 | +# CI/CD changes with issue number |
| 60 | +git commit -m "ci: [#23] add workflow for testing provisioning" |
| 61 | + |
| 62 | +# Bug fix with scope (optional format) |
| 63 | +git commit -m "fix(ansible): [#15] correct inventory file path resolution" |
| 64 | + |
| 65 | +# Breaking change with issue number (note the !) |
| 66 | +git commit -m "feat!: [#42] change default container provider from multipass to lxd" |
| 67 | + |
| 68 | +# Commit with body and footer including issue reference |
| 69 | +git commit -m "feat: [#23] add automated testing workflow |
| 70 | +
|
| 71 | +Add GitHub Actions workflow that tests: |
| 72 | +- LXD container provisioning |
| 73 | +- Multipass VM provisioning |
| 74 | +- Ansible playbook execution |
| 75 | +
|
| 76 | +Closes #23" |
| 77 | +``` |
| 78 | + |
| 79 | +## ✅ Pre-commit Checklist |
| 80 | + |
| 81 | +Before committing any changes, you **MUST** complete the following checks: |
| 82 | + |
| 83 | +### 1. Run All Linters |
| 84 | + |
| 85 | +```bash |
| 86 | +# Run all linters at once |
| 87 | +./scripts/linting/lint.sh all |
| 88 | + |
| 89 | +# Or run individually |
| 90 | +./scripts/linting/lint.sh md # Markdown |
| 91 | +./scripts/linting/lint.sh yaml # YAML |
| 92 | +./scripts/linting/lint.sh clippy # Rust code analysis |
| 93 | +./scripts/linting/lint.sh rustfmt # Rust formatting |
| 94 | +./scripts/linting/lint.sh shellcheck # Shell scripts |
| 95 | +``` |
| 96 | + |
| 97 | +**All linters must pass** before committing. Fix any reported issues. |
| 98 | + |
| 99 | +### 2. Run Tests |
| 100 | + |
| 101 | +```bash |
| 102 | +# Run Rust unit tests |
| 103 | +cargo test |
| 104 | + |
| 105 | +# Run E2E tests (if applicable to your changes) |
| 106 | +cargo run --bin e2e-tests wait-cloud-init |
| 107 | +``` |
| 108 | + |
| 109 | +## 📋 Commit Quality Guidelines |
| 110 | + |
| 111 | +### Good Commits |
| 112 | + |
| 113 | +✅ **Atomic**: Each commit represents one logical change |
| 114 | +✅ **Descriptive**: Clear, concise description of what changed |
| 115 | +✅ **Tested**: All tests pass |
| 116 | +✅ **Linted**: All linters pass |
| 117 | +✅ **Conventional**: Follows conventional commit format |
| 118 | + |
| 119 | +### Example of Good Commit History |
| 120 | + |
| 121 | +```text |
| 122 | +feat: add LXD container provisioning support |
| 123 | +fix: resolve ansible inventory template rendering |
| 124 | +docs: update contributing guidelines |
| 125 | +test: add unit tests for configuration parsing |
| 126 | +refactor: extract common logging utilities |
| 127 | +``` |
| 128 | + |
| 129 | +### Commits to Avoid |
| 130 | + |
| 131 | +❌ **Too large**: Multiple unrelated changes in one commit |
| 132 | +❌ **Vague**: Messages like "fix stuff" or "updates" |
| 133 | +❌ **Broken**: Commits that don't build or pass tests |
| 134 | +❌ **Non-conventional**: Not following the conventional commit format |
| 135 | + |
| 136 | +### Example of Poor Commit History |
| 137 | + |
| 138 | +```text |
| 139 | +fix stuff |
| 140 | +WIP |
| 141 | +updates |
| 142 | +more changes |
| 143 | +final fix |
| 144 | +actually final fix |
| 145 | +``` |
0 commit comments