From 4e2b021e489b7502f7bd251f798ad9e85d4eb2c2 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Mon, 29 Mar 2021 22:09:42 -0400 Subject: [PATCH 1/9] Add the `force_latest_compatible_version` input, and add the "auto-detect Dependabot/CompatHelper" functionality --- action.yml | 26 +++++++++++++++++--------- autodetect-dependabot.jl | 29 +++++++++++++++++++++++++++++ kwargs.jl | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 autodetect-dependabot.jl create mode 100644 kwargs.jl diff --git a/action.yml b/action.yml index 8188b93..7553d3f 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: depwarn: description: 'Value passed to the --depwarn flag. Options: yes | no | error. Default value: yes.' default: 'yes' + force_latest_compatible_version: + description: 'If true, then, for each `[compat]` entry in the active project, only the latest compatible version will be allowed. Options: true | false | auto. Default value: auto. If the value is auto, then force_latest_compatible_version will be set to true if this is a Dependabot/CompatHelper pull request, and false otherwise.' + default: 'auto' inline: description: 'Value passed to the --inline flag. Options: yes | no. Default value: yes.' default: 'yes' @@ -44,13 +47,18 @@ runs: # packages via `Pkg.test`. JULIA_PKG_SERVER: "" - run: | - # The Julia command that will be executed - julia_cmd=( julia --color=yes --check-bounds=yes --inline=${{ inputs.inline }} --depwarn=${{ inputs.depwarn }} --project=${{ inputs.project }} -e 'using Pkg; Pkg.test(coverage=${{ inputs.coverage }})' ) - - # Add the prefix in front of the command if there is one - prefix="${{ inputs.prefix }}" - [[ -n $prefix ]] && julia_cmd=( "$prefix" "${julia_cmd[@]}" ) - - # Run the Julia command - "${julia_cmd[@]}" + JULIA_CMD="julia" + PREFIX="${{ inputs.prefix }}" + [[ -n $PREFIX ]] && JULIA_CMD="$PREFIX $JULIA_CMD" + echo "JULIA_CMD=$JULIA_CMD" >> $GITHUB_ENV + shell: bash + - run: | + ${{ env.JULIA_CMD }} --check-bounds=yes --color=yes --depwarn=${{ inputs.depwarn }} --inline=${{ inputs.inline }} --project=${{ inputs.project }} -e ' + import Pkg + include(joinpath(ENV["GITHUB_ACTION_PATH"], "kwargs.jl")) + kwargs = Kwargs.kwargs(; + coverage = :(${{ inputs.coverage }}), + force_latest_compatible_version = :(${{ inputs.force_latest_compatible_version }}), + ) + Pkg.test(; kwargs...)' shell: bash diff --git a/autodetect-dependabot.jl b/autodetect-dependabot.jl new file mode 100644 index 0000000..c9575ed --- /dev/null +++ b/autodetect-dependabot.jl @@ -0,0 +1,29 @@ +module AutodetectDependabot + +function _get_possible_branch_names() + possible_branch_names = [ + get(ENV, "GITHUB_BASE_REF", ""), + get(ENV, "GITHUB_HEAD_REF", ""), + get(ENV, "GITHUB_REF", ""), + ] + return possible_branch_names +end + +function _chop_refs_head(branch_name::AbstractString) + if startswith(branch_name, "refs/heads/") + return replace(branch_name, r"^(refs\/heads\/)" => "") + else + return branch_name + end +end + +function _is_dependabot_branch(branch_name::AbstractString) + return startswith(branch_name, "dependabot/julia") || startswith(branch_name, "compathelper/") +end + +function is_dependabot_job() + possible_branch_names = _get_possible_branch_names() + return any(_is_dependabot_branch.(_chop_refs_head.(possible_branch_names))) +end + +end # module diff --git a/kwargs.jl b/kwargs.jl new file mode 100644 index 0000000..115bd0f --- /dev/null +++ b/kwargs.jl @@ -0,0 +1,37 @@ +module Kwargs + +include(joinpath(@__DIR__, "autodetect-dependabot.jl")) + +function kwargs(; coverage::Bool, + force_latest_compatible_version::Union{Bool, Symbol}) + is_dependabot_job = AutodetectDependabot.is_dependabot_job() + kwargs_dict = Dict{Symbol, Any}() + kwargs_dict[:coverage] = coverage + + if !Sys.isapple() && VERSION >= v"1.7.0-" # TODO: delete this line + # if VERSION >= v"1.7.0-" # excludes 1.6, includes 1.7-DEV, includes 1.7 # TODO: uncomment this line + if force_latest_compatible_version isa Bool + kwargs_dict[:force_latest_compatible_version] = force_latest_compatible_version + elseif force_latest_compatible_version == :auto + if is_dependabot_job + @info("This is a Dependabot/CompatHelper job, so `force_latest_compatible_version` has been set to `true`") + kwargs_dict[:force_latest_compatible_version] = true + else + kwargs_dict[:force_latest_compatible_version] = false + end + else + throw(ArgumentError("Invalid value for force_latest_compatible_version: $(force_latest_compatible_version)")) + end + else + if force_latest_compatible_version != :auto + @warn( + "The `force_latest_compatible_version` option requires at least Julia 1.7", + VERSION, + force_latest_compatible_version, + ) + end + end + return kwargs_dict +end + +end # module From 790be2f421a8724fdfbea09c61517ba04d45efbe Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 30 Mar 2021 19:52:46 -0400 Subject: [PATCH 2/9] Apply suggestions from code review Co-authored-by: Sascha Mann --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7553d3f..0a0c5f0 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: description: 'Value passed to the --depwarn flag. Options: yes | no | error. Default value: yes.' default: 'yes' force_latest_compatible_version: - description: 'If true, then, for each `[compat]` entry in the active project, only the latest compatible version will be allowed. Options: true | false | auto. Default value: auto. If the value is auto, then force_latest_compatible_version will be set to true if this is a Dependabot/CompatHelper pull request, and false otherwise.' + description: 'If true, then, for each [compat] entry in the active project, only allow the latest compatible version. If the value is auto and the pull request has been opened by Dependabot or CompatHelper, then force_latest_compatible_version will be set to true, otherwise it will be set to false. Options: true | false | auto. Default value: auto.' default: 'auto' inline: description: 'Value passed to the --inline flag. Options: yes | no. Default value: yes.' From dd8c4ad62f39dc166915a33a1ec6888c2d2f9988 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 30 Mar 2021 19:53:19 -0400 Subject: [PATCH 3/9] Apply suggestions from code review Co-authored-by: Sascha Mann --- autodetect-dependabot.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/autodetect-dependabot.jl b/autodetect-dependabot.jl index c9575ed..5c4d6ab 100644 --- a/autodetect-dependabot.jl +++ b/autodetect-dependabot.jl @@ -10,11 +10,7 @@ function _get_possible_branch_names() end function _chop_refs_head(branch_name::AbstractString) - if startswith(branch_name, "refs/heads/") - return replace(branch_name, r"^(refs\/heads\/)" => "") - else - return branch_name - end + replace(branch_name, r"^(refs\/heads\/)" => "") end function _is_dependabot_branch(branch_name::AbstractString) From 770d1414f05b89f2a5ba4239bfeaad4a0a3ca3c4 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 30 Mar 2021 19:55:03 -0400 Subject: [PATCH 4/9] Apply suggestions from code review Co-authored-by: Sascha Mann --- kwargs.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kwargs.jl b/kwargs.jl index 115bd0f..0514269 100644 --- a/kwargs.jl +++ b/kwargs.jl @@ -24,11 +24,7 @@ function kwargs(; coverage::Bool, end else if force_latest_compatible_version != :auto - @warn( - "The `force_latest_compatible_version` option requires at least Julia 1.7", - VERSION, - force_latest_compatible_version, - ) + @warn("The `force_latest_compatible_version` option requires at least Julia 1.7", VERSION, force_latest_compatible_version) end end return kwargs_dict From d928f49db56ed18f151faaf81c153896fc6f0835 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 30 Mar 2021 19:55:58 -0400 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Sascha Mann --- kwargs.jl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kwargs.jl b/kwargs.jl index 0514269..2a34896 100644 --- a/kwargs.jl +++ b/kwargs.jl @@ -13,12 +13,8 @@ function kwargs(; coverage::Bool, if force_latest_compatible_version isa Bool kwargs_dict[:force_latest_compatible_version] = force_latest_compatible_version elseif force_latest_compatible_version == :auto - if is_dependabot_job - @info("This is a Dependabot/CompatHelper job, so `force_latest_compatible_version` has been set to `true`") - kwargs_dict[:force_latest_compatible_version] = true - else - kwargs_dict[:force_latest_compatible_version] = false - end + is_dependabot_job && @info("This is a Dependabot/CompatHelper job, so `force_latest_compatible_version` has been set to `true`") + kwargs_dict[:force_latest_compatible_version] = is_dependabot_job else throw(ArgumentError("Invalid value for force_latest_compatible_version: $(force_latest_compatible_version)")) end From 9be550baaf6735b8ad224311ed7f1c513a179c68 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 30 Mar 2021 20:01:06 -0400 Subject: [PATCH 6/9] Update kwargs.jl --- kwargs.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kwargs.jl b/kwargs.jl index 2a34896..a2f15bf 100644 --- a/kwargs.jl +++ b/kwargs.jl @@ -8,8 +8,7 @@ function kwargs(; coverage::Bool, kwargs_dict = Dict{Symbol, Any}() kwargs_dict[:coverage] = coverage - if !Sys.isapple() && VERSION >= v"1.7.0-" # TODO: delete this line - # if VERSION >= v"1.7.0-" # excludes 1.6, includes 1.7-DEV, includes 1.7 # TODO: uncomment this line + if VERSION >= v"1.7.0-" # excludes 1.6, includes 1.7-DEV, includes 1.7 if force_latest_compatible_version isa Bool kwargs_dict[:force_latest_compatible_version] = force_latest_compatible_version elseif force_latest_compatible_version == :auto From 78c6039ef2f66a7eed1a234e61e2f63d556bf3f5 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 30 Mar 2021 20:10:20 -0400 Subject: [PATCH 7/9] Reduce nesting --- kwargs.jl | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/kwargs.jl b/kwargs.jl index a2f15bf..b9c94bc 100644 --- a/kwargs.jl +++ b/kwargs.jl @@ -4,24 +4,26 @@ include(joinpath(@__DIR__, "autodetect-dependabot.jl")) function kwargs(; coverage::Bool, force_latest_compatible_version::Union{Bool, Symbol}) - is_dependabot_job = AutodetectDependabot.is_dependabot_job() + if !(force_latest_compatible_version isa Bool) && (force_latest_compatible_version != :auto) + throw(ArgumentError("Invalid value for force_latest_compatible_version: $(force_latest_compatible_version)")) + end + kwargs_dict = Dict{Symbol, Any}() kwargs_dict[:coverage] = coverage - - if VERSION >= v"1.7.0-" # excludes 1.6, includes 1.7-DEV, includes 1.7 - if force_latest_compatible_version isa Bool - kwargs_dict[:force_latest_compatible_version] = force_latest_compatible_version - elseif force_latest_compatible_version == :auto - is_dependabot_job && @info("This is a Dependabot/CompatHelper job, so `force_latest_compatible_version` has been set to `true`") - kwargs_dict[:force_latest_compatible_version] = is_dependabot_job - else - throw(ArgumentError("Invalid value for force_latest_compatible_version: $(force_latest_compatible_version)")) - end + + if VERSION < v"1.7.0-" + (force_latest_compatible_version != :auto) && @warn("The `force_latest_compatible_version` option requires at least Julia 1.7", VERSION, force_latest_compatible_version) + return kwargs_dict + end + + if force_latest_compatible_version == :auto + is_dependabot_job = AutodetectDependabot.is_dependabot_job() + is_dependabot_job && @info("This is a Dependabot/CompatHelper job, so `force_latest_compatible_version` has been set to `true`") + kwargs_dict[:force_latest_compatible_version] = is_dependabot_job else - if force_latest_compatible_version != :auto - @warn("The `force_latest_compatible_version` option requires at least Julia 1.7", VERSION, force_latest_compatible_version) - end + kwargs_dict[:force_latest_compatible_version] = force_latest_compatible_version::Bool end + return kwargs_dict end From 7d93fe622bf8c54375f6bfd13e373bedd7d0d9f3 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 30 Mar 2021 20:48:21 -0400 Subject: [PATCH 8/9] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4f1652f..caf2624 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018-2020 GitHub, Inc., David Anthoff and contributors +Copyright (c) 2018-2021 GitHub, Inc., David Anthoff and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 1132bc01fc27bea62eeca1e0d97cf62ff8e55b02 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Wed, 31 Mar 2021 17:50:41 -0400 Subject: [PATCH 9/9] Update action.yml --- action.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index 0a0c5f0..6923474 100644 --- a/action.yml +++ b/action.yml @@ -47,18 +47,13 @@ runs: # packages via `Pkg.test`. JULIA_PKG_SERVER: "" - run: | - JULIA_CMD="julia" - PREFIX="${{ inputs.prefix }}" - [[ -n $PREFIX ]] && JULIA_CMD="$PREFIX $JULIA_CMD" - echo "JULIA_CMD=$JULIA_CMD" >> $GITHUB_ENV - shell: bash - - run: | - ${{ env.JULIA_CMD }} --check-bounds=yes --color=yes --depwarn=${{ inputs.depwarn }} --inline=${{ inputs.inline }} --project=${{ inputs.project }} -e ' - import Pkg - include(joinpath(ENV["GITHUB_ACTION_PATH"], "kwargs.jl")) - kwargs = Kwargs.kwargs(; - coverage = :(${{ inputs.coverage }}), - force_latest_compatible_version = :(${{ inputs.force_latest_compatible_version }}), - ) - Pkg.test(; kwargs...)' + # The Julia command that will be executed + julia_cmd=( julia --check-bounds=yes --color=yes --depwarn=${{ inputs.depwarn }} --inline=${{ inputs.inline }} --project=${{ inputs.project }} -e 'import Pkg;include(joinpath(ENV["GITHUB_ACTION_PATH"], "kwargs.jl"));kwargs = Kwargs.kwargs(;coverage = :(${{ inputs.coverage }}),force_latest_compatible_version = :(${{ inputs.force_latest_compatible_version }}),);Pkg.test(; kwargs...)' ) + + # Add the prefix in front of the command if there is one + prefix="${{ inputs.prefix }}" + [[ -n $prefix ]] && julia_cmd=( "$prefix" "${julia_cmd[@]}" ) + + # Run the Julia command + "${julia_cmd[@]}" shell: bash