index.rst 12 KB

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