|
1 | | -# Contributing to azldev-preview |
| 1 | +# Contribution Guidelines |
2 | 2 |
|
3 | | -Thank you for your interest in contributing to the azldev-preview project! This document provides guidelines and standards that all contributors should follow. |
| 3 | +## Contributing License Agreement |
4 | 4 |
|
5 | | -## Code of Conduct |
| 5 | +This project welcomes contributions and suggestions. Most contributions require you to agree to a |
| 6 | +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us |
| 7 | +the rights to use your contribution. For details, visit [Contributor License Agreements](https://cla.opensource.microsoft.com). |
6 | 8 |
|
7 | | -This project follows Microsoft's Open Source Code of Conduct, see [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details. |
| 9 | +When you submit a pull request, a CLA bot will automatically determine whether you need to provide |
| 10 | +a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions |
| 11 | +provided by the bot. You will only need to do this once across all repos using our CLA. |
8 | 12 |
|
9 | | -## License |
| 13 | +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). |
| 14 | +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or |
| 15 | +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
10 | 16 |
|
11 | | -By contributing to this project, you agree that your contributions will be licensed under the same license as the project (MIT License). |
| 17 | +## Security |
12 | 18 |
|
13 | | -### Contribution License Agreement (CLA) |
| 19 | +Please review our project's [Security Guidelines](./SECURITY.md). |
14 | 20 |
|
15 | | -This project welcomes contributions from the community. Most contributions require you to sign a Contribution License Agreement (CLA) to clarify the terms under which contributions are made (you have the right to, and do, grant us a license to use your contributions). For more details, visit |
16 | | -[Microsoft's CLA page](https://cla.microsoft.com/). |
| 21 | +## Development |
17 | 22 |
|
18 | | -When you submit a pull request, if you have not already done so, you will be prompted to sign the CLA. |
19 | | - |
20 | | -## Getting Started |
21 | | - |
22 | | -### Prerequisites |
23 | | - |
24 | | -- **Go 1.25+** - Required for building and running the application |
25 | | -- **Git** - For version control and submitting changes |
26 | | -- **Mage** - Our build automation tool |
27 | | - |
28 | | - ```bash |
29 | | - # Mage is not technically required, the build tools may also be invoked |
30 | | - # directly via `go run magefile.go` or `./magefile.go` |
31 | | - go install github.com/magefile/mage@latest |
32 | | - ``` |
33 | | - |
34 | | -### Initial Setup |
35 | | - |
36 | | -1. Fork the repository (strongly recommended for all contributors) |
37 | | -2. Clone your fork locally |
38 | | -3. Install dependencies: |
39 | | - |
40 | | - ```bash |
41 | | - dnf install -y golang |
42 | | - ``` |
43 | | - |
44 | | -4. Verify the build works: |
45 | | - |
46 | | - ```bash |
47 | | - mage build |
48 | | - ``` |
49 | | - |
50 | | -5. Install the built tools to your `$GOPATH/bin` directory: |
51 | | - |
52 | | - ```bash |
53 | | - mage install |
54 | | - ``` |
55 | | - |
56 | | - After running `mage install`, the tools will be available in your `$GOPATH/bin` directory. |
57 | | - Not all systems will have this directory in their `$PATH` by default, so you may need to add it. |
58 | | - |
59 | | -#### Azure Linux 3.0 as a development host |
60 | | - |
61 | | -```bash |
62 | | -# These instructions work for AzureLinux (https://github.com/microsoft/azurelinux) |
63 | | -# While the tools should build and run on any system with golang installed, some of the runtime dependencies |
64 | | -# may not be available on all systems (e.g., `mock`). |
65 | | -tdnf install -y golang ca-certificates glibc-devel |
66 | | - |
67 | | -git clone <URL> |
68 | | -cd <REPO> |
69 | | - |
70 | | -# You may want to permanently add $GOPATH/bin to your $PATH via |
71 | | -# echo 'export GOPATH=$(go env GOPATH)' >> $HOME/.bashrc |
72 | | -# echo 'export PATH=$PATH:${GOPATH}/bin' >> $HOME/.bashrc |
73 | | -export GOPATH=$(go env GOPATH) |
74 | | -export PATH=$PATH:${GOPATH}/bin |
75 | | -go install github.com/magefile/mage@latest |
76 | | -mage build |
77 | | -mage install |
78 | | -``` |
79 | | - |
80 | | -## Build Reference |
81 | | - |
82 | | -All code in this repo is written in `golang`. The `golang` package is required to build and run the tools. |
83 | | - |
84 | | -The build system uses mage, which can be installed with `go install github.com/magefile/mage@latest`. Alternatively, a zero-install approach is available through `go run magefile.go` or `./magefile.go`, which automatically downloads the required dependencies without manual installation. All additional build tools are managed automatically by go, and no manual tool installation is required. |
85 | | - |
86 | | -All other tooling dependencies are handled by `go tool`, which will automatically get the required tools when using `mage`. See [the tools section](./tools/README.md) for more information. |
87 | | - |
88 | | -This repo contains configs for the `golangci-lint` linter. It is installed as part of the [VSCode go extension](https://marketplace.visualstudio.com/items?itemName=golang.go). It's also optionally available as a [binary release](https://golangci-lint.run/welcome/install/#local-installation). |
89 | | - |
90 | | -### Mage Commands |
91 | | - |
92 | | -| Command | Description | When to Use | |
93 | | -|---------|-------------|-------------| |
94 | | -| `mage -l` | List all available targets | To see all options | |
95 | | -| `mage all` | Full build, test, and check pipeline | Before submitting PR | |
96 | | -| `mage build` | Build Go binaries | After code changes | |
97 | | -| `mage install` | Build Go binaries and install | Outer-loop testing | |
98 | | -| `mage unit` | Run unit tests | After writing tests | |
99 | | -| `mage scenario` | Run scenario tests (SLOW) | For major changes | |
100 | | -| `mage scenarioUpdate` | Update test snapshots | When test expectations change | |
101 | | -| `mage check all` | Run all quality checks | Before committing | |
102 | | -| `mage fix all` | Auto-fix code issues | When linting fails | |
103 | | -| `mage generate` | Run code generation | Automatic with build/test | |
104 | | - |
105 | | -**Note**: Dependencies run automatically in correct order |
106 | | -(i.e. `mage build` and `mage unit` automatically run code generation as needed). |
107 | | - |
108 | | -### Code Generation |
109 | | - |
110 | | -The project uses automatic code generation including: |
111 | | - |
112 | | -- `go:generate` directives |
113 | | -- Stringer for enums |
114 | | -- Schema generation |
115 | | -- Mocks generated by `mockgen` |
116 | | - |
117 | | -You typically don't need to run `mage generate` manually as it's included in build dependencies. |
118 | | - |
119 | | -See [tools documentation](tools/README.md#invoking-the-tool-as-part-of-gogenerate) for more details on how to use tools with `go tool` in `go:generate` directives. |
120 | | - |
121 | | -## Ideal Development Workflow |
122 | | - |
123 | | -### Before Making Changes |
124 | | - |
125 | | -1. **Understand the codebase**: Review existing code patterns and architecture |
126 | | -2. **Run the full test suite**: Execute `mage all` to ensure clean state |
127 | | -3. **Create an issue**: For non-trivial changes, discuss the approach first |
128 | | - |
129 | | -### Making Changes |
130 | | - |
131 | | -1. **Create a feature branch**: Use descriptive names (e.g., `user/feature/add-config-validation`) |
132 | | -2. **Write tests first**: Consider adding tests for new functionality before implementing |
133 | | -3. **Follow coding standards**: See standards section below |
134 | | -4. **Make incremental commits**: Use clear, descriptive commit messages following conventional commit format. Conventional commit naming will be enforced by the CI pipeline for the final PR title. |
135 | | - |
136 | | -### Validating Changes |
137 | | - |
138 | | -Before submitting, ensure your changes pass all checks: |
139 | | - |
140 | | -```bash |
141 | | -mage all # Comprehensive validation (will also invoke scenario tests, which will be slow) |
142 | | -``` |
143 | | - |
144 | | -For faster iteration during development: |
145 | | - |
146 | | -```bash |
147 | | -mage build # Rebuild the tool |
148 | | -mage unit # Fast unit tests |
149 | | -mage check all # Code quality checks |
150 | | -mage fix all # Auto-fix issues |
151 | | -``` |
152 | | - |
153 | | -For scenario tests, use: |
154 | | - |
155 | | -```bash |
156 | | -mage scenario # Run all scenario tests (may take time) |
157 | | -``` |
158 | | - |
159 | | -To see all available Mage targets, run: |
160 | | - |
161 | | -```bash |
162 | | -mage -l |
163 | | -``` |
164 | | - |
165 | | -## Coding Standards |
166 | | - |
167 | | -### Go Code Style |
168 | | - |
169 | | -- **Follow Go conventions**: Use `mage fix lint` for formatting (fallback: `gofmt`), and standard Go idioms |
170 | | -- **Naming**: Use clear, descriptive names for variables, functions, and types |
171 | | -- **Error handling**: Always handle errors appropriately with context. Use the following pattern: |
172 | | - |
173 | | - ```go |
174 | | - // ErrOperationFailed is a global error for operation failures |
175 | | - var ErrOperationFailed = errors.New("operation failed") |
176 | | - |
177 | | - // someOperation returns an error |
178 | | - func someOperation() error { |
179 | | - return fmt.Errorf("failed to connect to service: %w", ErrOperationFailed) |
180 | | - } |
181 | | - |
182 | | - // Example usage in a function |
183 | | - func performOperation() error { |
184 | | - err := someOperation() |
185 | | - // Wrap the error with context |
186 | | - if err != nil { |
187 | | - return fmt.Errorf("performing operation: %w", err) |
188 | | - } |
189 | | - return nil |
190 | | - } |
191 | | - ``` |
192 | | - |
193 | | -- **Comments**: Document exported functions, types, and complex logic |
194 | | -- **Package organization**: Follow the existing package structure |
195 | | -- **String formatting**: Prefer `%#q` format specifier for strings |
196 | | - |
197 | | -### Code Quality Requirements |
198 | | - |
199 | | -- **Linting**: All code must pass `golangci-lint` checks (use `mage check lint` and `mage fix lint` to fix some issues automatically) |
200 | | - - Avoid using `//nolint` comments unless absolutely necessary. If you must use it, specify the linter (e.g., `//nolint:golint`). |
201 | | -- **Testing**: New functionality requires unit tests |
202 | | -- **Coverage**: Maintain reasonable test coverage for critical paths |
203 | | -- **Documentation**: Update relevant documentation for user-facing changes |
204 | | - |
205 | | -### File Organization |
206 | | - |
207 | | -- **Business logic**: Place in `internal/` packages |
208 | | -- **Command handlers**: Keep minimal logic in `cmd/` packages |
209 | | -- **Unit Tests**: Co-locate with source files using `_test.go` suffix |
210 | | -- **Scenario Tests**: Use `scenario/` for scenario tests |
211 | | -- **Configuration**: Use TOML format, provide defaults in `defaultconfigs/` |
212 | | - |
213 | | -### Command Structure |
214 | | - |
215 | | -- See [azldev command guidelines](docs/reference/command-guidelines.md) for details on command structure and naming conventions. |
216 | | - |
217 | | -### Logging Guidelines |
218 | | - |
219 | | -- Use structured logging with the `slog` package |
220 | | -- Include relevant context in log messages |
221 | | -- Use appropriate log levels (Debug, Info, Warn, Error) |
222 | | - |
223 | | -## Testing |
224 | | - |
225 | | -Testing can be run with `mage`, or directly using `go test`. The `mage` build system is preferred as it can also automatically run the scenario tests and update the test expectations. |
226 | | - |
227 | | -```bash |
228 | | -# Run the unit tests |
229 | | -mage unit |
230 | | - |
231 | | -# Run the coverage tests, producing an .html report |
232 | | -mage coverage |
233 | | - |
234 | | -# Run scenario tests |
235 | | -mage scenario |
236 | | -``` |
237 | | - |
238 | | -See the [testing documentation](docs/how-to/testing.md) for detailed guidelines on writing and running tests. |
239 | | - |
240 | | -## Pull Request Process |
241 | | - |
242 | | -### Before Submitting |
243 | | - |
244 | | -- [ ] `mage all` passes successfully |
245 | | -- [ ] Code follows the style guidelines |
246 | | -- [ ] Documentation is updated if needed |
247 | | -- [ ] All dynamically generated code is covered by `mage generate` |
248 | | -- [ ] Update [CHANGELOG.md](CHANGELOG.md) with your changes |
249 | | - |
250 | | -### PR Guidelines |
251 | | - |
252 | | -- **Title**: Use a clear, descriptive title following conventional commit format (e.g., `feat: add user authentication`, `fix: resolve memory leak in parser`, `docs: update installation guide`) |
253 | | -- **Description**: Explain what changes were made and why |
254 | | -- **Testing**: Describe how the changes were tested |
255 | | -- **Breaking changes**: Clearly document any breaking changes |
256 | | - |
257 | | -## Configuration Management |
258 | | - |
259 | | -### Adding New Configuration |
260 | | - |
261 | | -- Add schema definitions to appropriate config structs |
262 | | -- Provide sensible defaults in `defaultconfigs/` |
263 | | -- Update configuration documentation if user-facing |
264 | | -- Test configuration loading and validation |
265 | | - |
266 | | -### Configuration Best Practices |
267 | | - |
268 | | -- Use TOML format for configuration files |
269 | | -- Validate configuration early in application startup |
270 | | -- Provide clear error messages for invalid configurations |
271 | | -- Support environment variable overrides where appropriate |
272 | | - |
273 | | -## Troubleshooting |
274 | | - |
275 | | -### Common Issues |
276 | | - |
277 | | -- **Build failures**: Ensure Go version is 1.25+ and all dependencies are installed. Try running `mage build -v`. Ensure `GOPATH` is configured. |
278 | | -- **Test failures**: Run `mage generate` to ensure generated code is up to date |
279 | | -- **Lint errors**: Address specific linting issues or discuss exceptions with maintainers |
280 | | -- **Command not found**: Run `mage install`, ensure `GOPATH` is in your `$PATH`. |
281 | | - |
282 | | -## Questions and Support |
283 | | - |
284 | | -If you have any questions about contributing, please open an issue in the repository. |
285 | | - |
286 | | -Thank you for contributing to azldev-preview! |
| 23 | +Please consult our [Developer Guide](./docs/developer/) |
0 commit comments