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

Add the push_if_no_changes keyword argument #27

Merged
merged 1 commit into from
Dec 3, 2020
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
7 changes: 6 additions & 1 deletion .github/workflows/BumpStdlibs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ on:
required: false
default: 'all'
BUMPSTDLIBS_CLOSE_OLD_PULL_REQUESTS:
description: 'Close old pull requests: (true/false)'
description: 'Close outdated pull requests: (true/false)'
required: false
default: 'true'
BUMPSTDLIBS_PUSH_IF_NO_CHANGES:
description: 'Push (and retrigger CI) even if there are no changes: (true/false)'
required: false
default: 'false'
jobs:
BumpStdlibs:
if: github.event_name == 'workflow_dispatch'
Expand All @@ -23,6 +27,7 @@ jobs:
- run: julia --color=yes --project -e 'using BumpStdlibs; bump_stdlibs("JuliaLang/julia")'
env:
BUMPSTDLIBS_CLOSE_OLD_PULL_REQUESTS: ${{ github.event.inputs.BUMPSTDLIBS_CLOSE_OLD_PULL_REQUESTS }}
BUMPSTDLIBS_PUSH_IF_NO_CHANGES: ${{ github.event.inputs.BUMPSTDLIBS_PUSH_IF_NO_CHANGES }}
BUMPSTDLIBS_STDLIBS_TO_INCLUDE: ${{ github.event.inputs.BUMPSTDLIBS_STDLIBS_TO_INCLUDE }}
BUMPSTDLIBS_TOKEN: ${{ secrets.BUMPSTDLIBS_TOKEN }}
JULIA_DEBUG: 'all'
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BumpStdlibs"
uuid = "10e0400f-8273-43d0-bd6e-07483373ba4f"
authors = ["Dilum Aluthge", "contributors"]
version = "2.0.0"
version = "3.0.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
13 changes: 12 additions & 1 deletion src/bump-stdlibs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,18 @@ function _bump_single_stdlib(stdlib::StdlibInfo, config::Config, state::State)
run(`git add stdlib/$(name).version`)
run(`bash -c "git add deps/checksums/$(name)-*"`)
run(`git commit -m "$(commit_message)"`)
run(`git push -f origin $(pr_branch)`)
do_push = true
if !(config.push_if_no_changes)
if pr_branch in get_origin_branches()
if git_diff_is_empty("HEAD", "origin/$(pr_branch)")
do_push = false
end
end
end
@info "" do_push
if do_push
run(`git push --force origin $(pr_branch)`)
end
whoami = GitHub.whoami(; auth = config.auth).login
pr_head_with_fork_owner = "$(whoami):$(pr_branch)"
pr_state = Dict{String, Any}(
Expand Down
4 changes: 4 additions & 0 deletions src/git.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ function delete_branches_with_prefix_on_origin_older_than(prefix::AbstractString
end
return nothing
end

function git_diff_is_empty(x::AbstractString, y::AbstractString)
return isempty(strip(read(`git diff $(x) $(y)`, String)))
end
27 changes: 14 additions & 13 deletions src/inputs.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const INPUTS = Dict{Symbol, Any}(
:auth => ("BUMPSTDLIBS_TOKEN", nothing),
:close_old_pull_requests => ("BUMPSTDLIBS_CLOSE_OLD_PULL_REQUESTS", "true"),
:push_if_no_changes => ("BUMPSTDLIBS_PUSH_IF_NO_CHANGES", "false"),
:stdlibs_to_include => ("BUMPSTDLIBS_STDLIBS_TO_INCLUDE", "all"),
)

function post_process_input(::Val, value)
return value
end

function post_process_input(::Val{:auth}, value)
return GitHub.authenticate(value)
end
Expand All @@ -12,32 +17,28 @@ function post_process_input(::Val{:close_old_pull_requests}, value)
return parse(Bool, value)
end

function post_process_input(::Val, value)
return value
function post_process_input(::Val{:push_if_no_changes}, value)
return parse(Bool, value)
end

function get_input_from_environment(input::Symbol,
env_var_name::Union{AbstractString, Nothing} = nothing)
if haskey(INPUTS, input)
default_env_var_name, default_value = INPUTS[input]
if env_var_name isa Nothing
_env_var_name = default_env_var_name
env_var_name_to_use = default_env_var_name
else
_env_var_name = env_var_name
env_var_name_to_use = env_var_name
end
if haskey(ENV, _env_var_name)
environment_variable_contents = strip(ENV[_env_var_name])
if isempty(environment_variable_contents)
throw(ArgumentError("The `$(_env_var_name)` environment variable is defined but empty."))
else
return post_process_input(Val(input), environment_variable_contents)
end
else
env_var_contents = strip(get(ENV, env_var_name_to_use, ""))
if isempty(env_var_contents)
if default_value isa Nothing
throw(ArgumentError("The `$(_env_var_name)` environment variable is not defined."))
throw(ArgumentError("Either the `$(_env_var_name)` environment variable is undefined, or it is defined but empty."))
else
return post_process_input(Val(input), default_value)
end
else
return post_process_input(Val(input), env_var_contents)
end
end
throw(ArgumentError("$(input) is not a valid input"))
Expand Down
7 changes: 4 additions & 3 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ Base.@kwdef struct StdlibInfo
current_shas::Dict{String, String}
end

Base.@kwdef struct Config{C1 <: GitHub.Authorization, C2 <: Bool, C3 <: Dates.AbstractTime, C4 <: AbstractString, C5 <: Union{AbstractString, Nothing}, C6 <: Union{AbstractString, AbstractVector{<:AbstractString}}}
Base.@kwdef struct Config{C1 <: GitHub.Authorization, C2 <: Bool, C3 <: Dates.AbstractTime, C4 <: AbstractString, C5 <: Bool, C6 <: Union{AbstractString, Nothing}, C7 <: Union{AbstractString, AbstractVector{<:AbstractString}}}
auth::C1 = get_input_from_environment(:auth)
close_old_pull_requests::C2 = get_input_from_environment(:close_old_pull_requests)
close_old_pull_requests_older_than::C3 = Dates.Minute(0)
pr_branch_suffix::C4 = ""
julia_repo_default_branch::C5 = nothing
stdlibs_to_include::C6 = get_input_from_environment(:stdlibs_to_include)
push_if_no_changes::C5 = get_input_from_environment(:push_if_no_changes)
julia_repo_default_branch::C6 = nothing
stdlibs_to_include::C7 = get_input_from_environment(:stdlibs_to_include)
end

Base.@kwdef struct State{S1 <: AbstractVector{<:AbstractString}, S2 <: GitHub.Repo, S3 <:AbstractString, S4 <: GitHub.Repo}
Expand Down
42 changes: 23 additions & 19 deletions test/integration-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,41 @@
julia_repo = "bcbi-test/julia"

global_kwargs = Dict(
:auth => BumpStdlibs.get_input_from_environment(:auth, "BUMPSTDLIBS_TOKEN_FOR_TESTS"),
:close_old_pull_requests => true,
:close_old_pull_requests_older_than => Dates.Minute(5),
:auth => BumpStdlibs.get_input_from_environment(:auth, "BUMPSTDLIBS_TOKEN_FOR_TESTS"),
:pr_branch_suffix => Random.randstring(4),
:push_if_no_changes => true,
:stdlibs_to_include => "Pkg",
)

@testset "all stdlibs" begin
result = bump_stdlibs(
julia_repo;
stdlibs_to_include = "all",
global_kwargs...
)
@test result isa Nothing
@testset "push_if_no_changes = true" begin
kwargs = deepcopy(global_kwargs)
kwargs[:push_if_no_changes] = true
kwargs[:stdlibs_to_include] = "all"
result = bump_stdlibs(julia_repo; kwargs...)
@test result isa Nothing
end
@testset "push_if_no_changes = false" begin
kwargs = deepcopy(global_kwargs)
kwargs[:push_if_no_changes] = false
kwargs[:stdlibs_to_include] = "all"
result = bump_stdlibs(julia_repo; kwargs...)
@test result isa Nothing
end
end

@testset "only specified stdlibs" begin
result = bump_stdlibs(
julia_repo;
stdlibs_to_include = "Pkg",
global_kwargs...
)
kwargs = deepcopy(global_kwargs)
result = bump_stdlibs(julia_repo; kwargs...)
@test result isa Nothing
end

@testset "Override the default branch" begin
result = bump_stdlibs(
julia_repo;
julia_repo_default_branch = "master",
stdlibs_to_include = "Pkg",
global_kwargs...
)
@testset "override the default branch" begin
kwargs = deepcopy(global_kwargs)
kwargs[:julia_repo_default_branch] = "master"
result = bump_stdlibs(julia_repo; kwargs...)
@test result isa Nothing
end
end