contributing.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. #. Check `Github Actions`_ status on your fork
  175. By now, and in case you haven't disabled `Github Actions`_, you should have at least 3
  176. workflows running on your fork.
  177. #. ``Pre-Commit`` - The pre-commit checks salt uses to validate several parts of its codebase
  178. #. ``Docs`` - Builds Salt's Documentation
  179. #. ``Lint`` - Runs lint checks agraint the salt codebase
  180. Go to https://github.com/my-account/salt/actions to check them out.
  181. These will give you an early warning in case something is not right, giving you a chance to fix
  182. them even before you open a pull request against the Salt repository.
  183. #. Find the branch on your GitHub salt fork.
  184. https://github.com/my-account/salt/branches/fix-broken-thing
  185. #. Open a new pull request.
  186. Click on ``Pull Request`` on the right near the top of the page,
  187. https://github.com/my-account/salt/pull/new/fix-broken-thing
  188. #. Choose ``master`` as the base Salt branch.
  189. #. Review that the proposed changes are what you expect.
  190. #. Write a descriptive comment. If you added good information to your git
  191. commit message, they will already be present here. Include links to
  192. related issues (e.g. 'Fixes #31337.') in the comment field.
  193. #. Click ``Create pull request``.
  194. #. Salt project members will review your pull request and automated tests will
  195. run on it.
  196. If you recognize any test failures as being related to your proposed
  197. changes or if a reviewer asks for modifications:
  198. #. Make the new changes in your local clone on the same local branch.
  199. #. Push the branch to GitHub again using the same commands as before.
  200. #. New and updated commits will be added to the pull request automatically.
  201. #. Feel free to add a comment to the discussion.
  202. .. note:: Jenkins
  203. Pull request against `saltstack/salt`_ are automatically tested on a
  204. variety of operating systems and configurations. On average these tests
  205. take a couple of hours. Depending on your GitHub notification settings
  206. you may also receive an email message about the test results.
  207. Test progress and results can be found at https://jenkinsci.saltstack.com/.
  208. .. _which-salt-branch:
  209. Salt's Branch Topology
  210. ----------------------
  211. Salt will only have one active branch - ``master``.
  212. This will include bug fixes, features and CVE “Common Vulnerabilities and Exposures”.
  213. The release will be cut from the master when the time comes for a new release,
  214. which should be every 3 to 4 months.
  215. To be able to merge code:
  216. #. The code must have a well-written test.
  217. Note that you are only expected to write tests for what you did, not the whole modules or function.
  218. #. All tests must pass.
  219. The SaltStack employee that reviews your pull request might request changes or deny the pull request for various reasons.
  220. Salt uses a typical branch strategy - ``master`` is the next expected release.
  221. Code should only make it to ``master`` once it's production ready. This means
  222. that typical changes (fixes, features) should have accompanying tests.\
  223. Closing GitHub issues from commits
  224. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  225. SaltStack encourages using `the magic keywords to close a GitHub issue <Closing
  226. issues via commit message_>`_. These should appear in the commit message text
  227. directly.
  228. Release Naming Convention
  229. -------------------------
  230. A new convention will start when Salt releases Salt 3000.
  231. Every new release name will increment by one ‘Salt last_release_number + 1’.
  232. This naming convention is very different from past releases, which was 'YYYY.MM.PATCH'.
  233. Handling CVE
  234. --------------
  235. If a CVE is discovered, Salt will create a new release that **only** contains the tests and patch for the CVE.
  236. This method should improve the upgrade process by reducing the chances of breaking something.
  237. .. _backporting-pull-requests:
  238. Backporting Pull Requests
  239. -------------------------
  240. On rare occasions, a serious bug will be found in the middle of a release
  241. cycle. These bugs will require a point release. Contributors should still
  242. submit fixes directly to ``master``, but they should also call attention to the
  243. fact that it addresses a critical issue and will need to be back-ported.
  244. Keeping Salt Forks in Sync
  245. --------------------------
  246. Salt advances quickly. It is therefore critical to pull upstream changes from
  247. upstream into your fork on a regular basis. Nothing is worse than putting hard
  248. work into a pull request only to see bunches of merge conflicts because it has
  249. diverged too far from upstream.
  250. .. seealso:: `GitHub Fork a Repo Guide`_
  251. The following assumes ``origin`` is the name of your fork and ``upstream`` is
  252. the name of the main `saltstack/salt`_ repository.
  253. #. View existing remotes.
  254. .. code-block:: bash
  255. git remote -v
  256. #. Add the ``upstream`` remote.
  257. .. code-block:: bash
  258. # For ssh github
  259. git remote add upstream git@github.com:saltstack/salt.git
  260. # For https github
  261. git remote add upstream https://github.com/saltstack/salt.git
  262. #. Pull upstream changes into your clone.
  263. .. code-block:: bash
  264. git fetch upstream
  265. #. Update your copy of the ``master`` branch.
  266. .. code-block:: bash
  267. git checkout master
  268. git merge --ff-only upstream/master
  269. If Git complains that a fast-forward merge is not possible, you have local
  270. commits.
  271. * Run ``git pull --rebase origin master`` to rebase your changes on top of
  272. the upstream changes.
  273. * Or, run ``git branch <branch-name>`` to create a new branch with your
  274. commits. You will then need to reset your ``master`` branch before
  275. updating it with the changes from upstream.
  276. If Git complains that local files will be overwritten, you have changes to
  277. files in your working directory. Run ``git status`` to see the files in
  278. question.
  279. #. Update your fork.
  280. .. code-block:: bash
  281. git push origin master
  282. #. Repeat the previous two steps for any other branches you work with, such as
  283. the current release branch.
  284. Posting patches to the mailing list
  285. -----------------------------------
  286. Patches will also be accepted by email. Format patches using `git
  287. format-patch`_ and send them to the `salt-users`_ mailing list. The contributor
  288. will then get credit for the patch, and the Salt community will have an archive
  289. of the patch and a place for discussion.
  290. Issue and Pull Request Labeling System
  291. --------------------------------------
  292. SaltStack uses several labeling schemes to help facilitate code contributions
  293. and bug resolution. See the :ref:`Labels and Milestones
  294. <labels-and-milestones>` documentation for more information.
  295. Mentionbot
  296. ----------
  297. SaltStack runs a mention-bot which notifies contributors who might be able
  298. to help review incoming pull-requests based on their past contribution to
  299. files which are being changed.
  300. If you do not wish to receive these notifications, please add your GitHub
  301. handle to the blacklist line in the ``.mention-bot`` file located in the
  302. root of the Salt repository.
  303. Bootstrap Script Changes
  304. ------------------------
  305. Salt's Bootstrap Script, known as `bootstrap-salt.sh`_ in the Salt repo, has its own
  306. repository, contributing guidelines, and release cadence.
  307. All changes to the Bootstrap Script should be made to `salt-bootstrap repo`_. Any
  308. pull requests made to the `bootstrap-salt.sh`_ file in the Salt repository will be
  309. automatically overwritten upon the next stable release of the Bootstrap Script.
  310. For more information on the release process or how to contribute to the Bootstrap
  311. Script, see the Bootstrap Script's `Contributing Guidelines`_.
  312. .. _`saltstack/salt`: https://github.com/saltstack/salt
  313. .. _`GitHub Fork a Repo Guide`: https://help.github.com/articles/fork-a-repo
  314. .. _`issue tracker`: https://github.com/saltstack/salt/issues
  315. .. _`Fork saltstack/salt`: https://github.com/saltstack/salt/fork
  316. .. _'Git resources`: https://help.github.com/articles/good-resources-for-learning-git-and-github/
  317. .. _`Closing issues via commit message`: https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue
  318. .. _`git format-patch`: https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-format-patch.html
  319. .. _salt-users: https://groups.google.com/forum/#!forum/salt-users
  320. .. _GPG Probot: https://probot.github.io/apps/gpg/
  321. .. _help articles: https://help.github.com/articles/signing-commits-with-gpg/
  322. .. _GPG Signature Verification feature announcement: https://github.com/blog/2144-gpg-signature-verification
  323. .. _bootstrap-salt.sh: https://github.com/saltstack/salt/blob/master/salt/cloud/deploy/bootstrap-salt.sh
  324. .. _salt-bootstrap repo: https://github.com/saltstack/salt-bootstrap
  325. .. _Contributing Guidelines: https://github.com/saltstack/salt-bootstrap/blob/develop/CONTRIBUTING.md
  326. .. _`Black`: https://pypi.org/project/black/
  327. .. _`SEP 15`: https://github.com/saltstack/salt-enhancement-proposals/pull/21
  328. .. _`pre-commit`: https://pre-commit.com/
  329. .. _`SaltStack Community Slack`: https://saltstackcommunity.herokuapp.com/
  330. .. _`#salt on freenode`: https://webchat.freenode.net/#salt
  331. .. _`saltstack meetup`: https://www.meetup.com/pro/saltstack/
  332. .. _`saltstack on serverfault`: https://serverfault.com/questions/tagged/saltstack
  333. .. _`Github Actions`: https://docs.github.com/actions