| 1 | Contributing to go-yaml |
| 2 | ======================= |
| 3 | |
| 4 | Thank you for your interest in contributing to go-yaml! |
| 5 | |
| 6 | This document provides guidelines and instructions for contributing to this |
| 7 | project. |
| 8 | |
| 9 | |
| 10 | ## Code of Conduct |
| 11 | |
| 12 | By participating in this project, you agree to follow our Code of Conduct. |
| 13 | |
| 14 | We expect all contributors to: |
| 15 | |
| 16 | - Be respectful and inclusive |
| 17 | - Use welcoming and inclusive language |
| 18 | - Be collaborative and constructive |
| 19 | - Focus on what is best for both the Go and YAML communities |
| 20 | |
| 21 | |
| 22 | ## How to Contribute |
| 23 | |
| 24 | |
| 25 | ### Reporting Issues |
| 26 | |
| 27 | Before submitting an issue, please: |
| 28 | |
| 29 | - Check if the issue already exists in our issue tracker |
| 30 | - Use a clear and descriptive title |
| 31 | - Provide detailed steps to reproduce the issue |
| 32 | - Include relevant code samples and error messages |
| 33 | - Specify your Go version and operating system |
| 34 | - Use the `go-yaml` CLI tool described below |
| 35 | |
| 36 | |
| 37 | ### Using the `go-yaml` CLI Tool |
| 38 | |
| 39 | This tool can be used to inspect both the internal stages and final results of |
| 40 | YAML processing with the go-yaml library. |
| 41 | It should be used when reporting most bugs. |
| 42 | |
| 43 | The `go-yaml` CLI tool uses the `go.yaml.in/yaml/v4` library to decode and |
| 44 | encode YAML. |
| 45 | Decoding YAML is a multi-stage process that involves tokens, events, and nodes. |
| 46 | The `go-yaml` CLI tool lets you see all of these intermediate stages of the |
| 47 | decoding process. |
| 48 | This is crucial for understanding what go-yaml is doing internally. |
| 49 | |
| 50 | The `go-yaml` CLI tool can be built with the `make go-yaml` command or installed |
| 51 | with the `go install go.yaml.in/yaml/v4/cmd/go-yaml@latest` command. |
| 52 | |
| 53 | You can learn about all of its options with the `go-yaml -h` command. |
| 54 | |
| 55 | Here is an example of using it on a small piece of YAML: |
| 56 | |
| 57 | ```bash |
| 58 | ./go-yaml -t <<< ' |
| 59 | foo: &a1 bar |
| 60 | *a1: baz |
| 61 | ``` |
| 62 | |
| 63 | |
| 64 | ### Coding Conventions |
| 65 | |
| 66 | - Follow standard Go coding conventions |
| 67 | - Use `make fmt` to format your code |
| 68 | - Write descriptive comments for non-obvious code |
| 69 | - Add tests for your work |
| 70 | - Keep line length to 80 characters |
| 71 | - Use meaningful variable and function names |
| 72 | - Start doc and comment sentences on a new line |
| 73 | - Test your changes with the `go-yaml` CLI tool when working on parsing logic |
| 74 | |
| 75 | |
| 76 | ### Commit Conventions |
| 77 | |
| 78 | - No merge commits |
| 79 | - Commit subject line should: |
| 80 | - Start with a capital letter |
| 81 | - Not end with a period |
| 82 | - Be no more than 50 characters |
| 83 | |
| 84 | |
| 85 | ### Pull Requests |
| 86 | |
| 87 | 1. Fork the repository |
| 88 | 1. Create a new branch for your changes |
| 89 | 1. Make your changes following our coding conventions |
| 90 | - If you are not sure about the coding conventions, please ask |
| 91 | - Look at the existing code for examples |
| 92 | 1. Write clear commit messages |
| 93 | 1. Update tests and documentation |
| 94 | 1. Submit a pull request |
| 95 | |
| 96 | |
| 97 | ### Testing |
| 98 | |
| 99 | - Ensure all tests pass with `make test` |
| 100 | - Add new tests for new functionality |
| 101 | - Update existing tests when modifying functionality |
| 102 | |
| 103 | |
| 104 | ## Development Process |
| 105 | |
| 106 | - This project makes use of a GNU makefile (`GNUmakefile`) for many dev tasks |
| 107 | - The makefile doesn't use your locally installed Go commands; it auto-installs |
| 108 | them, so that all results are deterministic |
| 109 | - Fork and clone the repository |
| 110 | - Make your changes |
| 111 | - Run tests, linters and formatters |
| 112 | - `make fmt` |
| 113 | - `make tidy` |
| 114 | - `make lint` |
| 115 | - `make test` |
| 116 | - You can use `make check` to run all of the above |
| 117 | - Submit a [Pull Request](https://github.com/yaml/go-yaml/pulls) |
| 118 | |
| 119 | |
| 120 | ### Using Your Own Go with the Makefile |
| 121 | |
| 122 | We ask that you always test with the makefile installed Go before committing, |
| 123 | since it is deterministic and uses the exact same flow as the go-yaml CI. |
| 124 | |
| 125 | We also realize that many Go devs need to run their locally installed Go |
| 126 | commands for their development environment, and might want to use them with |
| 127 | the go-yaml makefile. |
| 128 | |
| 129 | If you need to use your own Go utils with the makefile, set `GO_YAML_PATH` to |
| 130 | the directory(s) containing them (either by exporting it or passing it to |
| 131 | `make`). |
| 132 | |
| 133 | Something like this: |
| 134 | |
| 135 | ```bash |
| 136 | export GO_YAML_PATH=$(dirname "$(command -v go)") |
| 137 | make test |
| 138 | # or |
| 139 | make test GO_YAML_PATH=$(dirname "$(command -v go)") |
| 140 | ``` |
| 141 | |
| 142 | **Note:** `GO-VERSION` and `GO_YAML_PATH` are mutually exclusive. |
| 143 | When `GO_YAML_PATH` is set, the makefile uses your own Go environment and |
| 144 | ignores any `GO-VERSION` setting. |
| 145 | |
| 146 | |
| 147 | ### Using the Makefile Environment as a Shell |
| 148 | |
| 149 | Sometimes you might want to run your own shell commands using the same binaries |
| 150 | that the makefile installs. |
| 151 | |
| 152 | To get a subshell with this environment, run one of: |
| 153 | |
| 154 | ```bash |
| 155 | make shell |
| 156 | make bash |
| 157 | make zsh |
| 158 | make shell GO-VERSION=1.23.4 |
| 159 | ``` |
| 160 | |
| 161 | |
| 162 | |
| 163 | ## Makefile Targets |
| 164 | |
| 165 | The repository's makefile (`GNUmakefile`) provides a number of useful targets: |
| 166 | |
| 167 | - `make test` runs all tests including yaml-test-suite tests |
| 168 | - `make test-unit` runs just the unit tests |
| 169 | - `make test-internal` runs just the internal tests |
| 170 | - `make test-yts` runs just the yaml-test-suite tests |
| 171 | - `make test v=1 count=3` runs the tests with options |
| 172 | - `make test GO-VERSION=1.23.4` runs the tests with a specific Go version |
| 173 | - `make test GO_YAML_PATH=/path/to/go/bin` uses your own Go installation |
| 174 | - `make shell` opens a shell with the project's dependencies set up |
| 175 | - `make shell GO-VERSION=1.23.4` opens a shell with a specific Go version |
| 176 | - `make fmt` runs `golangci-lint fmt ./...` |
| 177 | - `make lint` runs `golangci-lint run` |
| 178 | - `make tidy` runs `go mod tidy` |
| 179 | - `make distclean` cleans the project completely |
| 180 | |
| 181 | |
| 182 | ## Getting Help |
| 183 | |
| 184 | If you need help, you can: |
| 185 | - Open an [issue](https://github.com/yaml/go-yaml/issues) with your question |
| 186 | - Start a [discussion](https://github.com/yaml/go-yaml/discussions) |
| 187 | - Read through our [documentation](https://pkg.go.dev/go.yaml.in/yaml/v4) |
| 188 | - Check the [migration guide](docs/v3-to-v4-migration.md) if upgrading from v3 |
| 189 | - Join our [Slack channel](https://cloud-native.slack.com/archives/C08PPAT8PS7) |
| 190 | |
| 191 | |
| 192 | ## We are a Work in Progress |
| 193 | |
| 194 | This project is very much a team effort. |
| 195 | We are just getting things rolling and trying to get the foundations in place. |
| 196 | There are lots of opinions and ideas about how to do things, even within the |
| 197 | core team. |
| 198 | |
| 199 | Once our process is more mature, we will likely change the rules here. |
| 200 | We'll make the new rules as a team. |
| 201 | For now, please stick to the rules as they are. |
| 202 | |
| 203 | This project is focused on serving the needs of both the Go and YAML |
| 204 | communities. |
| 205 | Sometimes those needs can be in conflict, but we'll try to find common ground. |
| 206 | |
| 207 | |
| 208 | ## Thank You |
| 209 | |
| 210 | Thank you for contributing to go-yaml! |