Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
532531f
upload metadata to movey
ea-open-source May 20, 2022
e1091b2
Add api token to upload request, get token from credential file
ea-open-source Jun 15, 2022
1213fbe
Show error message if upload with bad credentials
ea-open-source Jun 15, 2022
4c4d756
Refactor move_cli's utils & add cli tests
ea-open-source Jun 17, 2022
fe74142
Remove `description, total_size` field from request body, change move…
ea-open-source Jun 24, 2022
3eab134
call movey api after getting dependency
ea-open-source May 20, 2022
5b63f9d
Change dev movey_url, send params in post request
ea-open-source Jun 23, 2022
cd20142
Refactor error message when upload failed, add reqwest crate
ea-open-source Jun 27, 2022
0d374f6
Get long rev, use cli_exe path from env
ea-open-source Jun 27, 2022
c99c9b5
Refactor test code to run in parallel
ea-open-source Jun 28, 2022
38eefef
Refactor tests to run in current dir, flatten `upload` command
ea-open-source Jul 6, 2022
b575537
Refactor to be specific to Movey, change UploadRequest's params
ea-open-source Jul 11, 2022
1bdf00d
Refactor MOVE_HOME env, MOVEY_URL to common package
ea-open-source Jul 14, 2022
9f1c462
Refactor test logic in uploading, remove `increase download` logic
ea-open-source Jul 15, 2022
ccc39c6
Add Movey server Mock, refactor test code in upload
ea-open-source Jul 22, 2022
e98bb73
Rename move_command_line_common::movey.rs to movey_constants.rs
ea-open-source Jul 25, 2022
9680b91
Change movey api url, refactor getting credential key, refactor tests
ea-open-source Aug 2, 2022
41d4298
Rename movey api, change the message of successful upload request
ea-open-source Aug 5, 2022
6fd45f5
Refactor and add comments for movey tests
ea-open-source Aug 8, 2022
190f3a2
Refactor and rebase according to #226 changes
ea-open-source Aug 9, 2022
7a63283
Refactor mock movey server function, remove unnecessary license
ea-open-source Aug 10, 2022
e94be27
Move `MOVEY_CREDENTIAL_PATH` to common package, refactor logic of rea…
ea-open-source Aug 11, 2022
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
1,242 changes: 1,192 additions & 50 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion devtools/x-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ determinator = "0.7.0"
guppy = "0.12.3"
indoc = "1.0.3"
hex = "0.4.3"
log = "0.4.14"
log = "0.4.17"
toml = "0.5.8"
once_cell = "1.7.2"
ouroboros = "0.9.2"
Expand Down
2 changes: 1 addition & 1 deletion language/move-command-line-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ edition = "2021"
[dependencies]
anyhow = "1.0.52"
difference = "2.0.0"
dirs-next = "2.0.0"
walkdir = "2.3.1"
sha2 = "0.9.3"
hex = "0.4.3"
num-bigint = "0.4.0"
once_cell = "1.7.2"
serde = { version = "1.0.124", features = ["derive"] }
dirs-next = "2.0.0"

move-core-types = { path = "../move-core/types" }
1 change: 1 addition & 0 deletions language/move-command-line-common/src/movey_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
pub const MOVEY_URL: &str = "https://movey-app-staging.herokuapp.com";
#[cfg(not(debug_assertions))]
pub const MOVEY_URL: &str = "https://www.movey.net";
pub const MOVEY_CREDENTIAL_PATH: &str = "/movey_credential.toml";
3 changes: 3 additions & 0 deletions language/tools/move-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ tempfile = "3.2.0"
walkdir = "2.3.1"
codespan-reporting = "0.11.1"
itertools = "0.10.0"
serde_json = "1.0"
toml_edit = { version = "0.14.3", features = ["easy"] }
reqwest = { version = "0.10", features = ["blocking", "json"] }

bcs = "0.1.2"
move-bytecode-verifier = { path = "../../move-bytecode-verifier" }
Expand Down Expand Up @@ -51,6 +53,7 @@ move-bytecode-viewer = { path = "../move-bytecode-viewer" }

[dev-dependencies]
datatest-stable = "0.1.1"
httpmock = "0.6.6"

[[bin]]
name = "move"
Expand Down
1 change: 1 addition & 0 deletions language/tools/move-cli/src/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod docgen;
pub mod errmap;
pub mod info;
pub mod movey_login;
pub mod movey_upload;
pub mod new;
pub mod prove;
pub mod test;
Expand Down
23 changes: 6 additions & 17 deletions language/tools/move-cli/src/base/movey_login.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::utils::movey_credential::read_credential_file;
use anyhow::{bail, Result};
use clap::Parser;
use move_command_line_common::{env::MOVE_HOME, movey_constants::MOVEY_URL};
use move_command_line_common::{
env::MOVE_HOME,
movey_constants::{MOVEY_CREDENTIAL_PATH, MOVEY_URL},
};
use std::{fs, fs::File, io, path::PathBuf};
use toml_edit::easy::{map::Map, Value};

pub const MOVEY_CREDENTIAL_PATH: &str = "/movey_credential.toml";

#[derive(Parser)]
#[clap(name = "movey-login")]
pub struct MoveyLogin;
Expand Down Expand Up @@ -47,20 +49,7 @@ impl MoveyLogin {
create_credential_file(&credential_path)?;
}

let old_contents: String;
match fs::read_to_string(&credential_path) {
Ok(contents) => {
old_contents = contents;
}
Err(error) => bail!("Error reading input: {}", error),
}
let mut toml: Value = old_contents.parse().map_err(|e| {
anyhow::Error::from(e).context(format!(
"could not parse input at {} as TOML",
&credential_path
))
})?;

let mut toml: Value = read_credential_file(&credential_path)?;
// only update token key, keep the rest of the file intact
if let Some(registry) = toml.as_table_mut().unwrap().get_mut("registry") {
if let Some(toml_token) = registry.as_table_mut().unwrap().get_mut("token") {
Expand Down
134 changes: 134 additions & 0 deletions language/tools/move-cli/src/base/movey_upload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::utils::movey_credential;
use anyhow::bail;
use clap::*;
use move_command_line_common::env::MOVE_HOME;
use reqwest::blocking::Client;
use std::{env, fs::File, path::PathBuf, process::Command};

// Metadata that will be collected by Movey
#[derive(serde::Serialize, Default)]
pub struct MoveyUploadRequest {
github_repo_url: String,
total_files: usize,
token: String,
subdir: String,
}

/// Upload the package metadata to Movey.net.
#[derive(Parser)]
#[clap(name = "movey-upload")]
pub struct MoveyUpload;

impl MoveyUpload {
pub fn execute(self, path: Option<PathBuf>) -> anyhow::Result<()> {
if let Some(path) = path {
if path.exists() && path.is_dir() {
let _ = env::set_current_dir(&path);
} else {
bail!("invalid directory")
}
}
// make sure it's a Move project
let move_toml = File::open("Move.toml");
if move_toml.is_err() {
bail!("Move.toml not found")
}
let metadata = move_toml.unwrap().metadata()?;
if metadata.len() == 0 {
bail!("Move.toml not found")
}

// use git command to get the repository url
let mut movey_upload_request: MoveyUploadRequest = Default::default();
let mut output = Command::new("git")
.current_dir(".")
.args(&["remote", "-v"])
.output()
.unwrap();
if !output.status.success() || output.stdout.is_empty() {
bail!("invalid git repository")
}

let lines = String::from_utf8_lossy(output.stdout.as_slice());
let lines = lines.split("\n");
for line in lines {
if line.contains("github.com") {
let tokens: Vec<&str> = line.split(&['\t', ' '][..]).collect();
if tokens.len() != 3 {
bail!("invalid remote url")
}
// convert ssh url to https
let https_url = if tokens[1].starts_with("git@github.com") {
tokens[1].replace(":", "/").replace("git@", "https://")
} else {
String::from(tokens[1])
};
movey_upload_request.github_repo_url = if https_url.ends_with(".git") {
https_url[..https_url.len() - 4].to_string()
} else {
https_url
};
}
}

// use git command to get the subdir if move package is not on the top level
output = Command::new("git")
.current_dir(".")
.args(&["rev-parse", "--show-prefix"])
.output()
.unwrap();
let subdir = String::from_utf8_lossy(output.stdout.as_slice());
movey_upload_request.subdir = String::from(subdir);

// use git command to count total files
output = Command::new("git")
.current_dir(".")
.args(&["ls-files"])
.output()
.unwrap();
let tracked_files = String::from_utf8_lossy(output.stdout.as_slice());
let tracked_files: Vec<&str> = tracked_files.split("\n").collect();
let mut total_files = tracked_files.len();
for file_path in tracked_files {
if file_path.is_empty() {
total_files -= 1;
continue;
}
}
movey_upload_request.total_files = total_files;
movey_upload_request.token = movey_credential::get_registry_api_token(&MOVE_HOME)?;
let movey_url = movey_credential::get_movey_url(&MOVE_HOME);
match movey_url {
Ok(url) => {
let client = Client::new();
let response = client
.post(&format!("{}/api/v1/packages/upload", &url))
.json(&movey_upload_request)
.send();
match response {
Ok(response) => {
if response.status().is_success() {
println!(
"Your package has been successfully uploaded to Movey at {}/packages/{}.",
url,
response.text()?
);
} else if response.status().is_client_error() {
bail!("{}", response.text()?)
} else if response.status().is_server_error() {
bail!("An unexpected error occurred. Please try again later");
}
}
Err(_) => {
bail!("An unexpected error occurred. Please try again later");
}
}
}
Err(_) => bail!("An unexpected error occurred. Please try again later"),
}
Ok(())
}
}
6 changes: 5 additions & 1 deletion language/tools/move-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use base::{
build::Build, coverage::Coverage, disassemble::Disassemble, docgen::Docgen, errmap::Errmap,
info::Info, movey_login::MoveyLogin, new::New, prove::Prove, test::Test,
info::Info, movey_login::MoveyLogin, movey_upload::MoveyUpload, new::New, prove::Prove,
test::Test,
};
use move_package::BuildConfig;

pub mod base;
pub mod experimental;
pub mod sandbox;
pub mod utils;

/// Default directory where saved Move resources live
pub const DEFAULT_STORAGE_DIR: &str = "storage";
Expand Down Expand Up @@ -68,6 +70,7 @@ pub enum Command {
Docgen(Docgen),
Errmap(Errmap),
Info(Info),
MoveyUpload(MoveyUpload),
New(New),
Prove(Prove),
Test(Test),
Expand Down Expand Up @@ -112,6 +115,7 @@ pub fn run_cli(
Command::Docgen(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Errmap(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Info(c) => c.execute(move_args.package_path, move_args.build_config),
Command::MoveyUpload(c) => c.execute(move_args.package_path),
Command::New(c) => c.execute_with_defaults(move_args.package_path),
Command::Prove(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Test(c) => c.execute(move_args.package_path, move_args.build_config, natives),
Expand Down
4 changes: 4 additions & 0 deletions language/tools/move-cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

pub mod movey_credential;
Loading