Debian Codegraph @

devel-docs/ci.rst

raw
1 Continuous Integration
2 ======================
3
4 Or, when robots are eager to help.
5
6 Librsvg's repository on gitlab.gnome.org is configured to use a
7 Continuous Integration (CI) pipeline, so that it compiles the code and
8 runs the test suite after every ``git push``.
9
10 If you have never read it before, please read `The Not Rocket Science
11 Rule of Software Engineering
12 <https://graydon2.dreamwidth.org/1597.html>`_, about automatically
13 maintaining a repository of code that always passes all the tests.
14 This is what librsvg tries to do!
15
16 In addition to running the test suite, the CI pipeline does other cool
17 things. The pipeline is divided into *stages*. Here is roughly what
18 they do:
19
20 - First, set up a *reproducible environment* to build and test things:
21 this builds a couple of container images and automatically updates
22 them in gitlab. The container images have all of librsvg's
23 dependencies, and all the tools required for compilation, building
24 the documentation, and casual debugging.
25
26 - Then, run a quick ``cargo check`` ("does this have a chance of
27 compiling?"), and ``cargo test`` (run a fast subset of the test
28 suite). This stage is intended to catch breakage early.
29
30 - Then, run the full test suite in a couple different configurations:
31 different versions of Rust, different distros with slightly
32 different versions of dependencies. This stage is intended to catch
33 common sources of breakage across environments.
34
35 - In parallel with the above, run ``cargo clippy`` and ``cargo fmt``.
36 The first usually has good suggestions to improve the code; the latter
37 is to guarantee a consistent indentation style.
38
39 - In parallel, obtain a test coverage report. We'll talk about this below.
40
41 - Check whether making a release at this point would actually work:
42 this builds a release tarball and tries to compile it and run the
43 test suite again.
44
45 - Finally, generate documentation: reference docs for the C and Rust
46 APIs, and the rendered version of this development guide. Publish
47 the docs and coverage report to a web page.
48
49 We'll explain each stage in detail next.
50
51 Creating a reproducible environment
52 -----------------------------------
53
54 The task of setting up CI for a particular distro or build
55 configuration is rather repetitive. One has to start with a "bare"
56 distro image, then install the build-time dependencies that your
57 project requires, then that is slow, then you want to build a
58 container image instead of installing packages every time, then you
59 want to test another distro, then you want to make those container
60 images easily available to your project's forks, and then you start
61 pulling your hair.
62
63 `Fredesktop CI Templates
64 <https://gitlab.freedesktop.org/freedesktop/ci-templates/>`_
65 (`documentation
66 <https://freedesktop.pages.freedesktop.org/ci-templates/>`_) are a
67 solution to this. They can automatically build container images for
68 various distros, make them available to forks of your project, and
69 have some nice amenities to reduce the maintenance burden.
70
71 Librsvg uses CI templates to test its various build configurations.
72 The container images are stored here:
73 https://gitlab.gnome.org/GNOME/librsvg/container_registry
74
75 See the section below on the "Full test suite and different
76 environments" for details on what gets tested on the different
77 container images produced by this stage.
78
79 .. NOTE: The target below is used outside this development guide.
80
81 .. _container-image-version:
82
83 .. important::
84
85 Whenever changes are made to the CI environments (such as updating
86 dependencies or CI tools, or their versions), the container image
87 version tag defined as ``BASE_TAG`` in :source:`ci/container_builds.yml`
88 should be incremented appropriately.
89
90 The tag name is (by convention) of the format
91
92 .. code::
93
94 <date>.<version>-[<user_name>_]<branch_name>
95
96 where:
97
98 - *date* is the current date when incrementing the version tag and is
99 of the format ``YYYY-MM-DD``.
100 - *version* is an index number (starting from zero) to differentiate
101 images built on the same day for the same branch.
102 - *branch_name* is the name of the branch on which the CI changes are
103 being made.
104 - *user_name* is the user name of the branch's owner and is optional
105 but recommended for branches on forks, in order to avoid tag name
106 clashes with equally-named branches on other forks.
107
108 For example:
109
110 - ``2024-10-20.0-main`` ->
111 first iteration for ``GNOME/librsvg:main`` on 2024-10-20
112 - ``2025-09-01.1-foo_bar`` ->
113 second iteration for ``GNOME/librsvg:foo-bar`` on 2025-09-01
114 - ``2099-12-31.3-federico_bar_foo`` ->
115 third iteration for ``federico/librsvg:bar-foo`` on 2099-12-31
116
117 For any branch that is **not** :source:`GNOME/librsvg:main <main:>` and
118 is intended **to be merged** into it: Once the new container images are
119 confirmed to be working as expected, the version tag should be
120 incremented again **before merging** into ``main``, this time without
121 *user_name* and with ``main`` as *branch_name*.
122 This is always best done **when the branch is ready to be merged**, in
123 order to avoid unnecessary tag name conflicts and CI surprises.
124 In the case of conflicting tag names with ``main``, be sure to increment
125 the *version* number if the tag name on ``main`` has the current date.
126
127 If unsure whether a change you made is concerned or for any further
128 clarification, please ask the
129 :source:`maintainers <README.md#maintainers>`.
130
131
132 Quick checks
133 ------------
134
135 ``cargo check`` and ``cargo test`` run relatively quickly, and can catch
136 trivial compilation problems as well as breakage in the "fast" section
137 of the test suite. When trying out things in a branch or a merge
138 request, you can generally look at only these two jobs for a fast
139 feedback loop.
140
141
142 Full test suite and different environments
143 ------------------------------------------
144
145 - The "full test suite" in principle runs ``meson test``.
146 This runs the "fast" portion of the test suite, but also a few slow
147 tests which are designed to test librsvg's built-in limits. It also
148 runs the C API tests, which require a C compiler.
149
150 - There are builds use a certain Minimum Supported Rust Version
151 (MSRV), also a relatively recent stable Rust, and Rust nightly.
152 Building with the MSRV is to help distros that don't update Rust
153 super regularly, and also to ensure that librsvg's dependencies do
154 not suddently start depending on a too-recent Rust version, for
155 example. Building on nightly is hopefully to catch compiler bugs
156 early, or to get an early warning when the Rust compiler is about to
157 introduce newer lints/warnings.
158
159 - Build on a couple of distros. Librsvg's test suite is especially
160 sensitive to changes in rendering from Cairo, Pixman, and the
161 Pango/Freetype2/Harfbuzz stack. Building on a few distros gives us
162 slightly different versions of those dependencies, so that we can
163 catch breakage early.
164
165
166 Lints and formatting
167 --------------------
168
169 There is a job for ``cargo clippy``. Clippy usually has very good
170 suggestions to improve the coding style, so take advantage of them!
171 And if Clippy's suggetions don't make sense for a particular portion
172 of the code, feel free to add exceptions like
173 ``#[allow(clippy::foo_bar)]`` to the corresponding block.
174
175 There is a job for ``cargo fmt``. Librsvg uses the default formatting
176 for Rust code. For portions of code that are more legible if
177 indented/aligned by hand, please use ``#[rustfmt::skip]``.
178
179 One job runs ``cargo deny``, which checks if there are dependencies with
180 vulnerabilities.
181
182 Another job runs a script to check that the version numbers mentioned
183 in various parts of the source code all match. For example,
184 ``Cargo.toml`` and ``meson.build`` must have checks for the same Minimum
185 Supported Rust Version (MSRV).
186
187
188 Test coverage report
189 --------------------
190
191 There is a job that generates a `test coverage report
192 <https://gnome.pages.gitlab.gnome.org/librsvg/coverage/index.html>`_.
193 The code gets instrumented, and as the test suite runs, the
194 instrumentation remembers which lines of code were executed and which
195 ones were not; this then gets presented in an HTML report. This can
196 be used for various things:
197
198 - See which parts of the code are not executed while running the test
199 suite. Maybe we need to add tests that cause them to run!
200
201 - If you disable most of the test suite, you can use the coverage
202 report to explore which parts of the code get executed with a
203 particular SVG. This can aid in learning the code base.
204
205
206 Release tests
207 -------------
208
209 There is a job that runs ``meson dist``, a part of Meson that
210 simulates building a full release tarball. Running this in the CI
211 helps us guarantee that librsvg is always in a release-worthy state.
212
213
214 Generate documentation
215 ----------------------
216
217 The following sets of documentation get generated:
218
219 - `C API docs
220 <https://gnome.pages.gitlab.gnome.org/librsvg/Rsvg-2.0/index.html>`_,
221 with `gi-docgen <https://gitlab.gnome.org/GNOME/gi-docgen>`_.
222 - `Rust API docs <https://gnome.pages.gitlab.gnome.org/librsvg/doc/rsvg/index.html>`_, with ``cargo doc``.
223 - `Internals docs <https://gnome.pages.gitlab.gnome.org/librsvg/internals/rsvg/index.html>`_, with ``cargo doc --document-private-items``.
224 - `This development guide <https://gnome.pages.gitlab.gnome.org/librsvg/devel-docs/index.html>`_, with ``sphinx``.
225