index.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. Contributing
  2. ============
  3. Developing Wagtail CRX
  4. ----------------------
  5. To create a test project locally:
  6. #. Clone the code from https://github.com/coderedcorp/wagtailcrx (dev branch).
  7. #. Run ``pip install -r requirements-dev.txt`` from the root wagtailcrx
  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 wagtailcrx 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 wagtailcrx, run
  14. ``makemigrations wagtailcrx`` 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 ``wagtailcrx 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 wagtailcrx reaches a stable 1.0 release.
  31. Each production project that uses wagtailcrx should specify the appropriate
  32. version in its requirements.txt to prevent breakage.
  33. .. note::
  34. When testing existing projects with wagtailcrx 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 ``dev`` branch.
  41. The ``dev`` branch is the primary working branch, representing the development
  42. version of wagtailcrx.
  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 ``dev``
  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 ``wagtailcrx/static/scss/``. Then import the file
  61. in our main ``codered-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 wagtailcrx/static/wagtailcrx/
  65. $ # Build human readable CSS, and source map for nicer debugging.
  66. $ pysassc -g -t expanded scss/codered-front.scss css/codered-front.css
  67. $ # Build minified CSS.
  68. $ pysassc -t compressed scss/codered-front.scss css/codered-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 ``codered-front.js`` as an entry point, meaning feature
  74. detection should happen in ``codered-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-2021 CodeRed LLC
  84. License: https://github.com/coderedcorp/wagtailcrx/blob/dev/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 ``wagtailcrx/static/wagtailcrx/vendor/``.
  93. * Referenced via a CDN in ``wagtailcrx/static/wagtailcrx/codered-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. ``wagtailcrx/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 wagtailcrx/
  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 dev
  111. branch (based on latest Azure Pipeline build from dev) 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. ``wagtailcrx.models.page_models`` should be located in
  122. ``wagtailcrx.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 ``wagtailcrx/models/page_models.py``:
  125. #. Navigate to ``wagtailcrx/tests/testapp/models.py``
  126. #. Add the following import: ``from wagtailcrx.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 ``wagtailcrx/models/tests/test_page_models.py``
  130. #. Add the following import: ``from wagtailcrx.models import CoderedCustomPage``
  131. #. Add the following import: ``from wagtailcrx.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. Flake8 is used to check for syntax and style errors. To analyze the entire
  145. codebase, run:
  146. .. code-block:: console
  147. $ flake8 .
  148. Alternatively, our continuous integration only analyzes the diff between your
  149. changes and the dev branch. To analyze just the diff of your current changes,
  150. run the PowerShell script:
  151. .. code-block:: console
  152. $ ./ci/run-flake8.ps1
  153. Contributor Guidelines
  154. ----------------------
  155. We are happy to accept pull requests from the community if it aligns with our
  156. vision for wagtailcrx. When creating a pull request, please make sure you
  157. include the following:
  158. * A description in the pull request of what this change does and how it works.
  159. * Reference to an issue if the change is related to one of the issues on our
  160. GitHub page.
  161. * Documentation updates in the ``docs/`` directory describing your change.
  162. * Unit tests, or a description of how the change was manually tested.
  163. Following submission of your pull request, a CodeRed member will review and test
  164. your change. **All changes, even by CodeRed members, must go through a pull
  165. request process to ensure quality.**
  166. Merging Pull Requests
  167. ---------------------
  168. Follow these guidelines to merge a pull request into the dev branch:
  169. * Unit tests pass.
  170. * Code coverage is not lower than dev branch.
  171. * Documentation builds, and the PR provides documentation (release notes at a
  172. minimum).
  173. * If there is a related issue, the issue is referenced and/or closed (if
  174. applicable)
  175. * Finally, always make a squash merge with a single descriptive commit message.
  176. Avoid simply using the default commit message generated by GitHub if it is a
  177. summary of previous commits or is not descriptive of the change.
  178. In the event that the pull request needs more work that the author is unable to
  179. provide, the following process should be followed:
  180. * Create a new branch from dev in the form of ``merge/pr-123`` where 123 is
  181. the original pull request number.
  182. * Edit the pull request to merge into the new branch instead of dev.
  183. * Make the necessary changes and submit for review using the normal process.
  184. * When merging this branch into dev, follow the same process above, but be
  185. sure to credit the original author(s) by adding their names to the bottom of
  186. the commit message as so (see
  187. `GitHub documentation <https://help.github.com/en/articles/creating-a-commit-with-multiple-authors>`_):
  188. .. code-block:: text
  189. Co-authored-by: name <name@example.com>
  190. Co-authored-by: another-name <another-name@example.com>
  191. Building Python Packages
  192. ------------------------
  193. To build a publicly consumable pip package, run:
  194. .. code-block:: console
  195. $ python setup.py sdist bdist_wheel
  196. Building Documentation
  197. ----------------------
  198. For every code or feature change, be sure to update the docs in the repository.
  199. To build the documentation run the PowerShell script, which will also check for
  200. errors in the documentation:
  201. .. code-block:: console
  202. $ ./ci/make-docs.ps1
  203. Or manually using sphinx:
  204. .. code-block:: console
  205. $ sphinx-build -M html docs/ docs/_build/ -W
  206. Output will be in ``docs/_build/html/`` directory.
  207. Publishing a New Release
  208. ------------------------
  209. .. note::
  210. For creating pre-releases, use the "rc" version specifier in
  211. ``wagtailcrx/__init__.py``. When publishing a production release, leave this
  212. blank. After a release is completed, increment the version and add the
  213. "dev0" version specifier.
  214. First checkout the code/branch for release.
  215. Next build a pip package:
  216. .. code-block:: console
  217. $ python setup.py sdist bdist_wheel
  218. Then upload the pip package to the Python Package Index:
  219. .. code-block:: console
  220. $ twine upload dist/*
  221. Finally build and update docs:
  222. .. code-block:: console
  223. $ ./ci/make-docs.ps1
  224. If updating docs for an existing major version release:
  225. #. Copy the contents of ``docs/_build/html/`` to the CodeRed docs server under
  226. the existing version directory.
  227. Note that we do not release separate documentation versions for minor or
  228. maintenance releases. Update the existing major version docs with release notes
  229. and other changes.