-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update with partial implementation of auto-updates
- Loading branch information
Showing
12 changed files
with
332 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
[package] | ||
name = "augmented-dev-cli" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
clap = "^3.0.0-beta.2" | ||
log = "^0.4.14" | ||
wisual-logger = { version = "^0.1.3", path = "../wisual-logger" } | ||
cmd_lib = "^1.1.0" | ||
serde_json = "^1.0" | ||
chrono = "0.4" | ||
serde = { version = "^1.0", features = [ "derive" ] } | ||
toml = "^0.5.8" |
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,26 @@ | ||
use std::process::Command; | ||
|
||
fn main() { | ||
{ | ||
println!( | ||
"cargo:rustc-env=PROFILE={}", | ||
std::env::var("PROFILE").unwrap() | ||
); | ||
} | ||
{ | ||
let output = Command::new("git") | ||
.args(&["rev-parse", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string(); | ||
println!("cargo:rustc-env=GIT_REV={}", git_rev); | ||
} | ||
{ | ||
let output = Command::new("git") | ||
.args(&["rev-parse", "--short", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string(); | ||
println!("cargo:rustc-env=GIT_REV_SHORT={}", git_rev); | ||
} | ||
} |
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,159 @@ | ||
use chrono::prelude::*; | ||
use std::fs::read_to_string; | ||
use std::path::Path; | ||
|
||
use cmd_lib::run_cmd; | ||
|
||
use crate::manifests::{MacosAppConfig, ReleaseJson}; | ||
use manifests::CargoToml; | ||
|
||
mod manifests; | ||
|
||
fn get_cli_version() -> String { | ||
format!( | ||
"{}-{}-{}", | ||
env!("PROFILE"), | ||
env!("CARGO_PKG_VERSION"), | ||
env!("GIT_REV_SHORT") | ||
) | ||
} | ||
|
||
fn get_package_version(pkg_version: &str) -> String { | ||
let output = std::process::Command::new("git") | ||
.args(&["rev-parse", "--short", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string(); | ||
format!("release-{}-{}", pkg_version, git_rev) | ||
} | ||
|
||
fn run_build_release(crate_path: &str) { | ||
let config_path = Path::new(crate_path).join("Cargo.toml"); | ||
let input_cargo_file = read_to_string(config_path).expect("Failed to read toml file"); | ||
let cargo_toml: CargoToml = | ||
toml::from_str(&input_cargo_file).expect("Failed to parse toml file"); | ||
let package_version = get_package_version(&cargo_toml.package.version); | ||
|
||
log::info!("Read Cargo.toml:\n{:#?}", cargo_toml); | ||
log::info!("Forcing a build of \"{}\"", cargo_toml.package.name); | ||
|
||
run_cmd!(cd ${crate_path}; cargo build --release).unwrap(); | ||
let release_json = ReleaseJson { | ||
name: cargo_toml.package.name.clone(), | ||
key: package_version.clone(), | ||
created_at: Utc::now().to_rfc3339(), | ||
}; | ||
log::info!("Release:\n{:#?}", release_json); | ||
|
||
if let Some(local_package) = create_local_package(crate_path, &cargo_toml, &release_json) { | ||
let artifact_path = compress_release(&cargo_toml, local_package); | ||
upload_release(&release_json, artifact_path); | ||
} | ||
} | ||
|
||
fn upload_release(release_json: &ReleaseJson, artifact_path: String) {} | ||
|
||
fn compress_release(cargo_toml: &CargoToml, local_package: LocalPackage) -> String { | ||
let path = local_package.path; | ||
let volume_name = cargo_toml.package.name.clone(); | ||
let dmg_name = format!("{}.dmg", volume_name); | ||
let target_path = { | ||
let path = Path::new(&*path); | ||
let parent = path.parent().unwrap(); | ||
let dmg_path = parent.join(&*dmg_name); | ||
dmg_path.to_str().unwrap().to_string() | ||
}; | ||
|
||
log::info!( | ||
"Creating DMG file VOLUME_NAME={} SOURCE={} TARGET={}", | ||
volume_name, | ||
path, | ||
target_path | ||
); | ||
run_cmd!( | ||
hdiutil create -volname ${volume_name} -srcfolder ${path} -ov -format UDZO ${target_path} | ||
) | ||
.unwrap(); | ||
|
||
target_path | ||
} | ||
|
||
struct LocalPackage { | ||
path: String, | ||
} | ||
|
||
fn create_local_package( | ||
crate_path: &str, | ||
cargo_toml: &CargoToml, | ||
release_json: &ReleaseJson, | ||
) -> Option<LocalPackage> { | ||
let macos_config = cargo_toml | ||
.package | ||
.metadata | ||
.clone() | ||
.map(|m| m.app) | ||
.flatten() | ||
.map(|a| a.macos) | ||
.flatten(); | ||
if let Some(macos_config) = macos_config { | ||
match macos_config { | ||
MacosAppConfig::AppTemplate { template_path } => { | ||
let template_path = Path::new(crate_path).join(template_path); | ||
let base_target_path = | ||
Path::new("./target/apps/macos/").join(cargo_toml.package.name.clone()); | ||
|
||
log::info!( | ||
"Copying template into `{}` directory", | ||
base_target_path.to_str().unwrap() | ||
); | ||
run_cmd!(mkdir -p ${base_target_path}).unwrap(); | ||
run_cmd!(cp -r ${template_path} ${base_target_path}).unwrap(); | ||
|
||
let release_path = | ||
Path::new("./target/release/").join(cargo_toml.package.name.clone()); | ||
let target_app_path = base_target_path.join(template_path.file_name().unwrap()); | ||
run_cmd!(cp ${release_path} ${target_app_path}/Contents/MacOS/).unwrap(); | ||
|
||
let release_json_path = base_target_path.join("release.json"); | ||
log::info!("Outputting {}", release_json_path.to_str().unwrap()); | ||
let release_json_str = serde_json::to_string_pretty(&release_json).unwrap(); | ||
std::fs::write(release_json_path, release_json_str).unwrap(); | ||
|
||
Some(LocalPackage { | ||
path: base_target_path.to_str().unwrap().to_string(), | ||
}) | ||
} | ||
} | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
fn main() { | ||
wisual_logger::init_from_env(); | ||
log::info!( | ||
"Starting augmented-dev-cli VERSION={} GIT_REV={} GIT_REV_SHORT={}", | ||
get_cli_version(), | ||
env!("GIT_REV"), | ||
env!("GIT_REV_SHORT") | ||
); | ||
|
||
let version = get_cli_version(); | ||
let mut app = clap::App::new("augmented-dev-cli") | ||
.version(&*version) | ||
.about("Development CLI for augmented projects, helps build and deploy apps") | ||
.subcommand( | ||
clap::App::new("build-release") | ||
.about("Build a release package for a given app") | ||
.arg(clap::Arg::from("-c, --crate=<PATH> 'Crate path'")), | ||
); | ||
|
||
let matches = app.clone().get_matches(); | ||
if matches.is_present("build-release") { | ||
let matches = matches.subcommand_matches("build-release").unwrap(); | ||
run_build_release(matches.value_of("crate").unwrap()); | ||
} else { | ||
app.print_help().unwrap(); | ||
std::process::exit(1); | ||
} | ||
} |
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,42 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use toml::map::Map; | ||
use toml::Value; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ReleaseJson { | ||
pub name: String, | ||
pub key: String, | ||
pub created_at: String, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[serde(rename_all = "kebab-case")] | ||
#[serde(tag = "type")] | ||
pub enum MacosAppConfig { | ||
#[serde(rename_all = "kebab-case")] | ||
AppTemplate { template_path: String }, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct AppConfig { | ||
pub macos: Option<MacosAppConfig>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct CargoTomlPackageMetadata { | ||
pub app: Option<AppConfig>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct CargoTomlPackage { | ||
pub name: String, | ||
pub description: String, | ||
pub version: String, | ||
pub metadata: Option<CargoTomlPackageMetadata>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct CargoToml { | ||
pub package: CargoTomlPackage, | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Pedro Tacla Yamada | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,26 @@ | ||
use std::process::Command; | ||
|
||
fn main() { | ||
{ | ||
println!( | ||
"cargo:rustc-env=PROFILE={}", | ||
std::env::var("PROFILE").unwrap() | ||
); | ||
} | ||
{ | ||
let output = Command::new("git") | ||
.args(&["rev-parse", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string(); | ||
println!("cargo:rustc-env=GIT_REV={}", git_rev); | ||
} | ||
{ | ||
let output = Command::new("git") | ||
.args(&["rev-parse", "--short", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let git_rev = String::from_utf8(output.stdout).unwrap().trim().to_string(); | ||
println!("cargo:rustc-env=GIT_REV_SHORT={}", git_rev); | ||
} | ||
} |
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
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,9 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -x | ||
|
||
CARGO_PKG_VERSION=$(cat ./crates/plugin-host-gui2/Cargo.toml | grep version | head -n1 | awk '{ print $3 }' | sed 's/"//g') | ||
GIT_REV=$(git rev-parse --short HEAD) | ||
version="release-$CARGO_PKG_VERSION-$GIT_REV" | ||
|
||
echo ">> Building plugin-host-gui2 version=$version" | ||
cargo build --release --package plugin-host-gui2 | ||
|
||
echo ">> Building \"Plugin Host.app\" bundle" | ||
mkdir -p ./target/apps/macos | ||
cp -r "./crates/plugin-host-gui2/macos-app/Plugin Host.app" ./target/apps/macos/ | ||
cp target/release/plugin-host-gui2 "./target/apps/macos/Plugin Host.app/Contents/MacOS/" | ||
cp target/release/plugin-host-gui2 "./target/apps/macos/Plugin Host.app/Contents/MacOS/" | ||
|