-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command cargoLogin to login in all cargo registries (#153)
* cargoSyncConfig logins in all cargo registries * Add changelog entry * Placate linters * Add comment on ignored error in CargoSyncConfigTask * Move cargo login commands to new CargoLoginTask * Use cargo:token with least priority * Add comment on order of cargo credential providers * Update changelog entry * Linting * Apply suggestions from Nicolas Co-authored-by: Nicolas Trinquier <[email protected]> * Use TaskStatus for CargoLoginTask error handling * add log when cargo login command fails --------- Co-authored-by: Quentin Santos <[email protected]> Co-authored-by: Nicolas Trinquier <[email protected]> Co-authored-by: Niklas Rosenstein <[email protected]>
- Loading branch information
1 parent
3d53936
commit 6de51b3
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,9 @@ id = "db65bd12-a9d1-472c-a38b-6f889cdda683" | |
type = "improvement" | ||
description = "Move bump version into publish" | ||
author = "[email protected]" | ||
|
||
[[entries]] | ||
id = "31a52a49-8d26-4dd7-a4bc-84fe9fb37c19" | ||
type = "improvement" | ||
description = "Add task to login in all cargo registries" | ||
author = "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import annotations | ||
|
||
from subprocess import run | ||
|
||
from kraken.core import Property, Task, TaskStatus | ||
|
||
from ..config import CargoRegistry | ||
|
||
|
||
class CargoLoginTask(Task): | ||
"""This task runs cargo login for each registry.""" | ||
|
||
#: The registries to insert into the configuration. | ||
registries: Property[list[CargoRegistry]] = Property.default_factory(list) | ||
|
||
def execute(self) -> TaskStatus: | ||
for registry in self.registries.get(): | ||
publish_token = registry.publish_token | ||
if publish_token is None: | ||
continue | ||
p = run( | ||
["cargo", "login", "--registry", registry.alias], | ||
cwd=self.project.directory, | ||
capture_output=True, | ||
input=publish_token.encode(), | ||
) | ||
if p.returncode != 0: | ||
if p.stderr.endswith(b"\nerror: config.json not found in registry\n"): | ||
# This happens when the project's .cargo/config.toml file | ||
# contains a regitry which does not exist (anymore); since | ||
# that means it is not used, we can just skip configuring | ||
# authentication on this registry | ||
pass | ||
else: | ||
# unknown error, fail normally | ||
self.logger.error("cargo login failed: %s", p.stderr.decode()) | ||
return TaskStatus.failed("could not run cargo login") | ||
return TaskStatus.succeeded() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters