-
Notifications
You must be signed in to change notification settings - Fork 249
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
Implement initial tool for publishing to crates.io #251
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98b0d80
Implement initial tool for publishing to crates.io
jdisanti 5222e2e
CR feedback
jdisanti c740a1d
Fix clippy lints
jdisanti cc155ad
Add tools to CI
jdisanti 97697bb
Only run SDK CI when changing the SDK
jdisanti 7ef6cbe
Revert "Only run SDK CI when changing the SDK"
jdisanti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
on: [ pull_request ] | ||
|
||
env: | ||
rust_version: 1.52.1 | ||
rust_version: 1.53.0 | ||
|
||
name: CI | ||
|
||
|
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,39 @@ | ||
on: | ||
pull_request: | ||
paths: 'tools/**' | ||
|
||
env: | ||
rust_version: 1.53.0 | ||
rust_toolchain_components: clippy,rustfmt | ||
|
||
name: Tools CI | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
name: Compile, Test, and Lint the `tools/` path | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v2 | ||
name: Cargo Cache | ||
with: | ||
path: | | ||
~/.cargo/registry | ||
~/.cargo/git | ||
tools/publisher/target | ||
key: tools-${{ runner.os }}-cargo-${{ hashFiles('tools/**/Cargo.toml') }} | ||
restore-keys: | | ||
tools-${{ runner.os }}-cargo- | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ env.rust_version }} | ||
components: ${{ env.rust_toolchain_components }} | ||
default: true | ||
- name: Format Check | ||
run: rustfmt --check --edition 2018 $(find tools -name '*.rs' -print | grep -v /target/) | ||
- name: Cargo Test | ||
run: cargo test | ||
working-directory: tools/publisher | ||
- name: Cargo Clippy | ||
run: cargo clippy -- -D warnings | ||
working-directory: tools/publisher |
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,21 @@ | ||
[package] | ||
name = "publisher" | ||
version = "0.1.0" | ||
authors = ["AWS Rust SDK Team <[email protected]>"] | ||
description = "Tool used to publish the AWS SDK to crates.io" | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
publish = false | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
cargo_toml = "0.10.1" | ||
clap = "2.33" | ||
dialoguer = "0.8" | ||
num_cpus = "1.13" | ||
semver = "1.0" | ||
thiserror = "1.0" | ||
tokio = { version = "1.12", features = ["full"] } | ||
toml = "0.5.8" | ||
tracing = "0.1.29" | ||
tracing-subscriber = "0.2.25" |
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 @@ | ||
This is a tool that the SDK developer team uses to publish the AWS SDK to crates.io. |
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,86 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
//! Module for interacting with Cargo. | ||
|
||
use anyhow::{Context, Result}; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::{Command, Output}; | ||
|
||
macro_rules! cmd { | ||
[ $( $x:expr ),* ] => { | ||
{ | ||
let mut cmd = Cmd::new(); | ||
$(cmd.push($x);)* | ||
cmd | ||
} | ||
}; | ||
} | ||
|
||
/// Confirms that cargo exists on the path. | ||
pub async fn confirm_installed_on_path() -> Result<()> { | ||
cmd!["cargo", "--version"] | ||
.spawn() | ||
.await | ||
.context("cargo is not installed on the PATH")?; | ||
Ok(()) | ||
} | ||
|
||
/// Returns a `Cmd` that, when spawned, will asynchronously run `cargo publish` in the given crate path. | ||
pub fn publish_task(crate_path: &Path) -> Cmd { | ||
cmd!["cargo", "publish"].working_dir(crate_path) | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Cmd { | ||
parts: Vec<String>, | ||
working_dir: Option<PathBuf>, | ||
} | ||
|
||
impl Cmd { | ||
fn new() -> Cmd { | ||
Default::default() | ||
} | ||
|
||
fn push(&mut self, part: impl Into<String>) { | ||
self.parts.push(part.into()); | ||
} | ||
|
||
fn working_dir(mut self, working_dir: impl AsRef<Path>) -> Self { | ||
self.working_dir = Some(working_dir.as_ref().into()); | ||
self | ||
} | ||
|
||
/// Returns a plan string that can be output to the user to describe the command. | ||
pub fn plan(&self) -> String { | ||
let mut plan = String::new(); | ||
if let Some(working_dir) = &self.working_dir { | ||
plan.push_str(&format!("[in {:?}]: ", working_dir)); | ||
} | ||
plan.push_str(&self.parts.join(" ")); | ||
plan | ||
} | ||
|
||
/// Runs the command asynchronously. | ||
pub async fn spawn(mut self) -> Result<Output> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason to do this async? Seems like we may want to block on these commands running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I see, we use a semaphore later. 👍🏻 |
||
let working_dir = self | ||
.working_dir | ||
.take() | ||
.unwrap_or_else(|| std::env::current_dir().unwrap()); | ||
let mut command: Command = self.into(); | ||
tokio::task::spawn_blocking(move || Ok(command.current_dir(working_dir).output()?)).await? | ||
} | ||
} | ||
|
||
impl From<Cmd> for Command { | ||
fn from(cmd: Cmd) -> Self { | ||
assert!(!cmd.parts.is_empty()); | ||
let mut command = Command::new(&cmd.parts[0]); | ||
for i in 1..cmd.parts.len() { | ||
command.arg(&cmd.parts[i]); | ||
} | ||
command | ||
} | ||
} |
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,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use anyhow::{Context, Result}; | ||
use std::path::Path; | ||
use tokio::fs::File; | ||
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | ||
|
||
/// Abstraction of the filesystem to allow for more tests to be added in the future. | ||
#[derive(Clone, Debug)] | ||
pub enum Fs { | ||
Real, | ||
} | ||
|
||
impl Fs { | ||
/// Reads entire file into `Vec<u8>` | ||
pub async fn read_file(&self, path: impl AsRef<Path>) -> Result<Vec<u8>> { | ||
match self { | ||
Fs::Real => tokio_read_file(path.as_ref()).await, | ||
} | ||
} | ||
|
||
/// Writes an entire file from a `&[u8]` | ||
pub async fn write_file(&self, path: impl AsRef<Path>, contents: &[u8]) -> Result<()> { | ||
match self { | ||
Fs::Real => tokio_write_file(path.as_ref(), contents).await, | ||
} | ||
} | ||
} | ||
|
||
async fn tokio_read_file(path: &Path) -> Result<Vec<u8>> { | ||
let mut contents = Vec::new(); | ||
let mut file = File::open(path) | ||
.await | ||
.with_context(|| format!("failed to open {:?}", path))?; | ||
file.read_to_end(&mut contents) | ||
.await | ||
.with_context(|| format!("failed to read {:?}", path))?; | ||
Ok(contents) | ||
} | ||
|
||
async fn tokio_write_file(path: &Path, contents: &[u8]) -> Result<()> { | ||
let mut file = File::create(path) | ||
.await | ||
.with_context(|| format!("failed to create {:?}", path))?; | ||
file.write_all(contents) | ||
.await | ||
.with_context(|| format!("failed to write {:?}", path))?; | ||
Ok(()) | ||
} |
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,53 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use crate::subcommand::fix_manifests::subcommand_fix_manifests; | ||
use crate::subcommand::publish::subcommand_publish; | ||
use anyhow::Result; | ||
use clap::{crate_authors, crate_description, crate_name, crate_version}; | ||
|
||
mod cargo; | ||
mod fs; | ||
mod package; | ||
mod repo; | ||
mod sort; | ||
mod subcommand; | ||
|
||
pub const REPO_NAME: &str = "aws-sdk-rust"; | ||
pub const REPO_CRATE_PATH: &str = "sdk"; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
tracing_subscriber::fmt() | ||
.with_env_filter( | ||
std::env::var("RUST_LOG").unwrap_or_else(|_| "error,publisher=info".to_owned()), | ||
) | ||
.init(); | ||
|
||
let matches = clap_app().get_matches(); | ||
if let Some(_matches) = matches.subcommand_matches("publish") { | ||
subcommand_publish().await?; | ||
} else if let Some(_matches) = matches.subcommand_matches("fix-manifests") { | ||
subcommand_fix_manifests().await?; | ||
} else { | ||
clap_app().print_long_help().unwrap(); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn clap_app() -> clap::App<'static, 'static> { | ||
clap::App::new(crate_name!()) | ||
.version(crate_version!()) | ||
.author(crate_authors!()) | ||
.about(crate_description!()) | ||
// In the future, there may be another subcommand for yanking | ||
.subcommand( | ||
clap::SubCommand::with_name("fix-manifests") | ||
.about("fixes path dependencies in manifests to also have version numbers"), | ||
) | ||
.subcommand( | ||
clap::SubCommand::with_name("publish").about("publishes the AWS SDK to crates.io"), | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow...is there no library that does this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started off using async-process, but it was more complicated than I wanted to access stdout/stderr with that.