index.rst 11 KB

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