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 an input to specify which projects to modify #3

Merged
merged 1 commit into from
Feb 17, 2024
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions downgrade.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 20 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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
Expand Down
Loading