diff --git a/README.md b/README.md index 1bcb0f9..7d8d049 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,12 @@ bounds are too low. # (not strict) or 'v0' (strict for "0.*.*" and not strict otherwise). # Default: 'v0' strict: '' + + # Comma-separated list of Julia projects to modify. The Project.toml files in all of + # these directories will be modified. + # Example: ., test, docs + # Default: . + projects: '' ``` ## Example @@ -71,7 +77,7 @@ jobs: - uses: julia-actions/julia-downgrade-compat@v1 if: ${{ matrix.version == '1.6' }} with: - skip: Pkg,TOML + skip: Pkg, TOML - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 ``` diff --git a/action.yml b/action.yml index 066ce3e..9fbbb3a 100644 --- a/action.yml +++ b/action.yml @@ -7,10 +7,13 @@ inputs: strict: description: 'true, false or v0. Default: v0.' default: 'v0' + projects: + description: 'Comma-separated list of Julia projects to modify.' + default: '.' runs: using: "composite" steps: - - run: julia "${{ github.action_path }}/downgrade.jl" "${{ inputs.skip }}" "${{ inputs.strict }}" + - run: julia "${{ github.action_path }}/downgrade.jl" "${{ inputs.skip }}" "${{ inputs.strict }}" "${{ inputs.projects }}" shell: bash branding: icon: trending-down diff --git a/downgrade.jl b/downgrade.jl index 1057beb..c48d809 100644 --- a/downgrade.jl +++ b/downgrade.jl @@ -62,14 +62,18 @@ function downgrade(file, ignore_pkgs, strict) end end -ignore_pkgs = map(strip, split(ARGS[1], ",", keepempty=false)) +ignore_pkgs = filter(!isempty, map(strip, split(ARGS[1], ","))) strict = ARGS[2] +dirs = filter(!isempty, map(strip, split(ARGS[3], ","))) strict in ["true", "false", "v0"] || error("strict must be true, false or v0") -project_files = filter(isfile, ["Project.toml", "JuliaProject.toml"]) -isempty(project_files) && error("could not find Project.toml") - -for file in project_files - downgrade(file, ignore_pkgs, strict) +for dir in dirs + files = [joinpath(dir, "Project.toml"), joinpath(dir, "JuliaProject.toml")] + filter!(isfile, files) + isempty(files) && error("could not find Project.toml or JuliaProject.toml in $dir") + for file in files + @info "downgrading $file" + downgrade(file, ignore_pkgs, strict) + end end diff --git a/test/runtests.jl b/test/runtests.jl index 463df47..52c7a85 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,10 +5,11 @@ downgrade_jl = joinpath(dirname(@__DIR__), "downgrade.jl") specs = [ ( strict = "v0", - ignore = "Pkg0", + ignore = "Pkg0, Pkg00", compats = [ ("julia", "1.6", "1.6"), ("Pkg0", "1.2", "1.2"), + ("Pkg00", "1.3", "1.3"), ("Pkg1", "1", "~1.0.0"), ("Pkg2", "1.2", "~1.2.0"), ("Pkg3", "1.2.3", "~1.2.3"), @@ -26,10 +27,11 @@ specs = [ ) ( strict = "true", - ignore = "Pkg0", + ignore = "Pkg0, Pkg00", compats = [ ("julia", "1.6", "1.6"), ("Pkg0", "1.2", "1.2"), + ("Pkg00", "1.3", "1.3"), ("Pkg1", "1", "=1.0.0"), ("Pkg2", "1.2", "=1.2.0"), ("Pkg3", "1.2.3", "=1.2.3"), @@ -47,10 +49,11 @@ specs = [ ) ( strict = "false", - ignore = "Pkg0", + ignore = "Pkg0, Pkg00", compats = [ ("julia", "1.6", "1.6"), ("Pkg0", "1.2", "1.2"), + ("Pkg00", "1.3", "1.3"), ("Pkg1", "1", "~1.0.0"), ("Pkg2", "1.2", "~1.2.0"), ("Pkg3", "1.2.3", "~1.2.3"), @@ -85,13 +88,20 @@ function test_downgrade(; strict, ignore, compats, file) @info "testing $strict $ignore $file" mktempdir() do dir cd(dir) do - toml1 = make_toml([(pkg, compat) for (pkg, compat, _) in compats]) - toml2 = make_toml([(pkg, compat) for (pkg, _, compat) in compats]) - write("Project.toml", toml1) - run(`$(Base.julia_cmd()) $downgrade_jl $ignore $strict`) - toml3 = read("Project.toml", String) - @test toml3 != toml1 - @test toml3 == toml2 + toml1a = make_toml([(pkg, compat) for (pkg, compat, _) in compats]) + toml2a = make_toml([(pkg, compat) for (pkg, _, compat) in compats]) + toml1b = toml1a * "# foo\n" + toml2b = toml2a * "# foo\n" + mkdir("foo") + write(file, toml1a) + write(joinpath("foo", file), toml1b) + run(`$(Base.julia_cmd()) $downgrade_jl $ignore $strict "., foo"`) + toml3a = read(file, String) + toml3b = read(joinpath("foo", file), String) + @test toml3a != toml1a + @test toml3a == toml2a + @test toml3b != toml1b + @test toml3b == toml2b end end end