Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump lockfile version and drop support for older lockfiles #285

Merged
merged 3 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

### Changed

- Bump lockfile version to 0.3 (#285, @NathanReb)
- Mark packages to be pulled by opam-monorepo with the `vendor` variable so
using OPAM with `opam install --deps-only --locked .` will not install
packages that will be installed with `opam-monorepo pull` (#237,
Expand All @@ -38,6 +39,8 @@

### Removed

- Drop support for lockfile versions 0.2 and lower (#285, @NathanReb)

### Security

## 0.2.7
Expand Down
32 changes: 19 additions & 13 deletions lib/lockfile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ end
module Version = struct
type t = int * int

let current = (0, 2)
let compare (major, minor) (major', minor') =
match Ordering.of_int (Int.compare major major') with
| Eq -> Ordering.of_int (Int.compare minor minor')
| ordering -> ordering

let current = (0, 3)
let pp fmt (major, minor) = Format.fprintf fmt "%d.%d" major minor
let to_string (major, minor) = Printf.sprintf "%d.%d" major minor

Expand All @@ -35,19 +40,20 @@ module Version = struct
| Some major, Some minor -> Ok (major, minor)
| _ -> err ())

let backward_compatible (major, minor) (major', minor') =
major = major' && minor >= minor'

let compatible t =
(* We still support 0.1 lockfiles but we'll need to update that if we stop doing so *)
if backward_compatible current t then Ok ()
else
Error
(`Msg
(Format.asprintf
"Incompatible opam-monorepo lockfile version %a. Please upgrade \
your opam-monorepo plugin."
pp t))
match compare current t with
| Eq -> Ok ()
| Lt ->
Rresult.R.error_msgf
"Incompatible opam-monorepo lockfile version %a. Please upgrade your \
opam-monorepo plugin."
pp t
| Gt ->
Rresult.R.error_msgf
"opam-monorepo lockfile version %a is too old. Please regenerate the \
lockfile using your current opam-monorepo plugin or install an \
older version of the plugin."
pp t

let to_opam_value t = Opam.Value.String.to_value (to_string t)

Expand Down
8 changes: 8 additions & 0 deletions test/bin/lockfile-version.t/lockfile-version.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
opam-version: "2.0"
depends: [
"ocaml"
"dune"
]
x-opam-monorepo-opam-repositories: [
"file://$OPAM_MONOREPO_CWD/minimal-repo"
]
24 changes: 24 additions & 0 deletions test/bin/lockfile-version.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
We have a simple project with a single package that we will use to generate
a lockfile for our current version.

$ gen-minimal-repo
$ opam-monorepo lock > /dev/null
$ opam show --no-lint --raw -fx-opam-monorepo-version ./lockfile-version.opam.locked
"0.3"

This is our current version.
At the moment we are not backward compatible so if we downgrade this version number,
pull will refuse the lockfile and suggest it is regenerated with the current plugin:

$ sed -i "s/x-opam-monorepo-version: \"0.3\"/x-opam-monorepo-version: \"0.2\"/" lockfile-version.opam.locked
$ opam-monorepo pull > /dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you run pull in the happy path as well to make sure it doesn't result in an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately pull will require internet access, which it won't have in the CI.

opam-monorepo: [ERROR] opam-monorepo lockfile version 0.2 is too old. Please regenerate the lockfile using your current opam-monorepo plugin or install an older version of the plugin.
[1]

We also obviously do not support future versions and they should be rejected as well,
suggesting that the user upgrade their plugin to be able to interpret that lockfile:

$ sed -i "s/x-opam-monorepo-version: \"0.2\"/x-opam-monorepo-version: \"0.999\"/" lockfile-version.opam.locked
$ opam-monorepo pull > /dev/null
opam-monorepo: [ERROR] Incompatible opam-monorepo lockfile version 0.999. Please upgrade your opam-monorepo plugin.
[1]
2 changes: 1 addition & 1 deletion test/bin/simple-lock.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ The lockfile should contain the base packages, dune and our 2 dependencies
"file://$OPAM_MONOREPO_CWD/minimal-repo" "file://$OPAM_MONOREPO_CWD/repo"
]
x-opam-monorepo-root-packages: ["a"]
x-opam-monorepo-version: "0.2"
x-opam-monorepo-version: "0.3"