1
0

contributing.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. .. _contributing:
  2. ============
  3. Contributing
  4. ============
  5. There is a great need for contributions to Salt and patches are welcome! The
  6. goal here is to make contributions clear, make sure there is a trail for where
  7. the code has come from, and most importantly, to give credit where credit is
  8. due!
  9. There are a number of ways to contribute to Salt development, including (but
  10. not limited to):
  11. * filing well-written bug reports
  12. * enhancing the documentation
  13. * providing workarounds, patches, and other code without tests
  14. * engaging in constructive discussion
  15. * helping out in `#salt on Freenode <#salt on freenode_>`_,
  16. the `Community Slack <SaltStack Community Slack_>`_,
  17. the `salt-users <salt-users_>`_ mailing list,
  18. a `SaltStack meetup <saltstack meetup_>`_,
  19. or `Server Fault <saltstack on serverfault_>`_.
  20. * telling others about problems you solved with Salt
  21. If this or other Salt documentation is unclear, please review :ref:`Writing
  22. Salt Documentation <salt-docs>`. PRs are welcome!
  23. Quickstart
  24. ----------
  25. If you just want to get started before reading the rest of this guide, you can
  26. get the process started by running the following:
  27. .. code-block:: bash
  28. python3 -m pip install --user pre-commit
  29. git clone --origin upstream https://github.com/saltstack/salt.git
  30. cd salt
  31. pre-commit install
  32. While those commands are running, finish reading the rest of this guide.
  33. Pre-commit
  34. ----------
  35. To reduce friction during the development process, SaltStack uses `pre-commit
  36. <pre-commit_>`_. This tool adds pre-commit hooks to git to automate several
  37. processes that used to be manual. Rather than having to remember to run several
  38. different tools before you commit, you only have to run ``git commit``, and you
  39. will be notified about style and lint issues before you ever open a PR.
  40. Salt Coding Style
  41. -----------------
  42. After the 3000 release, SaltStack is `joining the ranks <SEP 15_>`_ of projects
  43. in adopting the `Black code formatter <Black_>`_ in order to ease the adoption
  44. of a unified code formatting style.
  45. Where Black is silent, SaltStack has its own coding style guide that informs
  46. contributors on various style points. Please review the :ref:`Salt Coding Style
  47. <coding-style>` documentation for information about Salt's particular coding
  48. patterns.
  49. Within the :ref:`Salt Coding Style <coding-style>` documentation, there is a
  50. section about running Salt's ``.testing.pylintrc`` file. SaltStack recommends
  51. running the ``.testing.pylintrc`` file on any files you are changing with your
  52. code contribution before submitting a pull request to Salt's repository.
  53. If you've installed ``pre-commit``, this will automatically happen before each
  54. commit. Otherwise, see the :ref:`Linting<pylint-instructions>` documentation
  55. for more information.
  56. Copyright Headers
  57. -----------------
  58. Copyright headers are not needed for files in the Salt project. Files that have
  59. existing copyright headers should be considered legacy and not an example to
  60. follow.
  61. .. _github-pull-request:
  62. Sending a GitHub pull request
  63. -----------------------------
  64. Sending pull requests on GitHub is the preferred method for receiving
  65. contributions. The workflow advice below mirrors `GitHub's own guide <GitHub
  66. Fork a Repo Guide_>`_ and is well worth reading.
  67. #. `Fork saltstack/salt`_ on GitHub.
  68. #. Make a local clone of your fork. (Skip this step if you followed
  69. the Quickstart)
  70. .. code-block:: bash
  71. git clone git@github.com:my-account/salt.git
  72. cd salt
  73. #. Add `saltstack/salt`_ as a git remote.
  74. .. code-block:: bash
  75. git remote add upstream https://github.com/saltstack/salt.git
  76. If you followed the Quickstart, you'll add your own remote instead
  77. .. code-block:: bash
  78. git remote add my-account git@github.com:my-account/salt.git
  79. #. Create a new branch in your clone.
  80. .. note::
  81. A branch should have one purpose. For example, "Fix bug X," or "Add
  82. feature Y". Multiple unrelated fixes and/or features should be
  83. isolated into separate branches.
  84. .. code-block:: bash
  85. git fetch upstream
  86. git checkout -b fix-broken-thing upstream/master
  87. #. Edit and commit changes to your branch.
  88. .. code-block:: bash
  89. vim path/to/file1 path/to/file2 tests/test_file1.py tests/test_file2.py
  90. git diff
  91. git add path/to/file1 path/to/file2
  92. git commit
  93. Write a short, descriptive commit title and a longer commit message if
  94. necessary. Use an imperative style for the title.
  95. GOOD
  96. .. code-block::
  97. Fix broken things in file1 and file2
  98. Fixes #31337
  99. We needed to make this change because the underlying dependency
  100. changed. Now this uses the up-to-date API.
  101. # Please enter the commit message for your changes. Lines starting
  102. # with '#' will be ignored, and an empty message aborts the commit.
  103. # On branch fix-broken-thing
  104. # Changes to be committed:
  105. # modified: path/to/file1
  106. # modified: path/to/file2
  107. BAD
  108. .. code-block::
  109. Fixes broken things
  110. # Please enter the commit message for your changes. Lines starting
  111. # with '#' will be ignored, and an empty message aborts the commit.
  112. # On branch fix-broken-thing
  113. # Changes to be committed:
  114. # modified: path/to/file1
  115. # modified: path/to/file2
  116. Taking a few moments to explain *why* you made a change will save time
  117. and effort in the future when others come to investigate a change. A
  118. clear explanation of why something changed can help future developers
  119. avoid introducing bugs, or breaking an edge case.
  120. .. note::
  121. If your change fixes a bug or implements a feature already filed in the
  122. `issue tracker`_, be sure to
  123. `reference the issue <https://help.github.com/en/articles/closing-issues-using-keywords>`_
  124. number in the commit message body.
  125. If you get stuck, there are many introductory Git resources on
  126. http://help.github.com.
  127. #. Push your locally-committed changes to your GitHub fork.
  128. .. code-block:: bash
  129. git push -u origin fix-broken-thing
  130. or
  131. .. code-block:: bash
  132. git push -u origin add-cool-feature
  133. .. note::
  134. You may want to rebase before pushing to work out any potential
  135. conflicts:
  136. .. code-block:: bash
  137. git fetch upstream
  138. git rebase upstream/master fix-broken-thing
  139. git push -u origin fix-broken-thing
  140. If you do rebase, and the push is rejected with a
  141. ``(non-fast-forward)`` comment, then run ``git status``. You will
  142. likely see a message about the branches diverging:
  143. .. code-block:: text
  144. On branch fix-broken-thing
  145. Your branch and 'origin/fix-broken-thing' have diverged,
  146. and have 1 and 2 different commits each, respectively.
  147. (use "git pull" to merge the remote branch into yours)
  148. nothing to commit, working tree clean
  149. Do **NOT** perform a ``git pull`` or ``git merge`` here. Instead, add
  150. ``--force-with-lease`` to the end of the ``git push`` command to get the changes
  151. pushed to your fork. Pulling or merging, while they will resolve the
  152. non-fast-forward issue, will likely add extra commits to the pull
  153. request which were not part of your changes.
  154. #. Find the branch on your GitHub salt fork.
  155. https://github.com/my-account/salt/branches/fix-broken-thing
  156. #. Open a new pull request.
  157. Click on ``Pull Request`` on the right near the top of the page,
  158. https://github.com/my-account/salt/pull/new/fix-broken-thing
  159. #. Choose ``master`` as the base Salt branch.
  160. #. Review that the proposed changes are what you expect.
  161. #. Write a descriptive comment. If you added good information to your git
  162. commit message, they will already be present here. Include links to
  163. related issues (e.g. 'Fixes #31337.') in the comment field.
  164. #. Click ``Create pull request``.
  165. #. Salt project members will review your pull request and automated tests will
  166. run on it.
  167. If you recognize any test failures as being related to your proposed
  168. changes or if a reviewer asks for modifications:
  169. #. Make the new changes in your local clone on the same local branch.
  170. #. Push the branch to GitHub again using the same commands as before.
  171. #. New and updated commits will be added to the pull request automatically.
  172. #. Feel free to add a comment to the discussion.
  173. .. note:: Jenkins
  174. Pull request against `saltstack/salt`_ are automatically tested on a
  175. variety of operating systems and configurations. On average these tests
  176. take a couple of hours. Depending on your GitHub notification settings
  177. you may also receive an email message about the test results.
  178. Test progress and results can be found at http://jenkins.saltstack.com/.
  179. .. _which-salt-branch:
  180. Salt's Branch Topology
  181. ----------------------
  182. Salt will only have one active branch - ``master``.
  183. This will include bug fixes, features and CVE “Common Vulnerabilities and Exposures”.
  184. The release will be cut from the master when the time comes for a new release,
  185. which should be every 3 to 4 months.
  186. To be able to merge code:
  187. #. The code must have a well-written test.
  188. Note that you are only expected to write tests for what you did, not the whole modules or function.
  189. #. All tests must pass.
  190. The SaltStack employee that reviews your pull request might request changes or deny the pull request for various reasons.
  191. Salt uses a typical branch strategy - ``master`` is the next expected release.
  192. Code should only make it to ``master`` once it's production ready. This means
  193. that typical changes (fixes, features) should have accompanying tests.\
  194. Closing GitHub issues from commits
  195. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  196. SaltStack encourages using `the magic keywords to close a GitHub issue <Closing
  197. issues via commit message_>`_. These should appear in the commit message text
  198. directly.
  199. Release Naming Convention
  200. -------------------------
  201. A new convention will start when Salt releases Salt 3000.
  202. Every new release name will increment by one ‘Salt last_release_number + 1’.
  203. This naming convention is very different from past releases, which was 'YYYY.MM.PATCH'.
  204. Handling CVE
  205. --------------
  206. If a CVE is discovered, Salt will create a new release that **only** contains the tests and patch for the CVE.
  207. This method should improve the upgrade process by reducing the chances of breaking something.
  208. .. _backporting-pull-requests:
  209. Backporting Pull Requests
  210. -------------------------
  211. On rare occasions, a serious bug will be found in the middle of a release
  212. cycle. These bugs will require a point release. Contributors should still
  213. submit fixes directly to ``master``, but they should also call attention to the
  214. fact that it addresses a critical issue and will need to be back-ported.
  215. Keeping Salt Forks in Sync
  216. --------------------------
  217. Salt advances quickly. It is therefore critical to pull upstream changes from
  218. upstream into your fork on a regular basis. Nothing is worse than putting hard
  219. work into a pull request only to see bunches of merge conflicts because it has
  220. diverged too far from upstream.
  221. .. seealso:: `GitHub Fork a Repo Guide`_
  222. The following assumes ``origin`` is the name of your fork and ``upstream`` is
  223. the name of the main `saltstack/salt`_ repository.
  224. #. View existing remotes.
  225. .. code-block:: bash
  226. git remote -v
  227. #. Add the ``upstream`` remote.
  228. .. code-block:: bash
  229. # For ssh github
  230. git remote add upstream git@github.com:saltstack/salt.git
  231. # For https github
  232. git remote add upstream https://github.com/saltstack/salt.git
  233. #. Pull upstream changes into your clone.
  234. .. code-block:: bash
  235. git fetch upstream
  236. #. Update your copy of the ``master`` branch.
  237. .. code-block:: bash
  238. git checkout master
  239. git merge --ff-only upstream/master
  240. If Git complains that a fast-forward merge is not possible, you have local
  241. commits.
  242. * Run ``git pull --rebase origin master`` to rebase your changes on top of
  243. the upstream changes.
  244. * Or, run ``git branch <branch-name>`` to create a new branch with your
  245. commits. You will then need to reset your ``master`` branch before
  246. updating it with the changes from upstream.
  247. If Git complains that local files will be overwritten, you have changes to
  248. files in your working directory. Run ``git status`` to see the files in
  249. question.
  250. #. Update your fork.
  251. .. code-block:: bash
  252. git push origin master
  253. #. Repeat the previous two steps for any other branches you work with, such as
  254. the current release branch.
  255. Posting patches to the mailing list
  256. -----------------------------------
  257. Patches will also be accepted by email. Format patches using `git
  258. format-patch`_ and send them to the `salt-users`_ mailing list. The contributor
  259. will then get credit for the patch, and the Salt community will have an archive
  260. of the patch and a place for discussion.
  261. Issue and Pull Request Labeling System
  262. --------------------------------------
  263. SaltStack uses several labeling schemes to help facilitate code contributions
  264. and bug resolution. See the :ref:`Labels and Milestones
  265. <labels-and-milestones>` documentation for more information.
  266. Mentionbot
  267. ----------
  268. SaltStack runs a mention-bot which notifies contributors who might be able
  269. to help review incoming pull-requests based on their past contribution to
  270. files which are being changed.
  271. If you do not wish to receive these notifications, please add your GitHub
  272. handle to the blacklist line in the ``.mention-bot`` file located in the
  273. root of the Salt repository.
  274. Bootstrap Script Changes
  275. ------------------------
  276. Salt's Bootstrap Script, known as `bootstrap-salt.sh`_ in the Salt repo, has it's own
  277. repository, contributing guidelines, and release cadence.
  278. All changes to the Bootstrap Script should be made to `salt-bootstrap repo`_. Any
  279. pull requests made to the `bootstrap-salt.sh`_ file in the Salt repository will be
  280. automatically overwritten upon the next stable release of the Bootstrap Script.
  281. For more information on the release process or how to contribute to the Bootstrap
  282. Script, see the Bootstrap Script's `Contributing Guidelines`_.
  283. .. _`saltstack/salt`: https://github.com/saltstack/salt
  284. .. _`GitHub Fork a Repo Guide`: https://help.github.com/articles/fork-a-repo
  285. .. _`issue tracker`: https://github.com/saltstack/salt/issues
  286. .. _`Fork saltstack/salt`: https://github.com/saltstack/salt/fork
  287. .. _'Git resources`: https://help.github.com/articles/good-resources-for-learning-git-and-github/
  288. .. _`Closing issues via commit message`: https://help.github.com/articles/closing-issues-via-commit-messages
  289. .. _`git format-patch`: https://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html
  290. .. _salt-users: https://groups.google.com/forum/#!forum/salt-users
  291. .. _GPG Probot: https://probot.github.io/apps/gpg/
  292. .. _help articles: https://help.github.com/articles/signing-commits-with-gpg/
  293. .. _GPG Signature Verification feature announcement: https://github.com/blog/2144-gpg-signature-verification
  294. .. _bootstrap-salt.sh: https://github.com/saltstack/salt/blob/master/salt/cloud/deploy/bootstrap-salt.sh
  295. .. _salt-bootstrap repo: https://github.com/saltstack/salt-bootstrap
  296. .. _Contributing Guidelines: https://github.com/saltstack/salt-bootstrap/blob/develop/CONTRIBUTING.md
  297. .. _`Black`: https://pypi.org/project/black/
  298. .. _`SEP 15`: https://github.com/saltstack/salt-enhancement-proposals/pull/21
  299. .. _`pre-commit`: https://pre-commit.com/
  300. .. _`SaltStack Community Slack`: https://saltstackcommunity.herokuapp.com/
  301. .. _`#salt on freenode`: http://webchat.freenode.net/?channels=salt&uio=Mj10cnVlJjk9dHJ1ZSYxMD10cnVl83
  302. .. _`saltstack meetup`: https://www.meetup.com/pro/saltstack/
  303. .. _`saltstack on serverfault`: https://serverfault.com/questions/tagged/saltstack