contributing.rst 20 KB

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