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 support for --registry and --index parameters #15

Closed
Veetaha opened this issue Sep 1, 2023 · 6 comments
Closed

Add support for --registry and --index parameters #15

Veetaha opened this issue Sep 1, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@Veetaha
Copy link

Veetaha commented Sep 1, 2023

For the use case when the installation happens from an alternative crates registry (e.g. a registry like Cloudsmith) cargo install provides a --registry and --index parameters.

It should be simple to provide a way to pass a registry and index input parameters for the action. It's important that the values of these parameters is then used in the cache key.

These parameters are mutually exclusive. The --registry is just a named index. I.e. the user has to have the following in the config.

[registries.registry-name]
index = "URL"

I am not sure how hard it will be to support version wildcards with alternative registries. I suppose listing the registry isn't included in the registry web API requirements. It would be at least something if only exact versions are supported for alternative registries

@baptiste0928
Copy link
Owner

I'm not familiar with alternative registries, but implementing version resolution as currently done with crates.io will not be possible without an easy way to query all available versions.

This might be possible with sparse indexes, but not all registries support them, and even then it will require parsing the index configuration and registry configuration.

For now, the best option is - as you suggested - to support only exact version requirements. I'll try to find some time to implement this in the next few days.

If supporting version wildcards is a requirement for some use cases, you can always use a more generic caching action like the awesome swatinem/rust-cache action, but the cache will be invalidated more often and will not be invalidated when a new version matching the requirements is available.

@baptiste0928 baptiste0928 added the enhancement New feature or request label Sep 2, 2023
@baptiste0928
Copy link
Owner

Hey @Veetaha, I've implemented this in #18. Can you test if everything works for you before I merge it?

You can use the PR's branch like this:

-  uses: baptiste0928/cargo-install@feat/custom-registry
   with:
    crate: my-awesome-crate
    version: 1.0.0 # exact version, except if using sparse index
    # index or registry parameters

Let me know if it works or if run into any issue.

@Veetaha
Copy link
Author

Veetaha commented Sep 5, 2023

Hey, I gave it a test run with the following setup (I redacted the names, since it uses a private registry):

uses: baptiste0928/cargo-install@b3ea78257dd2498a1656a5faa4aabbff8e287fd1
with:
  args: --bin bin-name
  crate: package-name
  index: https://dl.cloudsmith.io/basic/org-name/repo-name/cargo/index.git

This failed with the following output

Installing package-name...
  Error: Version ranges can only be used with sparse indexes

Unfortunately, we don't use a sparse index due to the lack of support for auth (rust-lang/cargo#10474). Then I tried specifying an exact version and it worked

uses: baptiste0928/cargo-install@b3ea78257dd2498a1656a5faa4aabbff8e287fd1
with:
  args: --bin bin-name
  crate: package-name
  index: https://dl.cloudsmith.io/basic/org-name/repo-name/cargo/index.git
  version: x.y.z
Installing package-name...
  Using non-sparse index, skipping version resolution
  Installation settings:
     version: x.y.z
     path: /home/runner/.cargo-install/package-name
     key: cargo-install-package-name-x.y.z-1f65051c7c713cc24cf4
No cached version found, installing package-name using cargo...
Added /home/runner/.cargo-install/package-name/bin to PATH.
Installed package-name x.y.z.

and caching works

  Cache Size: ~N MB (Nbytes B)
  /usr/bin/tar -xf /home/runner/work/_temp/a10cde7f-25fd-4081-bd19-9d18a9901d59/cache.tzst -P -C /home/runner/work/org/repo --use-compress-program unzstd
  Cache restored successfully
Restored package-name from cache.
Added /home/runner/.cargo-install/package-name/bin to PATH.
Installed package-name x.y.z.
Received Nbytes of Nbytes (100.0%), K.P MBs/sec

But would it be possible to support the use case at the top where the version is not specified? Meaning it should install just the latest version? I suppose there will be a problem of setting the cache key since no version is known at this point?

@baptiste0928
Copy link
Owner

But would it be possible to support the use case at the top where the version is not specified? Meaning it should install just the latest version? I suppose there will be a problem of setting the cache key since no version is known at this point?

You're right, the cache key needs the exact version being installed so it can restore from the cache and skip cargo install entirely. Version resolution was previously done using the Crates.io API, I rewrote it to use the sparse index instead (#16), so it can support at least some alternative registries.

For registries that do not support the sparse index, it will need to clone the registry index locally to do version resolution. It can be implemented, but I don't have time to do it right now. I'm open to contributions if you (or anyone else reading this issue) would like to try to implement it.

@Veetaha
Copy link
Author

Veetaha commented Sep 6, 2023

I don't think I have bandwidth for this contribution now, and it's not critical for me right now. I created a separate issue #19 targeted for supporting version wildcards so that we can close this one and have support for pinned package version installations, which is already good

@baptiste0928
Copy link
Owner

I published the new version with registry support (v2.2.0)

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

No branches or pull requests

2 participants