From e16476132f6c6cc72239ad1c42667c1f93b79a81 Mon Sep 17 00:00:00 2001 From: Sebastian Schlenkrich Date: Tue, 23 Jul 2024 13:20:19 +0200 Subject: [PATCH] Add test_arg input and populate to test_args in test() (#73) --- README.md | 32 ++++++++++++++++++++++++++++++++ action.yml | 4 ++++ kwargs.jl | 8 +++++++- test_harness.jl | 4 +++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 80697c8..2784e0f 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,38 @@ If you only want to add this prefix on certain builds, you can [include addition This will add the prefix `xvfb-run` to all builds where the `os` is `ubuntu-latest`. +### Pass Arguments to Test Suite + +You can pass arguments from the workflow specification to the test script via the `test_args` parameter. + +This is useful, for example, to specify separate workflows for fast and slow tests. + +The functionality can be incorporated as follows: + +```yaml + # ... + steps: + # ... + - uses: julia-actions/julia-runtest@v1 + with: + test_args: 'only_fast_tests' + # ... +``` + +The value of `test_args` can be accessed in `runtest.jl` via the `ARGS` variable. An example for `runtest.jl` is given below. + +```julia +using Test +# ... + +if @isdefined(ARGS) && length(ARGS) > 0 && ARGS[1] == "only_fast_tests" + # run only fast tests + include("only_fast_tests.jl") +else + # do something else +end +``` + ### Registry flavor preference diff --git a/action.yml b/action.yml index 7869774..e6c77e6 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,9 @@ inputs: allow_reresolve: description: 'Whether to allow re-resolving of package versions in the test environment. Only effective on Julia 1.9+. Options: true | false. Default value: true' default: 'true' + test_args: + description: 'Argument string that is passed on to test.' + default: '' runs: using: 'composite' @@ -74,3 +77,4 @@ runs: CHECK_BOUNDS: ${{ inputs.check_bounds }} COMPILED_MODULES: ${{ inputs.compiled_modules }} ALLOW_RERESOLVE: ${{ inputs.allow_reresolve }} + TEST_ARGS: ${{ inputs.test_args }} diff --git a/kwargs.jl b/kwargs.jl index 03992af..0a7caae 100644 --- a/kwargs.jl +++ b/kwargs.jl @@ -7,7 +7,9 @@ include(joinpath(@__DIR__, "autodetect-dependabot.jl")) function kwargs(; coverage, force_latest_compatible_version, allow_reresolve, - julia_args::AbstractVector{<:AbstractString}=String[]) + julia_args::AbstractVector{<:AbstractString}=String[], + test_args::AbstractString="", + ) if coverage isa AbstractString coverage = parse(Bool, coverage) end @@ -55,6 +57,10 @@ function kwargs(; coverage, if VERSION >= v"1.9" kwargs_dict[:allow_reresolve] = parse(Bool, allow_reresolve) end + + if test_args != "" # avoid ambiguity by empty string in test_args + kwargs_dict[:test_args] = [test_args] + end return kwargs_dict end diff --git a/test_harness.jl b/test_harness.jl index 8863cea..43e9c14 100644 --- a/test_harness.jl +++ b/test_harness.jl @@ -4,7 +4,9 @@ kwargs = Kwargs.kwargs(; coverage=ENV["COVERAGE"], force_latest_compatible_version=ENV["FORCE_LATEST_COMPATIBLE_VERSION"], allow_reresolve=ENV["ALLOW_RERESOLVE"], julia_args=[string("--check-bounds=", ENV["CHECK_BOUNDS"]), - string("--compiled-modules=", ENV["COMPILED_MODULES"])]) + string("--compiled-modules=", ENV["COMPILED_MODULES"])], + test_args=ENV["TEST_ARGS"], + ) if parse(Bool, ENV["ANNOTATE"]) && v"1.8pre" < VERSION < v"1.9.0-beta3" push!(LOAD_PATH, "@tests-logger-env") # access dependencies