| 1 | Information for developers about the CI system |
| 2 | ---------------------------------------------- |
| 3 | |
| 4 | When you submit a pull request (PR) on the Rocq GitHub repository, this will |
| 5 | launch a battery of CI tests. The PR will not be integrated |
| 6 | unless these tests pass. |
| 7 | |
| 8 | We are currently running tests on the following platforms: |
| 9 | |
| 10 | - GitLab CI is the main CI platform. It tests the compilation of Rocq, |
| 11 | of the documentation, and of RocqIDE on Linux with several versions |
| 12 | of OCaml and with warnings as errors; it runs the test-suite and |
| 13 | tests the compilation of several external developments. It also runs |
| 14 | a linter that checks whitespace discipline. A [pre-commit |
| 15 | hook](../tools/pre-commit) is automatically installed by |
| 16 | `./configure`. It should allow complying with this discipline |
| 17 | without pain. |
| 18 | |
| 19 | - Github Actions are used to test the compilation of Rocq on Windows |
| 20 | and macOS. For Windows, the Rocq platform script is used, producing |
| 21 | an installer that can be used to test Rocq. |
| 22 | |
| 23 | You can anticipate the results of most of these tests prior to submitting your |
| 24 | PR by running GitLab CI on your private branches. To do so follow these steps: |
| 25 | |
| 26 | 1. Log into GitLab CI (the easiest way is to sign in with your GitHub account). |
| 27 | 2. Click on "New Project". |
| 28 | 3. Choose "CI / CD for external repository" then click on "GitHub". |
| 29 | 4. Find your fork of the Rocq repository and click on "Connect". |
| 30 | 5. If GitLab did not do so automatically, [enable the Container Registry](https://docs.gitlab.com/ee/user/project/container_registry.html#enable-the-container-registry-for-your-project). |
| 31 | 6. You are encouraged to go to the CI / CD general settings and increase the |
| 32 | timeout from 1h to 2h for better reliability. |
| 33 | |
| 34 | Now every time you push (including force-push unless you changed the default |
| 35 | GitLab setting) to your fork on GitHub, it will be synchronized on GitLab and |
| 36 | CI will be run. You will receive an e-mail with a report of the failures if |
| 37 | there are some. |
| 38 | |
| 39 | You can also run one CI target locally (using `make ci-somedev`). |
| 40 | If using `bash` interactively you can update environment variables to use the locally |
| 41 | built Rocq (i.e. setting PATH, OCAMLPATH etc) by sourcing `dev/ci/ci-env.sh`. |
| 42 | |
| 43 | See also [`test-suite/README.md`](../../test-suite/README.md) for information about adding new tests to the test-suite. |
| 44 | |
| 45 | ### Light and full CI |
| 46 | |
| 47 | By default, only a light CI is run, mostly testing only Rocq itself. |
| 48 | Before merging a PR, it must also pass full CI testing multiple third party |
| 49 | developments. See [`CONTRIBUTING.md`](../../CONTRIBUTING.md#understanding-automatic-feedback) |
| 50 | for more details. |
| 51 | |
| 52 | ### Breaking changes |
| 53 | |
| 54 | When your PR breaks external projects we test in our CI, you must: |
| 55 | |
| 56 | 1. Assess the breakage. |
| 57 | * If it is a bug your PR introduces, it should be fixed. |
| 58 | * Otherwise, you must assess the impact of the breakage and porting |
| 59 | effort required on a few CI entries that exercise the |
| 60 | functionality being changed. |
| 61 | 2. Some breakages can be accepted, for instance to remove something |
| 62 | already deprecated for long. Less obvious cases are to be |
| 63 | determined with the PR assignee and reviewers, or discussed |
| 64 | during a [weekly Call](https://github.com/rocq-prover/rocq/wiki/Rocq-Calls) |
| 65 | when doubts remain. |
| 66 | 3. For intentional breakages, you must then write porting instructions |
| 67 | (typically the PR changelog), based on your previous assesment. |
| 68 | For instance something like "ensuring compilation with Rocq X.Y and |
| 69 | option -w +thing-we-are-removing-deprecated". You can also offer a |
| 70 | script to help porting if you wish. |
| 71 | 4. The PR assignee will finally ask the project maintainers to prepare |
| 72 | a patch. For plugins, you must prepare yourself an overlay (you can |
| 73 | ask the CI project maintainer for help). Ultimately, for |
| 74 | non-plugin CI projects, the responsibility of preparing a patch |
| 75 | falls on the project maintainer, but PR writers are encouraged to |
| 76 | be helpful and may prepare patches themselves to facilitate a |
| 77 | smooth process of adaptation. To ask project maintainers to adapt |
| 78 | their development, the PR assignee can use the following template |
| 79 | |
| 80 | > @maintainer please update <dev>. You can do so by <instructions on how |
| 81 | > to update, typically the PR changelog entry> |
| 82 | > If <dev> is not updated in 7 days from now, it will be disabled in Rocq CI |
| 83 | > so as to not further delay the current PR (the project can be reenabled |
| 84 | > later, once fixed). In case you encounter |
| 85 | > unanticipated difficulties, please come back to us (for instance below) |
| 86 | > and feel free to request an extension. |
| 87 | |
| 88 | You can find the maintainers to ping in [ci-basic.sh](./ci-basic.sh). |
| 89 | |
| 90 | Of course, it's not in the interest of any developer to disable |
| 91 | large spans of the CI, so best efforts will be made, in |
| 92 | collaboration with the respective project maintainers to not |
| 93 | disable some projects, considered flagship projects, particularly |
| 94 | towards the base of the hierarchy. |
| 95 | |
| 96 | There is experimental support for |
| 97 | an improved workflow, see [the next |
| 98 | section](#experimental-automatic-overlay-creation-and-building), below |
| 99 | are the steps to manually prepare a patch: |
| 100 | |
| 101 | 1. Fork the external project, create a new branch, push a commit adapting |
| 102 | the project to your changes. |
| 103 | |
| 104 | We recommend that the commit message mention your PR's number and a |
| 105 | short explanation of what changed, eg |
| 106 | `Adapt to rocq-prover/rocq#XXXXX (changed order of arguments of foo)`. |
| 107 | |
| 108 | The explanation makes it possible to understand what's going on |
| 109 | without having to dereference github PR numbers. |
| 110 | |
| 111 | 2. Test your pull request with your adapted version of the external project by |
| 112 | adding an overlay file to your pull request (cf. |
| 113 | [`dev/ci/user-overlays/README.md`](user-overlays/README.md)). |
| 114 | 3. Fixes to external libraries (pure Rocq projects) *must* be backward |
| 115 | compatible (i.e. they should also work with the development version of Rocq, |
| 116 | and the latest stable version). This will allow you to open a PR on the |
| 117 | external project repository to have your changes merged *before* your PR on |
| 118 | Rocq can be integrated. |
| 119 | |
| 120 | On the other hand, patches to plugins (projects linking to the Rocq ML API) |
| 121 | can very rarely be made backward compatible and plugins we test will |
| 122 | generally have a dedicated branch per Rocq version. |
| 123 | You can still open a pull request but the merging will be requested by the |
| 124 | developer who merges the PR on Rocq. To avoid early merges of such PR, |
| 125 | which would break Rocq CI, it is recommended to keep them as draft PRs. |
| 126 | |
| 127 | Moreover, in case of user visible change, your PR must absolutely add |
| 128 | a changelog entry. See the README in [`doc/changelog`][user-changelog] |
| 129 | for how to add a changelog entry. |
| 130 | |
| 131 | ### Experimental automatic overlay creation and building |
| 132 | |
| 133 | If you break external projects that are hosted on GitHub, you can use |
| 134 | the `create_overlays.sh` script to automatically perform most of the |
| 135 | above steps. In order to do so: |
| 136 | |
| 137 | - determine the list of failing projects: |
| 138 | IDs can be found as ci-XXX1 ci-XXX2 ci-XXX3 in the list of GitLab CI failures; |
| 139 | - for each project XXXi, look in [ci-basic-overlay.sh](https://github.com/rocq-prover/rocq/blob/master/dev/ci/ci-basic-overlay.sh) |
| 140 | to see if the corresponding `XXXi_CI_GITURL` is hosted on GitHub; |
| 141 | - log on GitHub and fork all the XXXi projects hosted there; |
| 142 | - call the script as: |
| 143 | |
| 144 | ``` |
| 145 | ./dev/tools/create_overlays.sh ejgallego 9873 XXX1 XXX2 XXX3 |
| 146 | ``` |
| 147 | |
| 148 | replacing `ejgallego` by your GitHub nickname, `9873` by the actual PR |
| 149 | number, and selecting the XXXi hosted on GitHub. The script will: |
| 150 | |
| 151 | + checkout the contributions and prepare the branch/remote so you can |
| 152 | just commit the fixes and push, |
| 153 | + add the corresponding overlay file in `dev/ci/user-overlays`; |
| 154 | |
| 155 | - go to `_build_ci/XXXi` to prepare your overlay |
| 156 | (you can test your modifications by using `make -C ../.. ci-XXXi`) |
| 157 | and push using `git push ejgallego` (replacing `ejgallego` by your GitHub nickname); |
| 158 | - finally push the `dev/ci/user-overlays/9873-elgallego-YYY.sh` file on your Rocq fork |
| 159 | (replacing `9873` by the actual PR number, and `ejgallego` by your GitHub nickname). |
| 160 | |
| 161 | For problems related to ML-plugins, if you use `dune build` to build |
| 162 | Rocq, it will actually be aware of the broken contributions and perform |
| 163 | a global build. This is very convenient when using `merlin` as you |
| 164 | will get a coherent view of all the broken plugins, with full |
| 165 | incremental cross-project rebuild. |
| 166 | |
| 167 | Advanced GitLab CI information |
| 168 | ------------------------------ |
| 169 | |
| 170 | GitLab CI is set up to use the "build artifact" feature to avoid |
| 171 | rebuilding Rocq. In one job, Rocq is built with `./configure -relocatable` |
| 172 | and `dune install --prefix=$(pwd)/_install_ci` is run, then the `_install_ci` directory |
| 173 | persists to and is used by the next jobs. |
| 174 | |
| 175 | ### Artifacts |
| 176 | |
| 177 | Build artifacts from GitLab can be linked / downloaded in a systematic |
| 178 | way, see [GitLab's documentation](https://docs.gitlab.com/ce/user/project/pipelines/job_artifacts.html#downloading-the-latest-job-artifacts) |
| 179 | for more information. For example, to access the documentation of the |
| 180 | `master` branch, you can do: |
| 181 | |
| 182 | https://gitlab.com/rocq-prover/rocq/-/jobs/artifacts/master/file/_install_ci/share/doc/coq/sphinx/html/index.html?job=doc:refman |
| 183 | |
| 184 | Browsing artifacts is also possible: |
| 185 | https://gitlab.com/rocq-prover/rocq/-/jobs/artifacts/master/browse/_install_ci/?job=build:base |
| 186 | |
| 187 | Above, you can replace `master` and `job` by the desired GitLab branch and job name. |
| 188 | |
| 189 | Currently available artifacts are: |
| 190 | |
| 191 | - the Rocq executables and stdlib, in four copies varying in |
| 192 | architecture and OCaml version used to build Rocq: |
| 193 | https://gitlab.com/rocq-prover/rocq/-/jobs/artifacts/master/browse/_install_ci/?job=build:base |
| 194 | |
| 195 | Additionally, an experimental Dune build is provided: |
| 196 | https://gitlab.com/rocq-prover/rocq/-/jobs/artifacts/master/browse/_build/?job=build:edge:dune:dev |
| 197 | |
| 198 | - the Rocq documentation, built in the `doc:*` jobs. When submitting a |
| 199 | documentation PR, this can help reviewers checking the rendered |
| 200 | result. **@coqbot** will automatically post links to these |
| 201 | artifacts in the PR checks section. Furthermore, these artifacts are |
| 202 | automatically deployed at: |
| 203 | |
| 204 | + Rocq's Reference Manual [master branch]: |
| 205 | <https://coq.github.io/doc/master/refman/> |
| 206 | + Rocq's Standard Library Documentation [master branch]: |
| 207 | <https://coq.github.io/doc/master/stdlib/> |
| 208 | + Rocq's ML API Documentation [master branch]: |
| 209 | <https://coq.github.io/doc/master/api/> |
| 210 | |
| 211 | ### GitLab and Docker |
| 212 | |
| 213 | System and opam packages are installed in a Docker image. The image is |
| 214 | automatically built and uploaded to your GitLab registry, and is |
| 215 | loaded by subsequent jobs. |
| 216 | |
| 217 | **IMPORTANT**: When updating Rocq's CI docker image, you must modify |
| 218 | the `CACHEKEY` variable in [`.gitlab-ci.yml`](../../.gitlab-ci.yml) |
| 219 | (see comment near it for details). |
| 220 | |
| 221 | The Docker building job reuses the uploaded image if it is available, |
| 222 | but if you wish to save more time you can skip the job by setting |
| 223 | `SKIP_DOCKER` to `true`. |
| 224 | |
| 225 | In the case of the main Rocq repository, this variable is set to true |
| 226 | by default, but coqbot will set it to `false` anytime a PR modifies a |
| 227 | path matching `dev/ci/docker/.*Dockerfile.*`. |
| 228 | |
| 229 | See also [`docker/README.md`](docker/README.md). |