Skip to content

Commit

Permalink
Gracefully handle deleted packages in analysis
Browse files Browse the repository at this point in the history
Previously, the analysis phase didn't expect any package deletions. So,
we'd fail with the error "impossible". But, with the new opam-repository
archival process, we allow for deletions, even though only in the
special case of a package being archived.
  • Loading branch information
punchagan committed Dec 17, 2024
1 parent fabac09 commit 906d7d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/analyse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,12 @@ module Analysis = struct
Fpath.v "packages" // name // (name^"."^version) // "opam"

let add_package_data ~dir (pkg, kind) packages =
match packages with
| Error _ as err -> Lwt.return err
| Ok packages ->
match (packages, kind) with
| Error _ as err, _ ->
Lwt.return err
| Ok packages, Deleted ->
Lwt.return_ok ((pkg, {kind; has_tests = false}) :: packages)
| Ok packages, _ ->
let open Lwt_result.Syntax in
let path = Fpath.to_string (package_to_path pkg) in
let* content = get_opam ~cwd:dir path |> Lwt_result.map_error (fun _ -> `Msg "impossible") in
Expand Down
4 changes: 3 additions & 1 deletion lib/lint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ module Check = struct
let new_arg = match change with
| Analyse.Analysis.(New Package) -> Some "true"
| Analyse.Analysis.(New Release | Unavailable | SignificantlyChanged | InsignificantlyChanged ) -> Some "false"
| Deleted -> None
| Deleted ->
Current.Job.log job "Skipping deleted package: %s" (OpamPackage.to_string pkg);
None
in
Option.map (Printf.sprintf "%s:new=%s" pkg_str) new_arg)
in
Expand Down
6 changes: 5 additions & 1 deletion test/analyse.t
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ Test deleting existing packages works
* a-1.0.0.1 removed (HEAD -> new-branch-2)
* a-1 (tag: initial-state, new-branch-1, master)
$ opam-repo-ci-local --repo="." --branch=new-branch-2 --analyse-only --no-web-server
Error "impossible"
{
"packages": [
[ "a-1.0.0.1", { "kind": [ "Deleted" ], "has_tests": false } ]
]
}

Clean up the build cache

Expand Down

0 comments on commit 906d7d7

Please sign in to comment.