diff --git a/opam-ci-check/lib/lint.ml b/opam-ci-check/lib/lint.ml index ecf01c3..6759bf1 100644 --- a/opam-ci-check/lib/lint.ml +++ b/opam-ci-check/lib/lint.ml @@ -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 () = diff --git a/opam-ci-check/lib/lint_error.ml b/opam-ci-check/lib/lint_error.ml index da05616..3fb67f6 100644 --- a/opam-ci-check/lib/lint_error.ml +++ b/opam-ci-check/lib/lint_error.ml @@ -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 } -> @@ -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 diff --git a/opam-ci-check/test/lint.t b/opam-ci-check/test/lint.t index f5a9f07..2a7ae8f 100644 --- a/opam-ci-check/test/lint.t +++ b/opam-ci-check/test/lint.t @@ -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" @@ -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 @@ -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]