index.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. Contributing
  2. ============
  3. Developing Wagtail CRX
  4. ----------------------
  5. To create a test project locally:
  6. #. Clone the code from https://github.com/coderedcorp/coderedcms (main 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 ``main`` branch.
  41. The ``main`` branch is the primary working branch, representing the development
  42. version of coderedcms.
  43. Releases are maintained in ``release/X`` branches, where X is the
  44. Major version. Maintenance patches are applied in ``main`` (if
  45. applicable) and then merged or cherry-picked into the respective
  46. release branch.
  47. A Note on Cross-Platform Support
  48. --------------------------------
  49. Wagtail CRX 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 Wagtail CRX, 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 Wagtail CRX 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 ``crx-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/crx-front.scss css/crx-front.css
  67. $ # Build minified CSS.
  68. $ pysassc -t compressed scss/crx-front.scss css/crx-front.min.css
  69. The generated CSS files must also be committed to version control whenever a sass file is
  70. changed, as they are distributed as part of our package.
  71. JavaScript Development
  72. ----------------------
  73. All JavaScript should use ``crx-front.js`` as an entry point, meaning feature
  74. detection should happen in ``crx-front.js`` and then only load secondary scripts and CSS
  75. as needed. This ensures only one single small JavaScript file is required on page load, which
  76. reduces render-blocking resources and page load time.
  77. All JavaScript files produced by CodeRed should contain a license header comment. This standard
  78. license header comment states copyright, ownership, license, and also provides compatibility for
  79. `LibreJS <https://www.gnu.org/software/librejs/free-your-javascript.html>`_.
  80. .. code-block:: text
  81. /*!
  82. Wagtail CRX (https://www.coderedcorp.com/cms/)
  83. Copyright 2018-2023 CodeRed LLC
  84. License: https://github.com/coderedcorp/coderedcms/blob/main/LICENSE
  85. @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause
  86. */
  87. ... script code here ...
  88. /* @license-end */
  89. Upgrading 3rd-Party CSS/JavaScript Libraries
  90. --------------------------------------------
  91. External front-end libraries are included in two places:
  92. * Source or distributables are in ``coderedcms/static/coderedcms/vendor/``.
  93. * Referenced via a CDN in ``coderedcms/static/coderedcms/crx-front.js``.
  94. To upgrade, replace the relevant files or links in these two sources. Then be
  95. sure to change any URLs if applicable within the ``base.html`` template.
  96. If changing SASS sources, be sure to test ``.scss`` files in
  97. ``coderedcms/project_template/sass/`` which may require changes.
  98. Testing Wagtail CRX
  99. -------------------
  100. To run the unit tests, run the following command. This will output a unit test
  101. report and code coverage report:
  102. .. code-block:: console
  103. $ pytest coderedcms/
  104. Or more conveniently, run the PowerShell script, which will also print out the
  105. code coverage percentage in the console:
  106. .. code-block:: console
  107. $ ./ci/run-tests.ps1
  108. Detailed test coverage reports are now available by opening ``htmlcov/index.html``
  109. in your browser (which is ignored by version control).
  110. To compare your current code coverage against the code coverage of the main
  111. branch (based on latest Azure Pipeline build from main) run:
  112. .. code-block:: console
  113. $ ./ci/compare-codecov.ps1
  114. Adding New Tests
  115. ----------------
  116. Test coverage at the moment is fairly minimal and it is highly recommended that
  117. new features and models include proper unit tests. Any testing infrastructure
  118. (i.e. implementations of abstract models and migrations) needed should be added
  119. to the ``tests`` app in your local copy of Wagtail CRX. The tests themselves
  120. should be in their relevant section in Wagtail CRX (i.e. tests for models in
  121. ``coderedcms.models.page_models`` should be located in
  122. ``coderedcms.models.tests.test_page_models``).
  123. For example, here is how you would add tests for a new abstract page type,
  124. ``CoderedCustomPage`` that would live in ``coderedcms/models/page_models.py``:
  125. #. Navigate to ``coderedcms/tests/testapp/models.py``
  126. #. Add the following import: ``from coderedcms.models.page_models import CoderedCustomPage``
  127. #. Implement a concrete version of ``CoderedCustomPage``, i.e. ``CustomPage(CoderedCustomPage)``.
  128. #. Run ``python manage.py makemigrations`` to make new testing migrations.
  129. #. Navigate to ``coderedcms/models/tests/test_page_models.py``
  130. #. Add the following import: ``from coderedcms.models import CoderedCustomPage``
  131. #. Add the following import: ``from coderedcms.tests.testapp.models import CustomPage``
  132. #. Add the following to the bottom of the file:
  133. .. code-block:: python
  134. class CoderedCustomPageTestCase(AbstractPageTestCase, WagtailPageTests):
  135. model = CoderedCustomPage
  136. #. Add the following to the bottom of the file:
  137. .. code-block:: python
  138. class CustomPageTestCase(ConcreteBasicPageTestCase, WagtailPageTests):
  139. model = CustomPage
  140. #. Write any specific test cases that ``CoderedCustomPage`` and ``CustomPage``
  141. may require.
  142. Static Analysis
  143. ---------------
  144. All code should be formatted with ``ruff`` before committing:
  145. .. code-block:: console
  146. $ ruff format .
  147. Ruff is also used to check for syntax and style errors. To analyze the entire codebase, run:
  148. .. code-block:: console
  149. $ ruff check --fix .
  150. Contributor Guidelines
  151. ----------------------
  152. We are happy to accept pull requests from the community if it aligns with our
  153. vision for coderedcms. When creating a pull request, please make sure you
  154. include the following:
  155. * A description in the pull request of what this change does and how it works.
  156. * Reference to an issue if the change is related to one of the issues on our
  157. GitHub page.
  158. * Documentation updates in the ``docs/`` directory describing your change.
  159. * Unit tests, or a description of how the change was manually tested.
  160. Following submission of your pull request, a CodeRed member will review and test
  161. your change. **All changes, even by CodeRed members, must go through a pull
  162. request process to ensure quality.**
  163. Merging Pull Requests
  164. ---------------------
  165. Follow these guidelines to merge a pull request into the main branch:
  166. * Unit tests pass.
  167. * Code coverage is not lower than main branch.
  168. * Documentation builds, and the PR provides documentation (release notes at a
  169. minimum).
  170. * If there is a related issue, the issue is referenced and/or closed (if
  171. applicable)
  172. * Finally, always make a squash merge with a single descriptive commit message.
  173. Avoid simply using the default commit message generated by GitHub if it is a
  174. summary of previous commits or is not descriptive of the change.
  175. In the event that the pull request needs more work that the author is unable to
  176. provide, the following process should be followed:
  177. * Create a new branch from main in the form of ``merge/pr-123`` where 123 is
  178. the original pull request number.
  179. * Edit the pull request to merge into the new branch instead of main.
  180. * Make the necessary changes and submit for review using the normal process.
  181. * When merging this branch into main, follow the same process above, but be
  182. sure to credit the original author(s) by adding their names to the bottom of
  183. the commit message as so (see
  184. `GitHub documentation <https://help.github.com/en/articles/creating-a-commit-with-multiple-authors>`_):
  185. .. code-block:: text
  186. Co-authored-by: name <name@example.com>
  187. Co-authored-by: another-name <another-name@example.com>
  188. Building Python Packages
  189. ------------------------
  190. To build a publicly consumable pip package, run:
  191. .. code-block:: console
  192. $ python -m build
  193. Building Documentation
  194. ----------------------
  195. For every code or feature change, be sure to update the docs in the repository.
  196. To build the documentation run the PowerShell script, which will also check for
  197. errors in the documentation:
  198. .. code-block:: console
  199. $ ./ci/make-docs.ps1
  200. Or manually using sphinx:
  201. .. code-block:: console
  202. $ sphinx-build -M html docs/ docs/_build/ -W
  203. Output will be in ``docs/_build/html/`` directory.
  204. Publishing a New Release
  205. ------------------------
  206. .. note::
  207. For creating pre-releases, use the "rc" version specifier in
  208. ``coderedcms/__init__.py``. When publishing a production release, leave this
  209. blank. After a release is completed, increment the version and add the
  210. "dev0" version specifier.
  211. First checkout the code/branch for release.
  212. Next build a pip package:
  213. .. code-block:: console
  214. $ python -m build
  215. Then upload the pip package to the Python Package Index:
  216. .. code-block:: console
  217. $ twine upload dist/*
  218. Finally build and update docs:
  219. .. code-block:: console
  220. $ ./ci/make-docs.ps1
  221. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under the existing version directory. Using the ``cr`` tool:
  222. .. code-block:: console
  223. $ cr upload --path ./docs/_build/html/ --remote /www/wagtail-crx/ docs