contributing.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. .. _contributing:
  2. ============
  3. Contributing
  4. ============
  5. There is a great need for contributions to Salt and patches are welcome! The goal
  6. here is to make contributions clear, make sure there is a trail for where the code
  7. has come from, and most importantly, to give credit where credit is due!
  8. There are a number of ways to contribute to Salt development.
  9. For details on how to contribute documentation improvements please review
  10. :ref:`Writing Salt Documentation <salt-docs>`.
  11. Salt Coding Style
  12. -----------------
  13. SaltStack has its own coding style guide that informs contributors on various coding
  14. approaches. Please review the :ref:`Salt Coding Style <coding-style>` documentation
  15. for information about Salt's particular coding patterns.
  16. Within the :ref:`Salt Coding Style <coding-style>` documentation, there is a
  17. section about running Salt's ``.testing.pylintrc`` file. SaltStack recommends
  18. running the ``.testing.pylintrc`` file on any files you are changing with your
  19. code contribution before submitting a pull request to Salt's repository. Please
  20. see the :ref:`Linting<pylint-instructions>` documentation for more information.
  21. .. note::
  22. There are two pylint files in the ``salt`` directory. One is the
  23. ``.pylintrc`` file and the other is the ``.testing.pylintrc`` file. The
  24. tests that run in Jenkins against GitHub Pull Requests use
  25. ``.testing.pylintrc``. The ``testing.pylintrc`` file is a little less
  26. strict than the ``.pylintrc`` and is used to make it easier for contributors
  27. to submit changes. The ``.pylintrc`` file can be used for linting, but the
  28. ``testing.pylintrc`` is the source of truth when submitting pull requests.
  29. .. _github-pull-request:
  30. New Features
  31. ------------
  32. Feature requests through Salt go through a multi-stage process.
  33. All features are added to major releases only. Salt does not accept
  34. feature additions in bug-fix branches. Therefore, all feature work
  35. is done exclusively in the develop branch.
  36. To formally propose a new feature, the proposal must take the form
  37. of an RFC. To create an RFC, copy the template file found in the rfcs/
  38. directory of the Salt codebase and fill the outline with the reasoning
  39. for the new feature and with implementation details.
  40. Upon submitting the written RFC via a pull-request, it will be reviewed
  41. by the core development team as well as the community. Once discussed
  42. and agreed upon, the RFC may be merged.
  43. A merged RFC indicates that a feature has been accepted and will be
  44. added to an upcoming release of Salt.
  45. Sending a GitHub pull request
  46. -----------------------------
  47. Sending pull requests on GitHub is the preferred method for receiving
  48. contributions. The workflow advice below mirrors `GitHub's own guide <GitHub
  49. Fork a Repo Guide_>`_ and is well worth reading.
  50. #. `Fork saltstack/salt`_ on GitHub.
  51. #. Make a local clone of your fork.
  52. .. code-block:: bash
  53. git clone git@github.com:my-account/salt.git
  54. cd salt
  55. #. Add `saltstack/salt`_ as a git remote.
  56. .. code-block:: bash
  57. git remote add upstream https://github.com/saltstack/salt.git
  58. #. Create a new branch in your clone.
  59. .. note::
  60. A branch should have one purpose. For example, "Fix bug X," or "Add
  61. feature Y". Multiple unrelated fixes and/or features should be
  62. isolated into separate branches.
  63. If you're working on a bug or documentation fix, create your branch from
  64. the oldest **supported** main release branch that contains the bug or requires the documentation
  65. update. See :ref:`Which Salt Branch? <which-salt-branch>`.
  66. .. code-block:: bash
  67. git fetch upstream
  68. git checkout -b fix-broken-thing upstream/2016.11
  69. If you're working on a feature, create your branch from the develop branch.
  70. .. code-block:: bash
  71. git fetch upstream
  72. git checkout -b add-cool-feature upstream/develop
  73. #. Edit and commit changes to your branch.
  74. .. code-block:: bash
  75. vim path/to/file1 path/to/file2
  76. git diff
  77. git add path/to/file1 path/to/file2
  78. git commit
  79. Write a short, descriptive commit title and a longer commit message if
  80. necessary.
  81. .. note::
  82. If your change fixes a bug or implements a feature already filed in the
  83. `issue tracker`_, be sure to
  84. `reference the issue <https://help.github.com/en/articles/closing-issues-using-keywords>`_
  85. number in the commit message body.
  86. .. code-block:: bash
  87. Fix broken things in file1 and file2
  88. Fixes #31337
  89. # Please enter the commit message for your changes. Lines starting
  90. # with '#' will be ignored, and an empty message aborts the commit.
  91. # On branch fix-broken-thing
  92. # Changes to be committed:
  93. # modified: path/to/file1
  94. # modified: path/to/file2
  95. If you get stuck, there are many introductory Git resources on
  96. http://help.github.com.
  97. #. Push your locally-committed changes to your GitHub fork.
  98. .. code-block:: bash
  99. git push -u origin fix-broken-thing
  100. or
  101. .. code-block:: bash
  102. git push -u origin add-cool-feature
  103. .. note::
  104. You may want to rebase before pushing to work out any potential
  105. conflicts:
  106. .. code-block:: bash
  107. git fetch upstream
  108. git rebase upstream/2016.11 fix-broken-thing
  109. git push -u origin fix-broken-thing
  110. or
  111. .. code-block:: bash
  112. git fetch upstream
  113. git rebase upstream/develop add-cool-feature
  114. git push -u origin add-cool-feature
  115. If you do rebase, and the push is rejected with a
  116. ``(non-fast-forward)`` comment, then run ``git status``. You will
  117. likely see a message about the branches diverging:
  118. .. code-block:: text
  119. On branch fix-broken-thing
  120. Your branch and 'origin/fix-broken-thing' have diverged,
  121. and have 1 and 2 different commits each, respectively.
  122. (use "git pull" to merge the remote branch into yours)
  123. nothing to commit, working tree clean
  124. Do **NOT** perform a ``git pull`` or ``git merge`` here. Instead, add
  125. ``--force-with-lease`` to the end of the ``git push`` command to get the changes
  126. pushed to your fork. Pulling or merging, while they will resolve the
  127. non-fast-forward issue, will likely add extra commits to the pull
  128. request which were not part of your changes.
  129. #. Find the branch on your GitHub salt fork.
  130. https://github.com/my-account/salt/branches/fix-broken-thing
  131. #. Open a new pull request.
  132. Click on ``Pull Request`` on the right near the top of the page,
  133. https://github.com/my-account/salt/pull/new/fix-broken-thing
  134. #. If your branch is a fix for a release branch, choose that as the base
  135. branch (e.g. ``2016.11``),
  136. https://github.com/my-account/salt/compare/saltstack:2016.11...fix-broken-thing
  137. If your branch is a feature, choose ``develop`` as the base branch,
  138. https://github.com/my-account/salt/compare/saltstack:develop...add-cool-feature
  139. #. Review that the proposed changes are what you expect.
  140. #. Write a descriptive comment. Include links to related issues (e.g.
  141. 'Fixes #31337.') in the comment field.
  142. #. Click ``Create pull request``.
  143. #. Salt project members will review your pull request and automated tests will
  144. run on it.
  145. If you recognize any test failures as being related to your proposed
  146. changes or if a reviewer asks for modifications:
  147. #. Make the new changes in your local clone on the same local branch.
  148. #. Push the branch to GitHub again using the same commands as before.
  149. #. New and updated commits will be added to the pull request automatically.
  150. #. Feel free to add a comment to the discussion.
  151. .. note:: Jenkins
  152. Pull request against `saltstack/salt`_ are automatically tested on a
  153. variety of operating systems and configurations. On average these tests
  154. take 30 minutes. Depending on your GitHub notification settings you may
  155. also receive an email message about the test results.
  156. Test progress and results can be found at http://jenkins.saltstack.com/.
  157. .. _which-salt-branch:
  158. Salt's Branch Topology
  159. ----------------------
  160. There are three different kinds of branches in use: develop, main release
  161. branches, and dot release branches.
  162. - All feature work should go into the ``develop`` branch.
  163. - Bug fixes and documentation changes should go into the oldest **supported
  164. main** release branch affected by the the bug or documentation change (you
  165. can use the blame button in github to figure out when the bug was introduced).
  166. Supported releases are the last 2 releases. For example, if the latest release
  167. is 2018.3, the last two release are 2018.3 and 2017.7.
  168. Main release branches are named after a year and month, such as
  169. ``2016.11`` and ``2017.7``.
  170. - Hot fixes, as determined by SaltStack's release team, should be submitted
  171. against **dot** release branches. Dot release branches are named after a
  172. year, month, and version. Examples include ``2016.11.8`` and ``2017.7.2``.
  173. .. note::
  174. GitHub will open pull requests against Salt's main branch, ``develop``,
  175. by default. Be sure to check which branch is selected when creating the
  176. pull request.
  177. The Develop Branch
  178. ==================
  179. The ``develop`` branch is unstable and bleeding-edge. Pull requests containing
  180. feature additions or non-bug-fix changes should be made against the ``develop``
  181. branch.
  182. .. note::
  183. If you have a bug fix or documentation change and have already forked your
  184. working branch from ``develop`` and do not know how to rebase your commits
  185. against another branch, then submit it to ``develop`` anyway. SaltStack's
  186. development team will be happy to back-port it to the correct branch.
  187. **Please make sure you let the maintainers know that the pull request needs
  188. to be back-ported.**
  189. Main Release Branches
  190. =====================
  191. The current release branch is the most recent stable release. Pull requests
  192. containing bug fixes or documentation changes should be made against the oldest supported main
  193. release branch that is affected.
  194. The branch name will be a date-based name such as ``2016.11``.
  195. Bug fixes are made on this branch so that dot release branches can be cut from
  196. the main release branch without introducing surprises and new features. This
  197. approach maximizes stability.
  198. Dot Release Branches
  199. ====================
  200. Prior to tagging an official release, a branch will be created when the SaltStack
  201. release team is ready to tag. The dot release branch is created from a main release
  202. branch. The dot release branch will be the same name as the tag minus the ``v``.
  203. For example, the ``2017.7.1`` dot release branch was created from the ``2017.7``
  204. main release branch. The ``v2017.7.1`` release was tagged at the ``HEAD`` of the
  205. ``2017.7.1`` branch.
  206. This branching strategy will allow for more stability when there is a need for
  207. a re-tag during the testing phase of the release process and further increases
  208. stability.
  209. Once the dot release branch is created, the fixes required for a given release,
  210. as determined by the SaltStack release team, will be added to this branch. All
  211. commits in this branch will be merged forward into the main release branch as
  212. well.
  213. Merge Forward Process
  214. =====================
  215. The Salt repository follows a "Merge Forward" policy. The merge-forward
  216. behavior means that changes submitted to older main release branches will
  217. automatically be "merged-forward" into the newer branches.
  218. For example, a pull request is merged into ``2017.7``. Then, the entire
  219. ``2017.7`` branch is merged-forward into the ``2018.3`` branch, and the
  220. ``2018.3`` branch is merged-forward into the ``develop`` branch.
  221. This process makes is easy for contributors to make only one pull-request
  222. against an older branch, but allows the change to propagate to all **main**
  223. release branches.
  224. The merge-forward work-flow applies to all main release branches and the
  225. operation runs continuously.
  226. Merge-Forwards for Dot Release Branches
  227. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228. The merge-forward policy applies to dot release branches as well, but has a
  229. slightly different behavior. If a change is submitted to a **dot** release
  230. branch, the dot release branch will be merged into its parent **main**
  231. release branch.
  232. For example, a pull request is merged into the ``2017.7.2`` release branch.
  233. Then, the entire ``2017.7.2`` branch is merged-forward into the ``2017.7``
  234. branch. From there, the merge forward process continues as normal.
  235. The only way in which dot release branches differ from main release branches
  236. in regard to merge-forwards, is that once a dot release branch is created
  237. from the main release branch, the dot release branch does not receive merge
  238. forwards.
  239. .. note::
  240. The merge forward process for dot release branches is one-way:
  241. dot release branch --> main release branch.
  242. Closing GitHub issues from commits
  243. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  244. This "merge-forward" strategy requires that `the magic keywords to close a
  245. GitHub issue <Closing issues via commit message_>`_ appear in the commit
  246. message text directly. Only including the text in a pull request will not
  247. close the issue.
  248. GitHub will close the referenced issue once the *commit* containing the
  249. magic text is merged into the default branch (``develop``). Any magic text
  250. input only into the pull request description will not be seen at the
  251. Git-level when those commits are merged-forward. In other words, only the
  252. commits are merged-forward and not the pull request text.
  253. .. _backporting-pull-requests:
  254. Backporting Pull Requests
  255. =========================
  256. If a bug is fixed on ``develop`` and the bug is also present on a
  257. currently-supported release branch, it will need to be back-ported to an
  258. applicable branch.
  259. .. note:: Most Salt contributors can skip these instructions
  260. These instructions do not need to be read in order to contribute to the
  261. Salt project! The SaltStack team will back-port fixes on behalf of
  262. contributors in order to keep the contribution process easy.
  263. These instructions are intended for frequent Salt contributors, advanced
  264. Git users, SaltStack employees, or independent souls who wish to back-port
  265. changes themselves.
  266. It is often easiest to fix a bug on the oldest supported release branch and
  267. then merge that branch forward into ``develop`` (as described earlier in this
  268. document). When that is not possible the fix must be back-ported, or copied,
  269. into any other affected branches.
  270. These steps assume a pull request ``#1234`` has been merged into ``develop``.
  271. And ``upstream`` is the name of the remote pointing to the main Salt repo.
  272. #. Identify the oldest supported release branch that is affected by the bug.
  273. #. Create a new branch for the back-port by reusing the same branch from the
  274. original pull request.
  275. Name the branch ``bp-<NNNN>`` and use the number of the original pull
  276. request.
  277. .. code-block:: bash
  278. git fetch upstream refs/pull/1234/head:bp-1234
  279. git checkout bp-1234
  280. #. Find the parent commit of the original pull request.
  281. The parent commit of the original pull request must be known in order to
  282. rebase onto a release branch. The easiest way to find this is on GitHub.
  283. Open the original pull request on GitHub and find the first commit in the
  284. list of commits. Select and copy the SHA for that commit. The parent of
  285. that commit can be specified by appending ``~1`` to the end.
  286. #. Rebase the new branch on top of the release branch.
  287. * ``<release-branch>`` is the branch identified in step #1.
  288. * ``<orig-base>`` is the SHA identified in step #3 -- don't forget to add
  289. ``~1`` to the end!
  290. .. code-block:: bash
  291. git rebase --onto <release-branch> <orig-base> bp-1234
  292. Note, release branches prior to ``2016.11`` will not be able to make use of
  293. rebase and must use cherry-picking instead.
  294. #. Push the back-port branch to GitHub and open a new pull request.
  295. Opening a pull request for the back-port allows for the test suite and
  296. normal code-review process.
  297. .. code-block:: bash
  298. git push -u origin bp-1234
  299. Keeping Salt Forks in Sync
  300. --------------------------
  301. Salt advances quickly. It is therefore critical to pull upstream changes
  302. from upstream into your fork on a regular basis. Nothing is worse than putting
  303. hard work into a pull request only to see bunches of merge conflicts because it
  304. has diverged too far from upstream.
  305. .. seealso:: `GitHub Fork a Repo Guide`_
  306. The following assumes ``origin`` is the name of your fork and ``upstream`` is
  307. the name of the main `saltstack/salt`_ repository.
  308. #. View existing remotes.
  309. .. code-block:: bash
  310. git remote -v
  311. #. Add the ``upstream`` remote.
  312. .. code-block:: bash
  313. # For ssh github
  314. git remote add upstream git@github.com:saltstack/salt.git
  315. # For https github
  316. git remote add upstream https://github.com/saltstack/salt.git
  317. #. Pull upstream changes into your clone.
  318. .. code-block:: bash
  319. git fetch upstream
  320. #. Update your copy of the ``develop`` branch.
  321. .. code-block:: bash
  322. git checkout develop
  323. git merge --ff-only upstream/develop
  324. If Git complains that a fast-forward merge is not possible, you have local
  325. commits.
  326. * Run ``git pull --rebase origin develop`` to rebase your changes on top of
  327. the upstream changes.
  328. * Or, run ``git branch <branch-name>`` to create a new branch with your
  329. commits. You will then need to reset your ``develop`` branch before
  330. updating it with the changes from upstream.
  331. If Git complains that local files will be overwritten, you have changes to
  332. files in your working directory. Run ``git status`` to see the files in
  333. question.
  334. #. Update your fork.
  335. .. code-block:: bash
  336. git push origin develop
  337. #. Repeat the previous two steps for any other branches you work with, such as
  338. the current release branch.
  339. Posting patches to the mailing list
  340. -----------------------------------
  341. Patches will also be accepted by email. Format patches using `git
  342. format-patch`_ and send them to the `salt-users`_ mailing list. The contributor
  343. will then get credit for the patch, and the Salt community will have an archive
  344. of the patch and a place for discussion.
  345. Issue and Pull Request Labeling System
  346. --------------------------------------
  347. SaltStack uses several labeling schemes to help facilitate code contributions
  348. and bug resolution. See the :ref:`Labels and Milestones
  349. <labels-and-milestones>` documentation for more information.
  350. Mentionbot
  351. ----------
  352. SaltStack runs a mention-bot which notifies contributors who might be able
  353. to help review incoming pull-requests based on their past contribution to
  354. files which are being changed.
  355. If you do not wish to receive these notifications, please add your GitHub
  356. handle to the blacklist line in the ``.mention-bot`` file located in the
  357. root of the Salt repository.
  358. .. _probot-gpg-verification:
  359. GPG Verification
  360. ----------------
  361. SaltStack has enabled `GPG Probot`_ to enforce GPG signatures for all
  362. commits included in a Pull Request.
  363. In order for the GPG verification status check to pass, *every* contributor in
  364. the pull request must:
  365. - Set up a GPG key on local machine
  366. - Sign all commits in the pull request with key
  367. - Link key with GitHub account
  368. This applies to all commits in the pull request.
  369. GitHub hosts a number of `help articles`_ for creating a GPG key, using the
  370. GPG key with ``git`` locally, and linking the GPG key to your GitHub account.
  371. Once these steps are completed, the commit signing verification will look like
  372. the example in GitHub's `GPG Signature Verification feature announcement`_.
  373. Bootstrap Script Changes
  374. ------------------------
  375. Salt's Bootstrap Script, known as `bootstrap-salt.sh`_ in the Salt repo, has it's own
  376. repository, contributing guidelines, and release cadence.
  377. All changes to the Bootstrap Script should be made to `salt-bootstrap repo`_. Any
  378. pull requests made to the `bootstrap-salt.sh`_ file in the Salt repository will be
  379. automatically overwritten upon the next stable release of the Bootstrap Script.
  380. For more information on the release process or how to contribute to the Bootstrap
  381. Script, see the Bootstrap Script's `Contributing Guidelines`_.
  382. .. _`saltstack/salt`: https://github.com/saltstack/salt
  383. .. _`GitHub Fork a Repo Guide`: https://help.github.com/articles/fork-a-repo
  384. .. _`issue tracker`: https://github.com/saltstack/salt/issues
  385. .. _`Fork saltstack/salt`: https://github.com/saltstack/salt/fork
  386. .. _'Git resources`: https://help.github.com/articles/good-resources-for-learning-git-and-github/
  387. .. _`Closing issues via commit message`: https://help.github.com/articles/closing-issues-via-commit-messages
  388. .. _`git format-patch`: https://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html
  389. .. _salt-users: https://groups.google.com/forum/#!forum/salt-users
  390. .. _GPG Probot: https://probot.github.io/apps/gpg/
  391. .. _help articles: https://help.github.com/articles/signing-commits-with-gpg/
  392. .. _GPG Signature Verification feature announcement: https://github.com/blog/2144-gpg-signature-verification
  393. .. _bootstrap-salt.sh: https://github.com/saltstack/salt/blob/develop/salt/cloud/deploy/bootstrap-salt.sh
  394. .. _salt-bootstrap repo: https://github.com/saltstack/salt-bootstrap
  395. .. _Contributing Guidelines: https://github.com/saltstack/salt-bootstrap/blob/develop/CONTRIBUTING.md