Skip to content

Commit

Permalink
feat(cargo): support private crate (#24704)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
4 people committed Oct 3, 2023
1 parent 2a548e7 commit 3c592a2
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 16 deletions.
29 changes: 23 additions & 6 deletions docs/usage/rust.md
Expand Up @@ -31,9 +31,26 @@ Read the [Rust environment variables docs](https://doc.rust-lang.org/cargo/refer

## Private crate registries and private Git dependencies

If any dependencies are hosted in private Git repositories, [Git Authentication for cargo](https://doc.rust-lang.org/cargo/appendix/git-authentication.html) must be set up.

If any dependencies are hosted on private crate registries (i.e., not on `crates.io`), then credentials should be set up in such a way that the Git command-line is able to clone the registry index.
Third-party crate registries usually provide instructions to achieve this.

Both of these are currently only possible when running Renovate self-hosted.
You as user can set authentication for private crates by adding a `hostRules` configuration to your `renovate.json` file.

All token `hostRules` with a `hostType` (e.g. `github`, `gitlab`, `bitbucket`, etc.) and host rules without a `hostType` will be automatically setup for authentication.
You can also configure a `hostRules` that's only for Cargo authentication (e.g. `hostType: 'cargo'`).

Here's an example of authentication for a private GitHub and Cargo registry:

```js
module.exports = {
hostRules: [
{
matchHost: 'github.enterprise.com',
token: process.env.GITHUB_TOKEN,
hostType: 'github',
},
{
matchHost: 'someGitHost.enterprise.com',
token: process.env.CARGO_GIT_TOKEN,
hostType: 'cargo',
},
],
};
```
10 changes: 5 additions & 5 deletions lib/modules/manager/cargo/__snapshots__/artifacts.spec.ts.snap
Expand Up @@ -3,7 +3,7 @@
exports[`modules/manager/cargo/artifacts returns null if unchanged 1`] = `
[
{
"cmd": "cargo update --manifest-path Cargo.toml --workspace",
"cmd": "cargo update --config net.git-fetch-with-cli=true --manifest-path Cargo.toml --workspace",
"options": {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -26,7 +26,7 @@ exports[`modules/manager/cargo/artifacts returns null if unchanged 1`] = `
exports[`modules/manager/cargo/artifacts returns updated Cargo.lock 1`] = `
[
{
"cmd": "cargo update --manifest-path Cargo.toml --workspace",
"cmd": "cargo update --config net.git-fetch-with-cli=true --manifest-path Cargo.toml --workspace",
"options": {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -49,7 +49,7 @@ exports[`modules/manager/cargo/artifacts returns updated Cargo.lock 1`] = `
exports[`modules/manager/cargo/artifacts returns updated Cargo.lock for lockfile maintenance 1`] = `
[
{
"cmd": "cargo update --manifest-path Cargo.toml",
"cmd": "cargo update --config net.git-fetch-with-cli=true --manifest-path Cargo.toml",
"options": {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -72,7 +72,7 @@ exports[`modules/manager/cargo/artifacts returns updated Cargo.lock for lockfile
exports[`modules/manager/cargo/artifacts returns updated workspace Cargo.lock 1`] = `
[
{
"cmd": "cargo update --manifest-path crates/one/Cargo.toml --workspace",
"cmd": "cargo update --config net.git-fetch-with-cli=true --manifest-path crates/one/Cargo.toml --workspace",
"options": {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -95,7 +95,7 @@ exports[`modules/manager/cargo/artifacts returns updated workspace Cargo.lock 1`
exports[`modules/manager/cargo/artifacts updates Cargo.lock based on the packageName, when given 1`] = `
[
{
"cmd": "cargo update --manifest-path Cargo.toml --workspace",
"cmd": "cargo update --config net.git-fetch-with-cli=true --manifest-path Cargo.toml --workspace",
"options": {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down

0 comments on commit 3c592a2

Please sign in to comment.