2
0

index.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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.Y`` branches, where X is the Major
  44. version and Y is the Minor version. Maintenance patches are applied in ``main``
  45. (if applicable) and then merged or cherry-picked into the respective release
  46. 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 ``black`` before committing:
  145. .. code-block:: console
  146. $ black .
  147. Flake8 is used to check for syntax and style errors. To analyze the entire
  148. codebase, run:
  149. .. code-block:: console
  150. $ flake8 .
  151. Contributor Guidelines
  152. ----------------------
  153. We are happy to accept pull requests from the community if it aligns with our
  154. vision for coderedcms. When creating a pull request, please make sure you
  155. include the following:
  156. * A description in the pull request of what this change does and how it works.
  157. * Reference to an issue if the change is related to one of the issues on our
  158. GitHub page.
  159. * Documentation updates in the ``docs/`` directory describing your change.
  160. * Unit tests, or a description of how the change was manually tested.
  161. Following submission of your pull request, a CodeRed member will review and test
  162. your change. **All changes, even by CodeRed members, must go through a pull
  163. request process to ensure quality.**
  164. Merging Pull Requests
  165. ---------------------
  166. Follow these guidelines to merge a pull request into the main branch:
  167. * Unit tests pass.
  168. * Code coverage is not lower than main branch.
  169. * Documentation builds, and the PR provides documentation (release notes at a
  170. minimum).
  171. * If there is a related issue, the issue is referenced and/or closed (if
  172. applicable)
  173. * Finally, always make a squash merge with a single descriptive commit message.
  174. Avoid simply using the default commit message generated by GitHub if it is a
  175. summary of previous commits or is not descriptive of the change.
  176. In the event that the pull request needs more work that the author is unable to
  177. provide, the following process should be followed:
  178. * Create a new branch from main in the form of ``merge/pr-123`` where 123 is
  179. the original pull request number.
  180. * Edit the pull request to merge into the new branch instead of main.
  181. * Make the necessary changes and submit for review using the normal process.
  182. * When merging this branch into main, follow the same process above, but be
  183. sure to credit the original author(s) by adding their names to the bottom of
  184. the commit message as so (see
  185. `GitHub documentation <https://help.github.com/en/articles/creating-a-commit-with-multiple-authors>`_):
  186. .. code-block:: text
  187. Co-authored-by: name <name@example.com>
  188. Co-authored-by: another-name <another-name@example.com>
  189. Building Python Packages
  190. ------------------------
  191. To build a publicly consumable pip package, run:
  192. .. code-block:: console
  193. $ python setup.py sdist bdist_wheel
  194. Building Documentation
  195. ----------------------
  196. For every code or feature change, be sure to update the docs in the repository.
  197. To build the documentation run the PowerShell script, which will also check for
  198. errors in the documentation:
  199. .. code-block:: console
  200. $ ./ci/make-docs.ps1
  201. Or manually using sphinx:
  202. .. code-block:: console
  203. $ sphinx-build -M html docs/ docs/_build/ -W
  204. Output will be in ``docs/_build/html/`` directory.
  205. Updating Tutorial Documentation
  206. -------------------------------
  207. From time to time, the documentation for the tutorial will need to be updated. You can work directly in
  208. the tutorial site by loading the fixture file for its database (read more at :ref:`load-data`).
  209. However, once you have worked in the tutorial site and gotten new screenshots for the **Getting Started** documentation,
  210. you will also need to update the fixture file, which is located in ``tutorial > mysite > website > fixtures``.
  211. **These are the steps for updating the fixture:**
  212. 1. From the command line, type ``python manage.py dumpdata --natural-foreign --natural-primary -e contenttypes -e auth.Permission --indent 4 > dumpdata.json``
  213. 2. The dumped data file will show up in the ``website`` folder. Open it and copy/paste its contents into a new file called ``database.json``. This will fix the encoding issue you would run into otherwise. Save the new fixture file and delete the one that was dumped. Also delete the one that is currently in the ``fixtures`` folder.
  214. 3. Move the ``database.json`` file into the ``fixtures`` folder.
  215. 4. For testing ``loaddata``, please review the steps at :ref:`load-data`.
  216. Publishing a New Release
  217. ------------------------
  218. .. note::
  219. For creating pre-releases, use the "rc" version specifier in
  220. ``coderedcms/__init__.py``. When publishing a production release, leave this
  221. blank. After a release is completed, increment the version and add the
  222. "dev0" version specifier.
  223. First checkout the code/branch for release.
  224. Next build a pip package:
  225. .. code-block:: console
  226. $ python setup.py sdist bdist_wheel
  227. Then upload the pip package to the Python Package Index:
  228. .. code-block:: console
  229. $ twine upload dist/*
  230. Finally build and update docs:
  231. .. code-block:: console
  232. $ ./ci/make-docs.ps1
  233. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under the existing version directory. Using the ``cr`` tool:
  234. .. code-block:: console
  235. $ cr upload --path ./docs/_build/html/ --remote /www/wagtail-crx/ docs
  236. Note that we do not release separate documentation versions for minor or
  237. maintenance releases. Update the existing major version docs with release notes
  238. and other changes.