1
0

contributing.rst 17 KB

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