Skip to content

CI: check license header of new OCaml files

Arvid Jakobsson requested to merge arvid@check-license into master

Context

Checks that new .ml(i) files have a MIT-SPDX header.

License checking

This MR adds an OCaml script scripts/check_license/main.ml that checks whether a given set of OCaml source files has at least one of a given set of acceptable license headers. Currently, I've implemented checks for the following headers:

  • --mit-spdx-deprecated: MIT license header with spdx identifier, as mandated by our current coding guidlines. it's marked deprecated in anticipation of !10140 (merged)
  • --mit-spdx: MIT license header with spdx identifier, as mandated by our forthcmoing coding guidlines in !10140 (merged).
  • --mit: full-text version of the MIT license header, mentioned as a deprected alternativ our coding guidlines and used through out the code base.
  • --mit-os: a version of the MIT license header that we seem to be using, where line MIT License is replaced with Open Source License.

Note also that I do not attempt to verify the contents of the

(* Copyright (c) [year(s)] [Holder <email>]                                  *)

lines: I only check that at least one such line exists following the (approximate) regexp (\* Copyright (c) .* \*).

Integration in the CI

The integration in the CI, in the job misc_checks verifies that all new .ml(i) files in a given MR have the --mit-spdx header.

Follow-ups

Exercises for further improvements, out of scope in this MR, include: adding more licenses, adding exceptions, transforming old licenses, verifying that the Copyright (c) lines correspond to something...

Manually testing the MR

ocaml scripts/check_license/main.ml --help

To check the header of the script itself, run:

ocaml scripts/check_license/main.ml --mit-spdx scripts/check_license/main.ml

To try it on a bunch of files in the repo:

find src -iname \*.ml\* | head -n 20 | xargs ocaml scripts/check_license/main.ml --verbose

Note: this only checks the first 20 files. If you increase the number of files checked, you will soon find .ml(i) files that have license headers that are not accepted by the tools. When I discovered the variety of headers we have, I decided to only concentrate on making new files follow the implemented --mit-spdx header.

To test in the CI, see MR !10363 (closed) and feel free to push commits there.

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
Edited by Arvid Jakobsson

Merge request reports