Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add the force_latest_compatible_version input, and add the "auto-de…
…tect Dependabot/CompatHelper" functionality
  • Loading branch information
DilumAluthge committed Mar 30, 2021
commit 4e2b021e489b7502f7bd251f798ad9e85d4eb2c2
26 changes: 17 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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...)'
Copy link
Member

Choose a reason for hiding this comment

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

Why is this split into two steps?

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually wasn't sure how to combine them into a single step

Copy link
Member Author

@DilumAluthge DilumAluthge Mar 31, 2021

Choose a reason for hiding this comment

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

Would I just change ${{ env.JULIA_CMD }} to "$JULIA_CMD"?

Copy link
Member

@SaschaMann SaschaMann Mar 31, 2021

Choose a reason for hiding this comment

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

You could leave the bash part almost as it was and then only replace -e 'using Pkg; Pkg.test(coverage=${{ inputs.coverage }})' with the new code.

I forgot the exact details, but there was some reason why () and a bash array was used. Originally I had a similar approach with normal double quoted variables but some people more familiar with bash told me it's a bad idea for reasons I forgot :D

Copy link
Member

Choose a reason for hiding this comment

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

Other than that, this PR is good to be merged

Copy link
Member Author

Choose a reason for hiding this comment

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

@SaschaMann Take a look now. Is this correct?

Copy link
Member

Choose a reason for hiding this comment

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

Looks good to me! Thanks :)

shell: bash
29 changes: 29 additions & 0 deletions autodetect-dependabot.jl
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions kwargs.jl
Original file line number Diff line number Diff line change
@@ -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