index.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. Contributing
  2. ============
  3. Developing CodeRed CMS
  4. ----------------------
  5. To create a test project locally:
  6. #. Clone the code from https://github.com/coderedcorp/coderedcms (dev branch).
  7. #. Run ``pip install -r requirements-dev.txt`` from the root coderedcms
  8. directory. This will install development tools, and also make the install
  9. editable, which is relevant when running ``makemigrations`` in test project
  10. to actually generate the migration files in the coderedcms pip package.
  11. #. Follow the steps in :doc:`/getting_started/install`. Use ``testproject`` for
  12. your project name to ensure it is ignored by git.
  13. #. When making model or block changes within coderedcms, run
  14. ``makemigrations coderedcms`` in the test project to generate the relevant
  15. migration files for the pip package. ALWAYS follow steps 4 and 5 in
  16. :doc:`/getting_started/install` with a fresh database before making migrations.
  17. #. When model or block changes affect the local test project (i.e. the "website"
  18. app), run ``makemigrations website`` in the test project to generate the
  19. relevant migration files locally. Apply and test the migrations. When
  20. satisfied, re-generate the ``0001_initial.py`` migration in
  21. ``project_template/website/migrations/`` as so:
  22. #. Create a new test project using ``coderedcms start testproject``.
  23. #. Before running migrations, DELETE all migrations in
  24. ``testproject/website/migrations/``.
  25. #. Run ``python manage.py makemigrations website``. This should generate
  26. an ``0001_initial.py`` migration.
  27. #. Replace ``project_template/website/migrations/0001_initial.py`` with
  28. your newly generated migration.
  29. When making changes that are potentially destructive or backwards incompatible,
  30. increment the minor version number until coderedcms reaches a stable 1.0 release.
  31. Each production project that uses coderedcms should specify the appropriate
  32. version in its requirements.txt to prevent breakage.
  33. .. note::
  34. When testing existing projects with coderedcms installed from a development
  35. branch, be sure to use a disposable database, as it is likely that the
  36. migrations will not be the same migrations that get released.
  37. Branching Strategy
  38. ------------------
  39. Primary development takes place in individual branches for each feature or bug.
  40. Changes are then made as a pull request against the ``dev`` branch.
  41. The ``dev`` branch is the primary working branch, representing the development
  42. version of coderedcms.
  43. Releases are maintained in ``release/X.Y`` branches, where X is the Major
  44. version and Y is the Minor version. Maintenance patches are applied in ``dev``
  45. (if applicable) and then merged or cherry-picked into the respective release
  46. branch.
  47. A Note on Cross-Platform Support
  48. --------------------------------
  49. CodeRed CMS works equally well on Windows, macOS, and Linux. When adding new features
  50. or new dependencies, ensure that these utilize proper cross-platform utilities in Python.
  51. To ease local development of CodeRed CMS, we have some automation scripts using
  52. cross-platform `PowerShell Core <https://github.com/powershell/powershell>`_.
  53. Throughout this contributing guide, you will encounter various PowerShell
  54. scripts which provide an easy way of running quality control measures.
  55. Our goal is that users of any platform can develop or host a CodeRed CMS website easily.
  56. CSS Development
  57. ---------------
  58. When CSS changes are needed for front-end code (not the wagtail admin), Sass should be used.
  59. Each block, page, snippet, or other component that requires styling should have a dedicated ``.scss``
  60. file created beginning with an underscore in ``coderedcms/static/scss/``. Then import the file
  61. in our main ``codered-front.scss`` file. Then build a human readable and minified version of CSS
  62. from the command prompt as so:
  63. .. code-block:: console
  64. $ cd coderedcms/static/coderedcms/
  65. // Build human readable CSS, and source map for nicer debugging.
  66. $ pysassc -g -t expanded scss/codered-front.scss css/codered-front.css
  67. // Build minified CSS.
  68. $ pysassc -t compressed scss/codered-front.scss css/codered-front.min.css
  69. Finally, copy the license header comment into codered-front.min.css (since ``pysassc`` does
  70. not have an argument to preserve comments while also using compressed output).
  71. The generated CSS files must also be committed to version control whenever a sass file is
  72. changed, as they are distributed as part of our package.
  73. JavaScript Development
  74. ----------------------
  75. All JavaScript should use ``codered-front.js`` as an entry point, meaning feature
  76. detection should happen in ``codered-front.js`` and then only load secondary scripts and CSS
  77. as needed. This ensures only one single small JavaScript file is required on page load, which
  78. reduces render-blocking resources and page load time.
  79. All JavaScript files produced by CodeRed should contain a license header comment. This standard
  80. license header comment states copyright, ownership, license, and also provides compatibility for
  81. `LibreJS <https://www.gnu.org/software/librejs/free-your-javascript.html>`_.
  82. .. code-block:: text
  83. /*
  84. CodeRed CMS (https://www.coderedcorp.com/cms/)
  85. Copyright 2018-2019 CodeRed LLC
  86. License: https://github.com/coderedcorp/coderedcms/blob/dev/LICENSE
  87. @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause
  88. */
  89. ... script code here ...
  90. /* @license-end */
  91. Upgrading 3rd-Party CSS/JavaScript Libraries
  92. --------------------------------------------
  93. External front-end libraries are included in two places:
  94. * Source or distributables are in ``coderedcms/static/coderedcms/vendor/``.
  95. * Referenced via a CDN in ``coderedcms/static/coderedcms/codered-front.js``.
  96. To upgrade, replace the relevant files or links in these two sources. Then be
  97. sure to change any URLs if applicable within the ``base.html`` template.
  98. If changing SASS sources, be sure to test ``.scss`` files in
  99. ``coderedcms/project_template/sass/`` which may require changes.
  100. Testing CodeRed CMS
  101. -------------------
  102. To run the unit tests, run the following command. This will output a unit test
  103. report and code coverage report:
  104. .. code-block:: console
  105. $ pytest coderedcms/
  106. Or more conveniently, run the PowerShell script, which will also print out the
  107. code coverage percentage in the console:
  108. .. code-block:: console
  109. $ ./ci/run-tests.ps1
  110. Detailed test coverage reports are now available by opening ``htmlcov/index.html``
  111. in your browser (which is ignored by version control).
  112. To compare your current code coverage against the code coverage of the dev
  113. branch (based on latest Azure Pipeline build from dev) run:
  114. .. code-block:: console
  115. $ ./ci/compare-codecov.ps1
  116. Adding New Tests
  117. ----------------
  118. Test coverage at the moment is fairly minimal and it is highly recommended that
  119. new features and models include proper unit tests. Any testing infrastructure
  120. (i.e. implementations of abstract models and migrations) needed should be added
  121. to the ``tests`` app in your local copy of CodeRed CMS. The tests themselves
  122. should be in their relevant section in CodeRed CMS (i.e. tests for models in
  123. ``coderedcms.models.page_models`` should be located in
  124. ``coderedcms.models.tests.test_page_models``).
  125. For example, here is how you would add tests for a new abstract page type,
  126. ``CoderedCustomPage`` that would live in ``coderedcms/models/page_models.py``:
  127. #. Navigate to ``coderedcms/tests/testapp/models.py``
  128. #. Add the following import: ``from coderedcms.models.page_models import CoderedCustomPage``
  129. #. Implement a concrete version of ``CoderedCustomPage``, i.e. ``CustomPage(CoderedCustomPage)``.
  130. #. Run ``python manage.py makemigrations`` to make new testing migrations.
  131. #. Navigate to ``coderedcms/models/tests/test_page_models.py``
  132. #. Add the following import: ``from coderedcms.models import CoderedCustomPage``
  133. #. Add the following import: ``from coderedcms.tests.testapp.models import CustomPage``
  134. #. Add the following to the bottom of the file:
  135. .. code-block:: python
  136. class CoderedCustomPageTestCase(AbstractPageTestCase, WagtailPageTests):
  137. model = CoderedCustomPage
  138. #. Add the following to the bottom of the file:
  139. .. code-block:: python
  140. class CustomPageTestCase(ConcreteBasicPageTestCase, WagtailPageTests):
  141. model = CustomPage
  142. #. Write any specific test cases that ``CoderedCustomPage`` and ``CustomPage``
  143. may require.
  144. Static Analysis
  145. ---------------
  146. Flake8 is used to check for syntax and style errors. To analyze the entire
  147. codebase, run:
  148. .. code-block:: console
  149. $ flake8 .
  150. Alternatively, our continuous integration only analyzes the diff between your
  151. changes and the dev branch. To analyze just the diff of your current changes,
  152. run the PowerShell script:
  153. .. code-block:: console
  154. $ ./ci/run-flake8.ps1
  155. Contributor Guidelines
  156. ----------------------
  157. We are happy to accept pull requests from the community if it aligns with our
  158. vision for coderedcms. When creating a pull request, please make sure you
  159. include the following:
  160. * A description in the pull request of what this change does and how it works.
  161. * Reference to an issue if the change is related to one of the issues on our
  162. GitHub page.
  163. * Documentation updates in the ``docs/`` directory describing your change.
  164. * Unit tests, or a description of how the change was manually tested.
  165. Following submission of your pull request, a CodeRed member will review and test
  166. your change. **All changes, even by CodeRed members, must go through a pull
  167. request process to ensure quality.**
  168. Merging Pull Requests
  169. ---------------------
  170. Follow these guidelines to merge a pull request into the dev branch:
  171. * Unit tests pass.
  172. * Code coverage is not lower than dev branch.
  173. * Documentation builds, and the PR provides documentation (release notes at a
  174. minimum).
  175. * If there is a related issue, the issue is referenced and/or closed (if
  176. applicable)
  177. * Finally, always make a squash merge with a single descriptive commit message.
  178. Avoid simply using the default commit message generated by GitHub if it is a
  179. summary of previous commits or is not descriptive of the change.
  180. In the event that the pull request needs more work that the author is unable to
  181. provide, the following process should be followed:
  182. * Create a new branch from dev in the form of ``merge/pr-123`` where 123 is
  183. the original pull request number.
  184. * Edit the pull request to merge into the new branch instead of dev.
  185. * Make the necessary changes and submit for review using the normal process.
  186. * When merging this branch into dev, follow the same process above, but be
  187. sure to credit the original author(s) by adding their names to the bottom of
  188. the commit message as so (see
  189. `GitHub documentation <https://help.github.com/en/articles/creating-a-commit-with-multiple-authors>`_):
  190. .. code-block:: text
  191. Co-authored-by: name <name@example.com>
  192. Co-authored-by: another-name <another-name@example.com>
  193. Building Python Packages
  194. ------------------------
  195. To build a publicly consumable pip package, run:
  196. .. code-block:: console
  197. $ python setup.py sdist bdist_wheel
  198. Building Documentation
  199. ----------------------
  200. For every code or feature change, be sure to update the docs in the repository.
  201. To build the documentation run the PowerShell script, which will also check for
  202. errors in the documentation:
  203. .. code-block:: console
  204. $ ./ci/make-docs.ps1
  205. Or manually using sphinx:
  206. .. code-block:: console
  207. $ sphinx-build -M html docs/ docs/_build/ -W
  208. Output will be in ``docs/_build/html/`` directory.
  209. Publishing a New Release
  210. ------------------------
  211. .. note::
  212. For creating pre-releases, use the "rc" version specifier in
  213. ``coderedcms/__init__.py``. When publishing a production release, leave this
  214. blank. After a release is completed, increment the version and add the
  215. "dev0" version specifier.
  216. First checkout the code/branch for release.
  217. Next build a pip package:
  218. .. code-block:: console
  219. $ python setup.py sdist bdist_wheel
  220. Then upload the pip package to the Python Package Index:
  221. .. code-block:: console
  222. $ twine upload dist/*
  223. Finally build and update docs:
  224. .. code-block:: console
  225. $ ./ci/make-docs.ps1
  226. If updating docs for an existing major version release:
  227. #. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under
  228. the existing version directory.
  229. Note that we do not release separate documentation versions for minor or
  230. maintenance releases. Update the existing major version docs with release notes
  231. and other changes.