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 Version of Package #358

Merged
merged 2 commits into from
Jul 28, 2021
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
2 changes: 2 additions & 0 deletions src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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, hostname_for_api)

Expand All @@ -42,6 +43,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 @@ -217,6 +217,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 @@ -274,11 +275,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 @@ -339,22 +342,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
mattBrzezinski marked this conversation as resolved.
Show resolved Hide resolved
)
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 @@ -245,7 +245,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 @@ -255,13 +255,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