Skip to content
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM python:3.7-alpine
RUN apk add --no-cache img --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

# Setup other deps
RUN apk add --no-cache git skopeo docker
RUN apk add --no-cache git skopeo docker cargo

# Define the working directory
WORKDIR taskboot
Expand Down
33 changes: 33 additions & 0 deletions taskboot/cargo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import logging
import subprocess

from taskboot.config import Configuration

logger = logging.getLogger(__name__)


def cargo_publish(target, args):
"""
Publish a crate on crates.io
"""

# Load config from file/secret
config = Configuration(args)
assert config.has_cargo_auth(), "Missing Cargo authentication"

# Build the package to publish on crates.io
subprocess.run(["cargo", "publish", "--dry-run"], check=True)

# Publish the crate on crates.io
Comment thread
Luni-4 marked this conversation as resolved.
# stdout and stderr are captured to avoid leaking the token
proc = subprocess.run(
["cargo", "publish", "--token", config.cargo["token"]], capture_output=True,
)

if proc.returncode != 0:
raise Exception("Failed to publish the crate on crates.io")
7 changes: 7 additions & 0 deletions taskboot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from taskboot.build import build_compose
from taskboot.build import build_hook
from taskboot.build import build_image
from taskboot.cargo import cargo_publish
from taskboot.github import github_release
from taskboot.push import heroku_release
from taskboot.push import push_artifacts
Expand Down Expand Up @@ -301,6 +302,12 @@ def main():
)
github_release_cmd.set_defaults(func=github_release)

# Publish on crates.io
cargo_publish_cmd = commands.add_parser(
"cargo-publish", help="Publish a crate on crates.io"
)
cargo_publish_cmd.set_defaults(func=cargo_publish)

# Always load the target
args = parser.parse_args()
target = Target(args)
Expand Down
6 changes: 6 additions & 0 deletions taskboot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ def has_github_auth(self):
if github is None:
return False
return "token" in github

def has_cargo_auth(self):
cargo = self.config.get("cargo")
if cargo is None:
return False
return "token" in cargo