index.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. Upgrading 3rd-Party CSS/JavaScript Libraries
  85. --------------------------------------------
  86. External front-end libraries are included in two places:
  87. * Source or distributables are in ``coderedcms/static/coderedcms/vendor/``.
  88. * Referenced via a CDN in ``coderedcms/static/coderedcms/codered-front.js``.
  89. To upgrade, replace the relevant files or links in these two sources. Then be
  90. sure to change any URLs if applicable within the ``base.html`` template.
  91. If changing SASS sources, be sure to test ``.scss`` files in
  92. ``coderedcms/project_template/sass/`` which may require changes.
  93. Testing CodeRed CMS
  94. -------------------
  95. To run the unit tests, run the following command. This will output a unit test
  96. report and code coverage report:
  97. .. code-block:: console
  98. $ pytest coderedcms/ --ds=coderedcms.tests.settings --junitxml=junit/test-results.xml --cov=coderedcms --cov-report=xml --cov-report=html
  99. Or more conveniently, run the PowerShell script, which will also print out the
  100. code coverage percentage in the console:
  101. .. code-block:: console
  102. $ ./ci/run-tests.ps1
  103. Detailed test coverage reports are now available by opening ``htmlcov/index.html``
  104. in your browser (which is ignored by version control).
  105. To compare your current code coverage against the code coverage of the master
  106. branch (based on latest Azure Pipeline build from master) run:
  107. .. code-block:: console
  108. $ ./ci/compare-codecov.ps1
  109. Adding New Tests
  110. ----------------
  111. Test coverage at the moment is fairly minimal and it is highly recommended that
  112. new features and models include proper unit tests. Any testing infrastructure
  113. (i.e. implementations of abstract models and migrations) needed should be added
  114. to the ``tests`` app in your local copy of CodeRed CMS. The tests themselves
  115. should be in their relevant section in CodeRed CMS (i.e. tests for models in
  116. ``coderedcms.models.page_models`` should be located in
  117. ``coderedcms.models.tests.test_page_models``).
  118. For example, here is how you would add tests for a new abstract page type,
  119. ``CoderedCustomPage`` that would live in ``coderedcms/models/page_models.py``:
  120. #. Navigate to ``coderedcms/tests/testapp/models.py``
  121. #. Add the following import: ``from coderedcms.models.page_models import CoderedCustomPage``
  122. #. Implement a concrete version of ``CoderedCustomPage``, i.e. ``CustomPage(CoderedCustomPage)``.
  123. #. Run ``python manage.py makemigrations`` to make new testing migrations.
  124. #. Navigate to ``coderedcms/models/tests/test_page_models.py``
  125. #. Add the following import: ``from coderedcms.models import CoderedCustomPage``
  126. #. Add the following import: ``from coderedcms.tests.testapp.models import CustomPage``
  127. #. Add the following to the bottom of the file:
  128. .. code-block:: python
  129. class CoderedCustomPageTestCase(AbstractPageTestCase, WagtailPageTests):
  130. model = CoderedCustomPage
  131. #. Add the following to the bottom of the file:
  132. .. code-block:: python
  133. class CustomPageTestCase(ConcreteBasicPageTestCase, WagtailPageTests):
  134. model = CustomPage
  135. #. Write any specific test cases that ``CoderedCustomPage`` and ``CustomPage``
  136. may require.
  137. Static Analysis
  138. ---------------
  139. Flake8 is used to check for syntax and style errors. To analyze the entire
  140. codebase, run:
  141. .. code-block:: console
  142. $ flake8 .
  143. Alternatively, our continuous integration only analyzes the diff between your
  144. changes and master. To analyze just the diff of your current changes, run the
  145. `PowerShell Core <https://github.com/powershell/powershell>`_ script:
  146. .. code-block:: console
  147. $ ./ci/run-flake8.ps1
  148. Contributor Guidelines
  149. ----------------------
  150. We are happy to accept pull requests from the community if it aligns with our
  151. vision for coderedcms. When creating a pull request, please make sure you
  152. include the following:
  153. * A description in the pull request of what this change does and how it works.
  154. * Reference to an issue if the change is related to one of the issues on our
  155. GitHub page.
  156. * Documentation updates in the ``docs/`` directory describing your change.
  157. * Unit tests, or a description of how the change was manually tested.
  158. Following submission of your pull request, a CodeRed member will review and test
  159. your change. **All changes, even by CodeRed members, must go through a pull
  160. request process to ensure quality.**
  161. Merging Pull Requests
  162. ---------------------
  163. Follow these guidelines to merge a pull request into the master branch:
  164. * Unit tests pass.
  165. * Code coverage is not lower than master branch.
  166. * Documentation builds, and the PR provides documentation (release notes at a
  167. minimum).
  168. * If there is a related issue, the issue is referenced and/or closed (if
  169. applicable)
  170. * Finally, always make a squash merge with a single descriptive commit message.
  171. Avoid simply using the default commit message generated by GitHub if it is a
  172. summary of previous commits or is not descriptive of the change.
  173. In the event that the pull request needs more work that the author is unable to
  174. provide, the following process should be followed:
  175. * Create a new branch from master in the form of ``merge/pr-123`` where 123 is
  176. the original pull request number.
  177. * Edit the pull request to merge into the new branch instead of master.
  178. * Make the necessary changes and submit for review using the normal process.
  179. * When merging this branch into master, follow the same process above, but be
  180. sure to credit the original author(s) by adding their names to the bottom of
  181. the commit message as so (see
  182. `GitHub documentation <https://help.github.com/en/articles/creating-a-commit-with-multiple-authors>`_):
  183. .. code-block:: text
  184. Co-authored-by: name <name@example.com>
  185. Co-authored-by: another-name <another-name@example.com>
  186. Building Python Packages
  187. ------------------------
  188. To build a publicly consumable pip package, run:
  189. .. code-block:: console
  190. $ python setup.py sdist bdist_wheel
  191. Building Documentation
  192. ----------------------
  193. For every code or feature change, be sure to update the docs in the repository.
  194. To build the documentation run the PowerShell script, which will also check for
  195. errors in the documentation:
  196. .. code-block:: console
  197. $ ./ci/make-docs.ps1
  198. Or manually using sphinx:
  199. .. code-block:: console
  200. $ sphinx-build -M html docs/ docs/_build/ -W
  201. Output will be in ``docs/_build/html/`` directory.
  202. Publishing a New Release
  203. ------------------------
  204. First checkout the code/branch for release.
  205. Next build a pip package:
  206. .. code-block:: console
  207. $ python setup.py sdist bdist_wheel
  208. Then upload the pip package to the Python Package Index:
  209. .. code-block:: console
  210. $ twine upload dist/*
  211. Finally build and update docs:
  212. .. code-block:: console
  213. $ ./ci/make-docs.ps1
  214. If updating docs for an existing minor version release:
  215. #. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under
  216. the existing version directory.
  217. If this is a new major or minor version release:
  218. #. Create a new ``major.minor`` directory on the CodeRed docs server.
  219. #. Update the ``stable`` symbolic link to point to the new version directory.
  220. #. Add the new version to the ``versions.txt`` file on the docs server.
  221. #. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under
  222. the new version directory.
  223. Note that we do not release separate documentation versions for maintenance
  224. releases. Update the existing minor version docs with release notes and other
  225. changes.