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 the force_latest_compat keyword argument to Pkg.test #2176

Closed
wants to merge 1 commit into from
Closed

Add the force_latest_compat keyword argument to Pkg.test #2176

wants to merge 1 commit into from

Conversation

DilumAluthge
Copy link
Member

@DilumAluthge DilumAluthge commented Oct 30, 2020

This pull request adds the force_latest_compat keyword argument to the Pkg.test function.

When force_latest_compat is true, then, for each [compat] entry in the active project, only the latest compatible version will be allowed.

The default value is force_latest_compat = false.

Motivation

Suppose that you have a bot (e.g. CompatHelper or Dependabot) that opens pull requests to widen your [compat] entries whenever one of your dependencies makes a new breaking release.

And suppose that originally your package's Project.toml file looks like this:

[compat]
SomePackage = "1"

The bot opens a PR to change your package's Project.toml file to this:

[compat]
SomePackage = "1, 2"

Now, your CI runs your test suite with this new Project.toml file. The problem is that, during the test suite, Pkg.test might choose to run your package's tests with version 1 of SomePackage.jl. Therefore, even if your CI tests pass, you don't know whether or not your package is compatible with version 2 of SomePackage.jl.

The solution is to modify your CI test script. Instead of using this as your test script (in Travis CI, AppVeyor CI, GitHub Actions CI, etc.):

Pkg.test(coverage=true)

You would have this as your CI test script instead:

Pkg.test(coverage=true, force_latest_compat=true)

This will guarantee that your tests will run with version 2 of SomePackage.jl.

@KristofferC
Copy link
Member

If this is decided to be a good idea, I think an option to Pkg.test makes more sense instead of actual rewriting of the project file.

@DilumAluthge
Copy link
Member Author

Sure, that would be fine. We could have an optional keyword argument force_latest_compat. Where in the Pkg.test code would I implement this?

I definitely think that we need this feature somewhere. Otherwise, you don't actually know if your CompatHelper/Dependabot PRs are passing CI.

@DilumAluthge DilumAluthge changed the title Add the force_latest_compat function Add the force_latest_compat keyword argument to Pkg.test Nov 1, 2020
@DilumAluthge
Copy link
Member Author

DilumAluthge commented Nov 2, 2020

@KristofferC Alright, it is now a keyword argument to Pkg.test. Example usage:

Pkg.test(coverage = true, force_latest_compat = true)

The default value is force_latest_compat = false.

@DilumAluthge
Copy link
Member Author

Bump. @KristofferC take a look at the new implementation and let me know what you think.

@DilumAluthge
Copy link
Member Author

Bump.

@christopher-dG
Copy link
Member

Just to put what's been said in Slack somewhere permanent:

It might be a good idea to make forcing latest versions of dependencies the default Pkg.test behaviour in CI environments for PRs created by CompatHelper or Dependabot. For example, in GitHub Actions the environment variable GITHUB_REF will be refs/heads/compathelper/new_version/....

Personally, I don't see this getting much buy-in if it needs to be done manually.

@DilumAluthge
Copy link
Member Author

DilumAluthge commented Nov 23, 2020

Just to put what's been said in Slack somewhere permanent:

It might be a good idea to make forcing latest versions of dependencies the default Pkg.test behaviour in CI environments for PRs created by CompatHelper or Dependabot. For example, in GitHub Actions the environment variable GITHUB_REF will be refs/heads/compathelper/new_version/....

Personally, I don't see this getting much buy-in if it needs to be done manually.

I agree.

Do you think that should go in this PR, or a follow-up PR? I was thinking that we first get this PR merged, and then I'll make a follow-up PR to add the automatic CI detection.

The alternative approach would just to be to set force_latest_compat = true by default and call it a day. But I imagine that people will not like that.

@christopher-dG
Copy link
Member

If we're going to make latest compat default all the time, it's basically the same as just not having the option to at all. Not a good idea IMO. It doesn't really matter to me in which PR stuff happens, just as long as it doesn't get delayed a whole minor Julia version. If it's easier to do it after this is merged, then sure.

@DilumAluthge
Copy link
Member Author

How about this: I'll put the CI changes in a new PR targeting this branch. So Kristoffer and others can review the two PRs separately. But if they do want to review everything at once, they can merge that PR into this one.

I'll get the CI changes PR up later today.

@DilumAluthge
Copy link
Member Author

DilumAluthge commented Nov 23, 2020

Okay, the "set force_latest_compat=true on Dependabot/CompatHelper" pull request is up here: #2234

@KristofferC Do you want to review these two pull requests (#2176 and #2234) separately? Or do you want me to merge them into a single branch, and then you can review it as a single pull request?

@DilumAluthge
Copy link
Member Author

Based on the discussion in #2234, I have closed #2234, and the "auto-detect Dependabot/CompatHelper" functionality has been moved into julia-actions/julia-runtest#20.

@quinnj
Copy link
Member

quinnj commented Dec 9, 2020

Bump; this seems really useful for CompatHelper

@DilumAluthge
Copy link
Member Author

Any additional thoughts or review comments on this PR? If not, I'm inclined to wait a little bit, and then merge this PR.

return compat_new
end

function force_latest_compat(filename::AbstractString)
Copy link
Member

Choose a reason for hiding this comment

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

This function looks kinda pointless. We already have functions to read and write projects. What you want to do is just change the compat of an existing project. So the only thing that should be modified is

compat::Dict{String,String} = Dict{String,String}()# TODO Dict{String, VersionSpec}
.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we can get rid of the force_latest_compat(filename::AbstractString) method. However, we would just end up moving this code (the code to load the project from the Project.toml file) from this location to line 1443 of src/Operations.jl.

If you look at lines 1437 through 1443 of src/Operations.jl: the temp project that is going to be used for the test sandbox is in the form of a Project.toml file that has been written to disk at the filename tmp_project. This temp project does not exist in memory yet; it is only a project file on disk. So we will need to read it in from the file.

@@ -1438,6 +1440,10 @@ function sandbox(fn::Function, ctx::Context, target::PackageSpec, target_path::S
cp(sandbox_project, tmp_project)
chmod(tmp_project, 0o600)
end
if force_latest_compat
Copy link
Member

Choose a reason for hiding this comment

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

Modify the sandbox_project_override.env.project.compat before it is written (at line 1437) and the correct compat should just be printed automatically. No need to write to disk, chmod, read it back in, modify compat, write it back out to disk, chmod again.

Copy link
Member Author

Choose a reason for hiding this comment

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

That works if sandbox_project_override !== nothing. But what if we are in the other branch, i.e. isfile(sandbox_project)?

@DilumAluthge
Copy link
Member Author

See #2439 for an alternative to this PR.

@DilumAluthge
Copy link
Member Author

Closing in favor of #2439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants