Skip to content

Commit

Permalink
Add lint checks for x-opam-repository-commit-hash-at-time-of-archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
shonfeder committed Jan 1, 2025
1 parent ebb8727 commit 2e6794f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
10 changes: 7 additions & 3 deletions opam-ci-check/lib/lint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,13 @@ module Checks = struct
| List {pelem = (_::_ as reasons); _} when List.for_all is_valid_reason reasons -> []
| _ -> [(pkg, InvalidReasonForArchiving)]


let x_opam_repository_commit_hash_at_time_of_archival ~pkg:_ _opam =
[] (* TODO *)
let x_opam_repository_commit_hash_at_time_of_archival ~pkg opam =
opam
|> OpamFile.OPAM.extensions
|> OpamStd.String.Map.find_opt x_opam_repository_commit_hash_at_time_of_archiving_field
|> function
| Some {pelem = String _; _} -> []
| _ -> [(pkg, InvalidOpamRepositoryCommitHash)]

let checks kinds ~newly_published ~opam_repo_dir ~pkg_src_dir repo_package_names =
let general_opam_file_checks () =
Expand Down
11 changes: 10 additions & 1 deletion opam-ci-check/lib/lint_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ type error =
| DefaultTagsPresent of string list
| MissingUpperBound of string
| InvalidReasonForArchiving
| InvalidOpamRepositoryCommitHash

(**/**)

(* These x_ fields are used in the opam repo archive *)
let x_reason_for_archiving_field = "x-reason-for-archiving"
(* Used in the opam repo archive *)
let x_reason_for_archiving_valid_reasons =
["ocaml-version"; "source-unavailable"; "maintenance-intent"; "uninstallable" ]
let x_opam_repository_commit_hash_at_time_of_archiving_field =
"x-opam-repository-commit-hash-at-time-of-archiving"

let msg_of_prefix_conflict_class_mismatch ~pkg = function
| WrongPrefix { conflict_class; required_prefix } ->
Expand Down Expand Up @@ -180,3 +183,9 @@ let msg_of_error (package, (err : error)) =
of one or more of the valid reasons %s"
pkg x_reason_for_archiving_field
(String.concat ", " x_reason_for_archiving_valid_reasons)
| InvalidOpamRepositoryCommitHash ->
Printf.sprintf
"Error in %s: The field '%s' must be present and hold a string \
recording the commit hash of the primary repo at the time the package \
version is archived."
pkg x_opam_repository_commit_hash_at_time_of_archiving_field
40 changes: 39 additions & 1 deletion opam-ci-check/test/lint.t
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ https://github.com/ocaml/opam-repository/blob/master/governance/policies/archivi
Test that we do not report an error on a minimal well-formed package:
$ echo 'x-reason-for-archiving: [ "source-unavailable" ]' >> packages/a-1/a-1.0.0.1/opam
$ echo 'x-reason-for-archiving: [ "source-unavailable" ]' \
> >> packages/a-1/a-1.0.0.1/opam
$ echo 'x-opam-repository-commit-hash-at-time-of-archiving: "de786e28dbea73843ad5e5f0290a4e81fba39370"' \
> >> packages/a-1/a-1.0.0.1/opam
$ cat packages/a-1/a-1.0.0.1/opam
opam-version: "2.0"
synopsis: "Synopsis"
Expand All @@ -378,6 +381,7 @@ Test that we do not report an error on a minimal well-formed package:
build: []
depends: []
x-reason-for-archiving: [ "source-unavailable" ]
x-opam-repository-commit-hash-at-time-of-archiving: "de786e28dbea73843ad5e5f0290a4e81fba39370"
$ opam-ci-check lint -r . --check=archive-repo a-1.0.0.1
Linting opam-repository at $TESTCASE_ROOT/. ...
No errors
Expand Down Expand Up @@ -461,3 +465,37 @@ Test we report an error when the x-reason-for-archiving has an invalid reason:
Linting opam-repository at $TESTCASE_ROOT/. ...
Error in a-1.0.0.1: The field 'x-reason-for-archiving' must be present and hold a nonempty list of one or more of the valid reasons ocaml-version, source-unavailable, maintenance-intent, uninstallable
[1]
Test we do NOT report an error when the x-reason-for-archiving has multiple invalid reasons:
$ sed \
> -e 's/x-reason-for-archiving:.*/x-reason-for-archiving: ["source-unavailable" "maintenance-intent"]/' \
> packages/a-1/a-1.0.0.1/opam > opam.new
$ mv opam.new packages/a-1/a-1.0.0.1/opam
$ opam-ci-check lint -r . --check=archive-repo a-1.0.0.1
Linting opam-repository at $TESTCASE_ROOT/. ...
No errors
# x-opam-repository-commit-hash-at-time-of-archiving checks
Test we report an error when the x-opam-repository-commit-hash-at-time-of-archiving
is missing:
$ sed \
> -e '/x-opam-repository-commit-hash-at-time-of-archiving/d' \
> packages/a-1/a-1.0.0.1/opam > opam.new
$ mv opam.new packages/a-1/a-1.0.0.1/opam
$ opam-ci-check lint -r . --check=archive-repo a-1.0.0.1
Linting opam-repository at $TESTCASE_ROOT/. ...
Error in a-1.0.0.1: The field 'x-opam-repository-commit-hash-at-time-of-archiving' must be present and hold a string recording the commit hash of the primary repo at the time the package version is archived.
[1]
Test we report an error when the x-opam-repository-commit-hash-at-time-of-archiving
has an invald value:
$ echo 'x-opam-repository-commit-hash-at-time-of-archiving: false' \
> >> packages/a-1/a-1.0.0.1/opam
$ opam-ci-check lint -r . --check=archive-repo a-1.0.0.1
Linting opam-repository at $TESTCASE_ROOT/. ...
Error in a-1.0.0.1: The field 'x-opam-repository-commit-hash-at-time-of-archiving' must be present and hold a string recording the commit hash of the primary repo at the time the package version is archived.
[1]

0 comments on commit 2e6794f

Please sign in to comment.