|
1 | | -# Contributing to vSphere Plugin |
| 1 | +# Contributing Guidelines |
2 | 2 |
|
3 | | -**First:** if you're unsure or afraid of _anything_, just ask or submit the |
4 | | -issue or pull request anyway. You won't be yelled at for giving your best |
5 | | -effort. The worst that can happen is that you'll be politely asked to change |
6 | | -something. We appreciate any sort of contributions, and don't want a wall of |
7 | | -rules to get in the way of that. |
| 3 | +Thank you for your interest in contributing to our project. Whether it's a bug |
| 4 | +report, new feature, correction, or additional documentation, we greatly value |
| 5 | +feedback and contributions from our community. |
8 | 6 |
|
9 | | -However, for those individuals who want a bit more guidance on the best way to |
10 | | -contribute to the project, read on. This document will cover what we're looking |
11 | | -for. By addressing all the points we're looking for, it raises the chances we |
12 | | -can quickly merge or address your contributions. |
| 7 | +Please read through this document before submitting any issues or pull requests |
| 8 | +to ensure we have all the necessary information to effectively respond to your |
| 9 | +bug report or contribution. |
13 | 10 |
|
14 | | -When contributing in any way to the Packer project (new issue, PR, etc), please |
15 | | -be aware that our team identifies with many gender pronouns. Please remember to |
16 | | -use nonbinary pronouns (they/them) and gender neutral language ("Hello folks") |
17 | | -when addressing our team. For more reading on our code of conduct, please see the |
18 | | -[HashiCorp community guidelines](https://www.hashicorp.com/community-guidelines). |
| 11 | +## Reporting Bugs and Suggesting Enhancements |
19 | 12 |
|
20 | | -## Issues |
| 13 | +We welcome you to use the [GitHub issues][gh-issues] to report bugs or suggest |
| 14 | +enhancements. |
21 | 15 |
|
22 | | -### Reporting an Issue |
| 16 | +When filing an issue, please check existing open, or recently closed, issues to |
| 17 | +make sure someone else hasn't already reported. |
23 | 18 |
|
24 | | -- Make sure you test against the latest released version. It is possible we |
25 | | - already fixed the bug you're experiencing. |
| 19 | +Please try to include as much information as you can using the issue form. |
| 20 | +Details like these are incredibly useful: |
26 | 21 |
|
27 | | -- Run packer with debug output with the environment variable `PACKER_LOG`. |
28 | | - For example: `PACKER_LOG=1 packer build template.pkr.hcl`. Take the _entire_ |
29 | | - output and create a [gist](https://gist.github.com) for linking to in your |
30 | | - issue. Packer should strip sensitive keys from the output, but take a look |
31 | | - through just in case. |
| 22 | +- A reproducible test case or series of steps. |
| 23 | +- Any modifications you've made relevant to the bug. |
| 24 | +- Anything unusual about your environment or deployment. |
32 | 25 |
|
33 | | -- Provide a reproducible test case. If a contributor can't reproduce an issue, |
34 | | - then it dramatically lowers the chances it'll get fixed. And in some cases, |
35 | | - the issue will eventually be closed. |
| 26 | +## Contributing via Pull Requests |
36 | 27 |
|
37 | | -- Respond promptly to any questions made by the Packer team to your issue. Stale |
38 | | - issues will be closed. |
| 28 | +Contributions using pull requests are appreciated. |
39 | 29 |
|
40 | | -### Issue Lifecycle |
| 30 | +**Before** sending us a pull request, please ensure that: |
41 | 31 |
|
42 | | -1. The issue is reported. |
| 32 | +1. You [open a discussion][gh-discussions] to discuss any significant work with |
| 33 | + the maintainer(s). |
| 34 | +2. You [open an issue][gh-issues] and link your pull request to the issue for |
| 35 | + context. |
| 36 | +3. You are working against the latest source on the `main` branch. |
| 37 | +4. You check existing open, and recently merged, pull requests to make sure |
| 38 | + someone else hasn't already addressed the problem. |
43 | 39 |
|
44 | | -2. The issue is verified and categorized by a Packer collaborator. |
45 | | - Categorization is done via tags. For example, bugs are marked as "bugs" and |
46 | | - simple fixes are marked as "good first issue". |
| 40 | +To open a pull request, please: |
47 | 41 |
|
48 | | -3. Unless it is critical, the issue is left for a period of time (sometimes many |
49 | | - weeks), giving outside contributors a chance to address the issue. |
| 42 | +1. Fork the repository. |
| 43 | +2. Modify the source; please focus on the **specific** change you are |
| 44 | + contributing. |
| 45 | +3. Ensure local tests pass. |
| 46 | +4. Update the documentation, if required. |
| 47 | +5. Sign-off and commit to your fork |
| 48 | + [using clear commit messages][git-commit]. Please use |
| 49 | + [Conventional Commits][conventional-commits]. |
| 50 | +6. Open a pull request, answering any default questions in the pull request. |
| 51 | +7. Pay attention to any automated failures reported in the pull request, and |
| 52 | + stay involved in the conversation. |
50 | 53 |
|
51 | | -4. The issue is addressed in a pull request or commit. The issue will be |
52 | | - referenced in the commit message so that the code that fixes it is clearly |
53 | | - linked. |
| 54 | +GitHub provides additional documentation on [forking a repository][gh-forks] and |
| 55 | +[creating a pull request][gh-pull-requests]. |
54 | 56 |
|
55 | | -5. Sometimes, if you have a specialized environment or use case, the maintainers |
56 | | - may ask for your help testing the patch. |
| 57 | +### Contributor Flow |
57 | 58 |
|
58 | | -6. The issue is closed. |
| 59 | +This is an outline of the contributor workflow: |
59 | 60 |
|
| 61 | +- Create a topic branch from where you want to base your work. |
| 62 | +- Make commits of logical units. |
| 63 | +- Make sure your commit messages are |
| 64 | + [in the proper format][conventional-commits]. |
| 65 | +- Push your changes to the topic branch in your fork. |
| 66 | +- Submit a pull request. If the pull request is a work in progress, please open |
| 67 | + as draft. |
60 | 68 |
|
| 69 | +Example: |
61 | 70 |
|
62 | | -## Setting up Go |
| 71 | +```shell |
| 72 | +git remote add upstream https://github.com/<org-name>/<repo-name>.git |
| 73 | +git checkout -b feat/add-x main |
| 74 | +git commit --signoff --message "feat: add support for x |
| 75 | + Added support for x. |
63 | 76 |
|
64 | | -If you have never worked with Go before, you will have to install its |
65 | | -runtime in order to build packer with the vSphere plugin. |
66 | | - |
67 | | -1. This project always releases from the latest version of golang. |
68 | | -[Install go](https://golang.org/doc/install#install) To properly build from |
69 | | -source, you need to have golang >= 1.21 |
70 | | - |
71 | | -## Setting up vSphere plugin for dev |
72 | | - |
73 | | -With Go installed, you can already `go get` the vSphere plugin and `make dev` in |
74 | | -order to compile and test it. These instructions target |
75 | | -POSIX-like environments (macOS, Linux, Cygwin, etc.) so you may need to |
76 | | -adjust them for Windows or other shells. |
77 | | - |
78 | | -1. Download the vSphere plugin source (and its dependencies) by running |
79 | | - `go get github.com/hashicorp/packer-plugin-vsphere`. This will download the source to |
80 | | - `$GOPATH/src/github.com/hashicorp/packer-plugin-vsphere`. |
81 | | - |
82 | | -2. When working on the vSphere plugin, first `cd $GOPATH/src/github.com/hashicorp/packer-plugin-vsphere` |
83 | | - so you can run `make dev` and easily access other files. `make dev` will build the packer-plugin-vsphere binary and install it under `$HOME/.packer.d/plugins/`. |
84 | | - |
85 | | -3. Make your changes to the vSphere plugin source. You can run `make dev` to build and install locally, and `make test` to run unit tests. |
86 | | - Any compilation errors will be shown when the binaries are rebuilding. If you don't have `make` you can simply run `go build -o packer-plugin-vsphere` from the project root, and `mv packer-plugin-vsphere ~/.packer.d/plugins/packer-plugin-vsphere` to install the plugin. |
87 | | - |
88 | | -4. After building the vSphere plugin successfully, use the latest version of Packer to build a machine and verify your changes. In the [example folder](https://github.com/hashicorp/packer-plugin-vsphere/blob/main/example) we provide a basic template. Comment out the `packer {}` block to force Packer use the development binary installed in the previous step. |
89 | | - |
90 | | -5. If everything works well and the tests pass, run `go fmt ./...` on your code before |
91 | | - submitting a pull-request. |
92 | | - |
93 | | - |
94 | | -### Opening a Pull Request |
95 | | - |
96 | | -Thank you for contributing! When you are ready to open a pull-request, you will |
97 | | -need to [fork the vSphere plugin](https://github.com/hashicorp/packer-plugin-vsphere#fork-destination-box), push your |
98 | | -changes to your fork, and then open a pull-request. |
99 | | - |
100 | | -For example, my github username is `myuser`, so I would do the following: |
| 77 | + Signed-off-by: Jane Doe <jdoe@example.com> |
101 | 78 |
|
| 79 | + Ref: #123" |
| 80 | +git push origin feat/add-x |
102 | 81 | ``` |
103 | | -git checkout -b f-my-feature |
104 | | -# Develop a patch. |
105 | | -git push https://github.com/myuser/packer-plugin-vsphere f-my-feature |
106 | | -``` |
107 | | - |
108 | | -From there, open your fork in your browser to open a new pull-request. |
109 | | - |
110 | | -### Pull Request Lifecycle |
111 | | - |
112 | | -1. You are welcome to submit your pull request for commentary or review before |
113 | | - it is fully completed. Please prefix the title of your pull request with |
114 | | - "[WIP]" to indicate this. It's also a good idea to include specific questions |
115 | | - or items you'd like feedback on. |
116 | | - |
117 | | -2. Once you believe your pull request is ready to be merged, you can remove any |
118 | | - "[WIP]" prefix from the title and a core team member will review. |
119 | | - |
120 | | -3. One of vSphere plugin's core team members will look over your contribution and |
121 | | - either merge, or provide comments letting you know if there is anything left |
122 | | - to do. We do our best to provide feedback in a timely manner, but it may take |
123 | | - some time for us to respond. We may also have questions that we need answered |
124 | | - about the code, either because something doesn't make sense to us or because |
125 | | - we want to understand your thought process. |
126 | | - |
127 | | -4. If we have requested changes, you can either make those changes or, if you |
128 | | - disagree with the suggested changes, we can have a conversation about our |
129 | | - reasoning and agree on a path forward. This may be a multi-step process. Our |
130 | | - view is that pull requests are a chance to collaborate, and we welcome |
131 | | - conversations about how to do things better. It is the contributor's |
132 | | - responsibility to address any changes requested. While reviewers are happy to |
133 | | - give guidance, it is unsustainable for us to perform the coding work necessary |
134 | | - to get a PR into a mergeable state. |
135 | | - |
136 | | -5. Once all outstanding comments and checklist items have been addressed, your |
137 | | - contribution will be merged! Merged PRs will be included in the next |
138 | | - Packer release. The core team takes care of updating the |
139 | | - [CHANGELOG.md](../CHANGELOG.md) as they merge. |
140 | | - |
141 | | -6. In rare cases, we might decide that a PR should be closed without merging. |
142 | | - We'll make sure to provide clear reasoning when this happens. |
143 | | - |
144 | | -### Tips for Working on Packer |
145 | | - |
146 | | -#### Getting Your Pull Requests Merged Faster |
147 | 82 |
|
148 | | -It is much easier to review pull requests that are: |
| 83 | +### Formatting Commit Messages |
149 | 84 |
|
150 | | -1. Well-documented: Try to explain in the pull request comments what your |
151 | | - change does, why you have made the change, and provide instructions for how |
152 | | - to produce the new behavior introduced in the pull request. If you can, |
153 | | - provide screen captures or terminal output to show what the changes look |
154 | | - like. This helps the reviewers understand and test the change. |
| 85 | +We follow the conventions on [How to Write a Git Commit Message][git-commit] and |
| 86 | +[Conventional Commits][conventional-commits]. |
155 | 87 |
|
156 | | -2. Small: Try to only make one change per pull request. If you found two bugs |
157 | | - and want to fix them both, that's _awesome_, but it's still best to submit |
158 | | - the fixes as separate pull requests. This makes it much easier for reviewers |
159 | | - to keep in their heads all of the implications of individual code changes, |
160 | | - and that means the PR takes less effort and energy to merge. In general, the |
161 | | - smaller the pull request, the sooner reviewers will be able to make time to |
162 | | - review it. |
| 88 | +Be sure to include any related GitHub issue references in the commit message. |
163 | 89 |
|
164 | | -3. Passing Tests: Based on how much time we have, we may not review pull |
165 | | - requests which aren't passing our tests. (Look below for advice on how to |
166 | | - run unit tests). If you need help figuring out why tests are failing, please |
167 | | - feel free to ask, but while we're happy to give guidance it is generally |
168 | | - your responsibility to make sure that tests are passing. If your pull request |
169 | | - changes an interface or invalidates an assumption that causes a bunch of |
170 | | - tests to fail, then you need to fix those tests before we can merge your PR. |
| 90 | +Example: |
171 | 91 |
|
172 | | -If we request changes, try to make those changes in a timely manner. Otherwise, |
173 | | -PRs can go stale and be a lot more work for all of us to merge in the future. |
| 92 | +```markdown |
| 93 | +feat: add support for x |
174 | 94 |
|
175 | | -Even with everyone making their best effort to be responsive, it can be |
176 | | -time-consuming to get a PR merged. It can be frustrating to deal with |
177 | | -the back-and-forth as we make sure that we understand the changes fully. Please |
178 | | -bear with us, and please know that we appreciate the time and energy you put |
179 | | -into the project. |
| 95 | +Added support for x. |
180 | 96 |
|
181 | | -#### Working on forks |
| 97 | +Signed-off-by: Jane Doe <jdoe@example.com> |
182 | 98 |
|
183 | | -The easiest way to work on a fork is to set it as a remote of the the vSphere plugin |
184 | | -project. After following the steps in "Setting up Go to work on the vSphere plugin": |
185 | | - |
186 | | -1. Navigate to the code: |
187 | | - |
188 | | - `cd $GOPATH/src/github.com/hashicorp/packer-plugin-vsphere` |
189 | | - |
190 | | -2. Add the remote by running: |
191 | | - |
192 | | - `git remote add <name of remote> <github url of fork>` |
193 | | - |
194 | | - For example: |
195 | | - |
196 | | - `git remote add myuser https://github.com/myuser/packer-plugin-vsphere.git` |
197 | | - |
198 | | -3. Checkout a feature branch: |
199 | | - |
200 | | - `git checkout -b new-feature` |
201 | | - |
202 | | -4. Make changes. |
203 | | -5. (Optional) Push your changes to the fork: |
204 | | - |
205 | | - `git push -u <name of remote> new-feature` |
206 | | - |
207 | | -This way you can push to your fork to create a PR, but the code on disk still |
208 | | -lives in the spot where the go cli tools are expecting to find it. |
209 | | - |
210 | | -#### Go modules & go vendor |
211 | | - |
212 | | -If you are submitting a change that requires new or updated dependencies, |
213 | | -please include them in `go.mod`/`go.sum`. This |
214 | | -helps everything get tested properly in CI. |
215 | | - |
216 | | -Note that you will need to use [go |
217 | | -mod](https://github.com/golang/go/wiki/Modules) to do this. This step is |
218 | | -recommended but not required. |
219 | | - |
220 | | -Use `go get <project>` to add dependencies to the project. See [go mod quick |
221 | | -start](https://github.com/golang/go/wiki/Modules#quick-start) for examples. |
222 | | - |
223 | | -Please only apply the minimal vendor changes to get your PR to work. The vSphere plugin |
224 | | -does not attempt to track the latest version for each dependency. |
225 | | - |
226 | | -#### HCL2 Spec code generation |
227 | | - |
228 | | -Packer relies on `go generate` to generate HCL2's bridging code. First you should install the command with `go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@latest`, then you generate with |
229 | | -`go generate ./...`. This should update/create `*.hcl2spec.go` file(s). |
| 99 | +Ref: #123 |
| 100 | +``` |
230 | 101 |
|
231 | | -#### Running Unit Tests |
| 102 | +### Staying In Sync With Upstream |
232 | 103 |
|
233 | | -To run unit tests, simply call |
| 104 | +When your branch gets out of sync with the `upstream/main` branch, use the |
| 105 | +following to update: |
234 | 106 |
|
| 107 | +```shell |
| 108 | +git checkout feat/add-x |
| 109 | +git fetch --all |
| 110 | +git pull --rebase upstream main |
| 111 | +git push --force-with-lease origin feat/add-x |
235 | 112 | ``` |
236 | | -make test |
237 | | -``` |
238 | | - |
239 | | -from the plugin's project root. |
240 | 113 |
|
241 | | -#### Running Builder Acceptance Tests |
| 114 | +### Updating Pull Requests |
242 | 115 |
|
243 | | -If the vSphere Plugin has [acceptance tests](https://en.wikipedia.org/wiki/Acceptance_testing), these probably have some requirements such as environment variables to be set for API tokens and keys. Each test should error and tell you what are missing, so those are not documented here. |
| 116 | +If your pull request fails to pass or needs changes based on code review, you'll |
| 117 | +most likely want to squash these changes into existing commits. |
244 | 118 |
|
245 | | -If you're working on a feature and want to verify it is functioning (and also hasn't broken anything else), we recommend creating or running the acceptance tests. |
| 119 | +If your pull request contains a single commit or your changes are related to the |
| 120 | +most recent commit, you can simply amend the commit. |
246 | 121 |
|
247 | | -**Warning:** The acceptance tests create/destroy/modify _real resources_, which |
248 | | -may incur costs for real money. In the presence of a bug, it is possible that |
249 | | -resources may be left behind, which can cost money even though you were not |
250 | | -using them. We recommend running tests in an account used only for that purpose |
251 | | -so it is easy to see if there are any dangling resources, and so production |
252 | | -resources are not accidentally destroyed or overwritten during testing. |
| 122 | +```shell |
| 123 | +git add . |
| 124 | +git commit --amend |
| 125 | +git push --force-with-lease origin feat/add-x |
| 126 | +``` |
253 | 127 |
|
254 | | -To run the acceptance tests, invoke `make testacc`: |
| 128 | +If you need to squash changes into an earlier commit, you can use: |
255 | 129 |
|
256 | | -``` |
257 | | -make testacc |
258 | | -... |
| 130 | +```shell |
| 131 | +git add . |
| 132 | +git commit --fixup <commit> |
| 133 | +git rebase --interactive --autosquash upsstream/main |
| 134 | +git push --force-with-lease origin feat/add-x |
259 | 135 | ``` |
260 | 136 |
|
261 | | -The `TEST` variable lets you narrow the scope of the acceptance tests to a |
262 | | -specific package / folder. |
| 137 | +Be sure to add a comment to the pull request indicating your new changes are |
| 138 | +ready to review, as GitHub does not generate a notification when you `git push`. |
263 | 139 |
|
264 | | -#### Debugging Plugins |
| 140 | +## Finding Contributions to Work On |
265 | 141 |
|
266 | | -Each packer plugin runs in a separate process and communicates via RPC over a |
267 | | -socket therefore using a debugger will not work (be complicated at least). |
| 142 | +Looking at the existing issues is a great way to find something to contribute |
| 143 | +on. If you have an idea you'd like to discuss, |
| 144 | +[open a discussion][gh-discussions]. |
268 | 145 |
|
269 | | -The Packer and plugins code provides more detailed logs when ran with PACKER_LOG |
270 | | -turned on. If that doesn't work, adding some extra debug print outs when you have |
271 | | -homed in on the problem is usually enough. |
| 146 | +[conventional-commits]: https://conventionalcommits.org |
| 147 | +[gh-discussions]: https://github.com/vmware/packer-plugin-vsphere/discussions |
| 148 | +[gh-forks]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo |
| 149 | +[gh-issues]: https://github.com/vmware/packer-plugin-vsphere/issues |
| 150 | +[gh-pull-requests]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request |
| 151 | +[git-commit]: https://cbea.ms/git-commit |
0 commit comments