Skip to content
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

Feature/version support #9

Merged
merged 4 commits into from
Jun 9, 2021
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
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: build punic

on:
push:
branches:
- master


jobs:
build_and_test:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions-rs/cargo@v1
with:
command: build
args: --release --all-features
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target
.DS_Store
.idea

/Carthage
*.orig
/Carthage
3 changes: 2 additions & 1 deletion Punfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ configuration:
s3Bucket: shred-ios-carthage-cache
dependencies:
- Alamofire:
- name: Alamofire
- name: Alamofire
version: 1.0.0
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate shellexpand;
extern crate tokio;

use crate::punfile::parse_pun_file;
use crate::punfile::print_pun_deps;
use crate::utils::download::download_dependencies;
use crate::utils::upload::upload_dependencies;
use clap::{App, Arg};
Expand All @@ -27,6 +28,7 @@ async fn main() {
.about("ios dependency caching made great again")
.author("Johnson Cheung")
.subcommand(

App::new("download")
.about("scan your punfile and download dependencies")
.arg(
Expand Down Expand Up @@ -88,7 +90,10 @@ async fn main() {
.takes_value(true),
),
)
.get_matches();
.subcommand(
App::new("list")
.about("list parsed out dependencies from punfile"),
).get_matches();

let punfile = parse_pun_file(matches.borrow());
let local_cache = punfile.configuration.local.clone();
Expand All @@ -105,5 +110,8 @@ async fn main() {
download_dependencies(punfile, matches, cache_dir).await;
} else if let Some(ref matches) = matches.subcommand_matches("upload") {
upload_dependencies(punfile, matches, cache_dir).await;
} else if let Some(ref matches) = matches.subcommand_matches("list"){
print_pun_deps(&punfile);
}

}
22 changes: 21 additions & 1 deletion src/punfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod data {
pub struct Repository {
pub repo_name: String,
pub name: String,
pub version: String
}
}

Expand Down Expand Up @@ -60,7 +61,7 @@ pub fn parse_pun_file(matches: &ArgMatches) -> punfile::data::PunFile {
println!("Cache Prefix\t\t: {}", punfile.configuration.prefix);
println!("Cache Local Path\t: {}", punfile.configuration.local);
println!("Cache Output Path\t: {}", punfile.configuration.output);
println!("S3 Bucket\t\t: {}", punfile.configuration.s3_bucket);
println!("S3 Bucket\t\t: {} \n", punfile.configuration.s3_bucket);

let repository_map = contents_yaml
.get("dependencies")
Expand All @@ -77,9 +78,11 @@ pub fn parse_pun_file(matches: &ArgMatches) -> punfile::data::PunFile {
.as_mapping()
.unwrap()
.get(&serde_yaml::Value::from("name"));
let version = seq.as_mapping().unwrap().get(&serde_yaml::Value::from("version"));
let repository = Repository {
repo_name: String::from(repo_name),
name: String::from(map_name.unwrap().as_str().unwrap()),
version: String::from(version.unwrap_or(&serde_yaml::Value::String("".into())).as_str().unwrap())
};
punfile.frameworks.push(repository);
}
Expand Down Expand Up @@ -109,3 +112,20 @@ fn get_cache_prefix(matches: &ArgMatches, configuration: &Value) -> String {
punfile_prefix.to_string()
}
}


pub fn print_pun_deps(punfile: &PunFile) {
let frameworks = &punfile.frameworks;
println!("Listing dependencies in Punfile");

frameworks.iter().enumerate().for_each(|(i, framework)|{
println!("{}. Group: {}, Artifact: {}, Version: {}",
i + 1,
framework.repo_name,
framework.name,
framework.version);

});

}

6 changes: 6 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ pub mod archive;
pub mod download;
pub mod scan;
pub mod upload;






3 changes: 2 additions & 1 deletion src/utils/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ where
}

pub fn extract_zip(root: &str, path: &str, dest: &str) {

println!("Unzipping {}...", path);
let file = fs::File::open(path).unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();

println!("Unzipping {}...", path);

for i in 0..archive.len() {
let mut file = archive.by_index(i).unwrap();
Expand Down
9 changes: 8 additions & 1 deletion src/utils/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub async fn download_dependencies<'a>(
.map(|it| Repository {
repo_name: String::from(it),
name: String::from(it),
version: String::from(it)
})
.collect();
let mut frameworks = punfile.frameworks;
Expand All @@ -35,6 +36,7 @@ pub async fn download_dependencies<'a>(
filtered_frameworks.push(Repository {
repo_name: frame.repo_name.to_string(),
name: frame.name.to_string(),
version: frame.version.to_string()
});
}
}
Expand All @@ -45,6 +47,7 @@ pub async fn download_dependencies<'a>(
let output = punfile.configuration.output.clone();
let cache_prefix = punfile.configuration.prefix.clone();
let framework_name = format!("{}.xcframework", dependencies.name);
let version = dependencies.version.clone();
let xcf_cache_dir = format!(
"{}/build/{}/{}.xcframework.zip",
cache_dir, cache_prefix, dependencies.name
Expand All @@ -59,7 +62,11 @@ pub async fn download_dependencies<'a>(
println!("Ignoring {}", xcf_cache_dir);
}
let s3_bucket = punfile.configuration.s3_bucket.clone();
let prefix = cache_prefix.clone();
let prefix = match dependencies.version.as_str() {
"" => cache_prefix.clone(),
_ => format!("{}/{}",cache_prefix.clone(), version.clone())
};

let task = tokio::spawn(async move {
cache::s3::download_from_s3(
xcf_cache_dir.to_string(),
Expand Down
31 changes: 30 additions & 1 deletion src/utils/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::borrow::Cow;
use std::fs::File;
use std::path::Path;
use walkdir::WalkDir;
use crate::punfile::data::Repository;
use std::collections::HashMap;



pub async fn upload_dependencies<'a>(
punfile: PunFile,
Expand All @@ -20,6 +24,7 @@ pub async fn upload_dependencies<'a>(
.unwrap_or(Values::default())
.collect();
let mut frameworks = scan_xcframeworks(punfile.configuration.output.clone());

if !requested_frameworks.is_empty() {
let mut filtered_frameworks: Vec<String> = Vec::new();
for dep in &requested_frameworks {
Expand All @@ -37,10 +42,34 @@ pub async fn upload_dependencies<'a>(
let output = punfile.configuration.output.clone();
let cache_prefix = punfile.configuration.prefix.clone();
let bucket_name = punfile.configuration.s3_bucket.clone();
println!("Found {}/{}", &output, frame);
let default_repo = Repository {
name: "".to_string(),
repo_name: "".to_string(),
version: "".to_string()
};

let expanded_frameworks: Vec<&str> = frame.split(".").collect();


let framework_key = expanded_frameworks.get(0).unwrap();

let framework = punfile.frameworks.iter().find(|item| item.name.contains(framework_key)).unwrap_or(&default_repo);

if framework.version.is_empty() {
println!("Found {}/{}", &output, frame);
} else {
println!("Found {}/{} @version {}", &output, frame, framework.version);
}

let src_dir = format!("{}/{}", output, frame);
let dest_dir = { format!("{}/build/{}/{}.zip", expanded_str, cache_prefix, frame) };
let prefix = cache_prefix.clone();
let version = framework.version.clone();
let _empty_string = String::from("");
let prefix = match framework.version.as_str() {
"" => cache_prefix.clone(),
_ => format!("{}/{}",cache_prefix.clone(),version)
};
// If the cache does not exist or we're ignoring the cache -> zip the files
if ignore_local_cache || !Path::new(&dest_dir).exists() {
let dest = dest_dir.clone();
Expand Down