Skip to content

Commit

Permalink
Try #358:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Jul 22, 2021
2 parents 8356597 + 7c5c905 commit 82e5bf6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function main(
include_jll::Bool=false,
unsub_from_prs=false,
cc_user=false,
bump_version=false,
)
api, repo = get_api_and_repo(ci_cfg)

Expand Down Expand Up @@ -44,6 +45,7 @@ function main(
pr_title_prefix=pr_title_prefix,
unsub_from_prs=unsub_from_prs,
cc_user=cc_user,
bump_version=bump_version,
)
end
end
Expand Down
45 changes: 41 additions & 4 deletions src/utilities/new_versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function make_pr_for_new_version(
pr_title_prefix::String="",
unsub_from_prs=false,
cc_user=false,
bump_version=false,
)
if !continue_with_pr(dep, bump_compat_containing_equality_specifier)
return nothing
Expand Down Expand Up @@ -273,11 +274,13 @@ function make_pr_for_new_version(
new_branch_name = "compathelper/new_version/$(get_random_string())"
git_branch(new_branch_name; checkout=true)

# Add new compat entry to project.toml and write it out
add_compat_entry(
# Add new compat entry to project.toml, bump the version if needed,
# and write it out
modify_project_toml(
dep.package.name,
joinpath(tmpdir, LOCAL_REPO_NAME, subdir),
brand_new_compat,
bump_version,
)
git_add()

Expand Down Expand Up @@ -338,22 +341,56 @@ function unsub_from_pr(api::GitLab.GitLabAPI, pr::GitLab.MergeRequest)
return @mock GitForge.unsubscribe_from_pull_request(api, pr.project_id, pr.iid)
end

function add_compat_entry(
name::AbstractString, repo_path::AbstractString, brand_new_compat::AbstractString
function modify_project_toml(
name::AbstractString,
repo_path::AbstractString,
brand_new_compat::AbstractString,
bump_version::Bool,
)
# Open up Project.toml
project_file = joinpath(repo_path, "Project.toml")
project = TOML.parsefile(project_file)

# Add the new compat
add_compat_section!(project)
project["compat"][name] = brand_new_compat

# Bump the version if specified
bump_version && bump_package_version!(project)

# Write the file back out
open(project_file, "w") do io
TOML.print(
io, project; sorted=true, by=key -> (Pkg.Types.project_key_order(key), key)
)
end
end

function bump_package_version!(project::Dict)
version = VersionNumber(project["version"])

# Only bump the version if prerelease is empty
!isempty(version.prerelease) && return nothing

# Bump minor if version > 1.0, else bump patch
if version.major >= 1
version = VersionNumber(
version.major, version.minor + 1, 0, version.prerelease, version.build
)
else
version = VersionNumber(
version.major,
version.minor,
version.patch + 1,
version.prerelease,
version.build
)
end

project["version"] = string(version)
return project
end

function create_ssh_private_key(dir::AbstractString; env=ENV)
run(`chmod 700 $dir`)
pkey_filename = joinpath(dir, "privatekey")
Expand Down
30 changes: 28 additions & 2 deletions test/utilities/new_versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ end
end
end

@testset "add_compat_entry" begin
@testset "modify_project_toml" begin
mktempdir() do tmpdir
# Lets copy our test Project.toml to the tmpdir for this test
src = joinpath(@__DIR__, "..", "deps", "Project.toml")
Expand All @@ -259,13 +259,39 @@ end
project = TOML.parsefile(dst)
@test !haskey(project["compat"], "PackageA")

CompatHelper.add_compat_entry("PackageA", tmpdir, "= 1.2")
CompatHelper.modify_project_toml("PackageA", tmpdir, "= 1.2", false)

project = TOML.parsefile(dst)
@test project["compat"]["PackageA"] == "= 1.2"
end
end

@testset "bump_package_version" begin
@testset "minor bump" begin
mock_toml = Dict("version" => "1.4.5")

@test mock_toml["version"] == "1.4.5"
CompatHelper.bump_package_version!(mock_toml)
@test mock_toml["version"] == "1.5.0"
end

@testset "patch bump" begin
mock_toml = Dict("version" => "0.5.2")

@test mock_toml["version"] == "0.5.2"
CompatHelper.bump_package_version!(mock_toml)
@test mock_toml["version"] == "0.5.3"
end

@testset "dev prerelease" begin
mock_toml = Dict("version" => "1.2.3-DEV")

@test mock_toml["version"] == "1.2.3-DEV"
CompatHelper.bump_package_version!(mock_toml)
@test mock_toml["version"] == "1.2.3-DEV"
end
end

@testset "cc_mention_user" begin
@testset "GitHub" begin
apply(gh_comment_patch) do
Expand Down

0 comments on commit 82e5bf6

Please sign in to comment.