Skip to content

Commit

Permalink
Correctly handle an edge case in the sequential version check (#563)
Browse files Browse the repository at this point in the history
* Add the `ErrorCannotComputeVersionDifference` struct

* Allow `difference(x, y)` to return an `ErrorCannotComputeVersionDifference` (instead of throwing an exception)

* Add a message field to `ErrorCannotComputeVersionDifference`

* `_valid_change()`: correctly handle `ErrorCannotComputeVersionDifference`

* Patch bump: bump from 10.3.0 to 10.3.1

* Fix two unit tests
  • Loading branch information
DilumAluthge authored Jun 13, 2024
1 parent 86cdd37 commit e4bb3ad
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RegistryCI"
uuid = "0c95cc5f-2f7e-43fe-82dd-79dbcba86b32"
authors = ["Dilum Aluthge <dilum@aluthge.com>", "Fredrik Ekre <ekrefredrik@gmail.com>", "contributors"]
version = "10.3.0"
version = "10.3.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
10 changes: 10 additions & 0 deletions src/AutoMerge/guidelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@ end

function _valid_change(old_version::VersionNumber, new_version::VersionNumber)
diff = difference(old_version, new_version)
if !(diff isa VersionNumber)
if diff isa ErrorCannotComputeVersionDifference
old_msg = diff.msg
else
T = typeof(diff)
old_msg = "Unknown diff type: $(T)"
end
new_msg = "Error occured while trying to compute version bump. Message: $(old_msg)"
return _invalid_sequential_version(new_msg)
end
@debug("Difference between versions: ", old_version, new_version, diff)
if diff == v"0.0.1"
return true, "", :patch
Expand Down
6 changes: 3 additions & 3 deletions src/AutoMerge/semver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ function difference(x::VersionNumber, y::VersionNumber)
elseif y.patch > x.patch
return VersionNumber(y.major - x.major, y.minor - x.minor, y.patch - x.patch)
else
throw(
ArgumentError("first argument must be strictly less than the second argument")
)
msg = "first argument $(x) must be strictly less than the second argument $(y)"
@warn msg x y
return ErrorCannotComputeVersionDifference(msg)
end
end

Expand Down
4 changes: 4 additions & 0 deletions src/AutoMerge/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ struct AutoMergeWrongBuildType <: AutoMergeException
msg::String
end

struct ErrorCannotComputeVersionDifference
msg::String
end

struct GitHubAutoMergeData
# Handle to the GitHub API. Used to query the PR and update
# comments and status.
Expand Down
4 changes: 2 additions & 2 deletions test/automerge-unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ end
@test AutoMerge.nextmajor(v"1.2") == v"2"
@test AutoMerge.nextmajor(v"1.2.3") == v"2"
@test AutoMerge.difference(v"1", v"2") == v"1"
@test_throws ArgumentError AutoMerge.difference(v"1", v"1")
@test_throws ArgumentError AutoMerge.difference(v"2", v"1")
@test AutoMerge.difference(v"1", v"1") isa AutoMerge.ErrorCannotComputeVersionDifference
@test AutoMerge.difference(v"2", v"1") isa AutoMerge.ErrorCannotComputeVersionDifference
@test !AutoMerge._has_upper_bound(Pkg.Types.VersionRange("0"))
@test AutoMerge._has_upper_bound(Pkg.Types.VersionRange("1"))
@test !AutoMerge._has_upper_bound(Pkg.Types.VersionRange("*"))
Expand Down

2 comments on commit e4bb3ad

@DilumAluthge
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/108941

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v10.3.1 -m "<description of version>" e4bb3ad236f66b626eb6b4ec8bcaf2b3b3e0246d
git push origin v10.3.1

Please sign in to comment.