Skip to content

Commit

Permalink
Changes required for github actions (#18)
Browse files Browse the repository at this point in the history
Updated version and enabled docker mode
  • Loading branch information
tapishr authored Feb 5, 2023
1 parent 59ee543 commit 10e023a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 38 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: [push]
jobs:
profile:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Profiler
uses: ./ # Uses an action in the root directory
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# dev-profiler
Showcase the most meaningful insights from your code contributions
Showcase the most meaningful insights from your code contributions
4 changes: 2 additions & 2 deletions devprofiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "devprofiler"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["Tapish Rathore <[email protected]>"]
license = "GPL-3.0-or-later"
Expand All @@ -16,7 +16,7 @@ categories = ["command-line-utilities"]
[dependencies]
git2 = {version = "0.15", default-features = false, features= ["vendored-libgit2"]}
detect-lang = "0.1.5"
clap = {version = "4.0.29", features = ["derive"]}
clap = {version = "4.1.4", features = ["derive"]}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
flate2 = "1.0"
Expand Down
122 changes: 89 additions & 33 deletions devprofiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ use serde::Serialize;
use std::collections::HashSet;
use std::io::Write;
use std::io;
use clap::Parser;

#[derive(Parser)]
struct Cli {
/// Specify arg parsing mode for cli
argmode: Option<String>
}

#[derive(Debug, Serialize, Default)]
struct UserAlias {
Expand All @@ -26,7 +33,6 @@ fn process_repos(user_paths: Vec::<String>, einfo: &mut RuntimeInfo, writer: &mu
let num_user_path = user_paths.len();
let mut count = 0;
// TODO - optimize count and iterating of vector user_path, get index in for loop
println!("");
for p in user_paths {
count += 1;
print!("Scanning [{count}/{num_user_path}] \r");
Expand All @@ -51,7 +57,6 @@ fn process_repos(user_paths: Vec::<String>, einfo: &mut RuntimeInfo, writer: &mu
}
}
}
println!("");
if valid_repo == 0 {
let err_line = "Unable to parse any provided repo(s)";
eprintln!("{err_line}");
Expand All @@ -62,10 +67,10 @@ fn process_repos(user_paths: Vec::<String>, einfo: &mut RuntimeInfo, writer: &mu
alias_vec
}

fn process_aliases(alias_vec: Vec::<String>, einfo: &mut RuntimeInfo, writer: &mut OutputWriter) {
match UserInput::alias_selector(alias_vec) {
Ok(user_aliases) => {
let alias_obj = UserAlias{ alias: user_aliases };
fn process_aliases(alias_vec: Vec::<String>, einfo: &mut RuntimeInfo, writer: &mut OutputWriter, dockermode: bool) {
match dockermode {
true => {
let alias_obj = UserAlias{ alias: alias_vec };
let alias_str = serde_json::to_string(&alias_obj).unwrap_or_default();
match writer.writeln(alias_str.as_str().as_ref()) {
Ok(_) => {},
Expand All @@ -76,49 +81,100 @@ fn process_aliases(alias_vec: Vec::<String>, einfo: &mut RuntimeInfo, writer: &m
process::exit(1);
}
}
}
Err(error) => {
eprintln!("Unable to process user aliases : {:?}", error);
einfo.record_err(error.to_string().as_str().as_ref());
let _res = writer.finish(); // result doesn't matter since already in error
process::exit(1);
}
false => {
match UserInput::alias_selector(alias_vec) {
Ok(user_aliases) => {
let alias_obj = UserAlias{ alias: user_aliases };
let alias_str = serde_json::to_string(&alias_obj).unwrap_or_default();
match writer.writeln(alias_str.as_str().as_ref()) {
Ok(_) => {},
Err(writer_err) => {
eprintln!("Unable to record user aliases in output file : {writer_err}");
einfo.record_err(writer_err.to_string().as_str().as_ref());
let _res = writer.finish(); // result doesn't matter since already in error
process::exit(1);
}
}
}
Err(error) => {
eprintln!("Unable to process user aliases : {:?}", error);
einfo.record_err(error.to_string().as_str().as_ref());
let _res = writer.finish(); // result doesn't matter since already in error
process::exit(1);
}
}
}
}

}

fn main() {
match UserInput::scan_path() {
Ok(scan_path_str) => {
match OutputWriter::new(){
Ok(mut writer) => {
let args = Cli::parse();
let mut dockermode = false;
match args.argmode {
Some(argval) => {
if argval == "docker" {
dockermode = true;
}
}
None => {}
}
match OutputWriter::new() {
Ok(mut writer) => {
match dockermode {
true => {
let writer_mut: &mut OutputWriter = &mut writer;
let einfo = &mut RuntimeInfo::new();
let scan_pathbuf = Path::new(&scan_path_str).to_path_buf();
let scan_pathbuf = Path::new("/").to_path_buf();
let rscanner = RepoScanner::new(scan_pathbuf);
let pathsvec = rscanner.scan(einfo, writer_mut);
match UserInput::repo_selection(pathsvec) {
Ok(user_paths) => {
let alias_vec = process_repos(user_paths, einfo, writer_mut);
process_aliases(alias_vec, einfo, writer_mut);
let _res = einfo.write_runtime_info(writer_mut);
match writer.finish() {
Ok(_) => {
println!("Profile generated as devprofile.jsonl.gz, proceed to https://devprofiler.tech/upload to upload!");
let pathsvec = rscanner.scan(einfo, writer_mut, dockermode);
let alias_vec = process_repos(pathsvec, einfo, writer_mut);
process_aliases(alias_vec, einfo, writer_mut, dockermode);
let _res = einfo.write_runtime_info(writer_mut);
match writer.finish() {
Ok(_) => {
println!("Profile generated as devprofile.jsonl.gz, proceed to https://devprofiler.tech/upload to upload!");
},
Err(error) => {
eprintln!("Unable to write to output : {error}");
}
}
}
false => {
match UserInput::scan_path() {
Ok(scan_path_str) => {
let writer_mut: &mut OutputWriter = &mut writer;
let einfo = &mut RuntimeInfo::new();
let scan_pathbuf = Path::new(&scan_path_str).to_path_buf();
let rscanner = RepoScanner::new(scan_pathbuf);
let pathsvec = rscanner.scan(einfo, writer_mut, dockermode);
match UserInput::repo_selection(pathsvec) {
Ok(user_paths) => {
let alias_vec = process_repos(user_paths, einfo, writer_mut);
process_aliases(alias_vec, einfo, writer_mut, dockermode);
let _res = einfo.write_runtime_info(writer_mut);
match writer.finish() {
Ok(_) => {
println!("Profile generated as devprofile.jsonl.gz, proceed to https://devprofiler.tech/upload to upload!");
},
Err(error) => {
eprintln!("Unable to write to output : {error}");
}
}
},
Err(error) => {
eprintln!("Unable to write to output : {error}");
eprintln!("Unable to process repository selection : {error}");
}
}
}
},
Err(error) => {
eprintln!("Unable to process repository selection : {error}");
eprintln!("Unable to write to present directory : {error}");
}
}
},
Err(error) => {
eprintln!("Unable to write to present directory : {error}");
}
}
}

},
Err(error) => {
eprintln!("Unable to start application : {error}");
Expand Down
6 changes: 4 additions & 2 deletions devprofiler/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl RepoScanner {
Self { scanpath }
}

pub fn scan(&self, einfo: &mut RuntimeInfo, writer: &mut OutputWriter) -> Vec<String>{
pub fn scan(&self, einfo: &mut RuntimeInfo, writer: &mut OutputWriter, dockermode: bool) -> Vec<String>{
let walker = WalkDir::new(self.scanpath.as_path()).into_iter();
let mut repo_paths = Vec::<String>::new();
let mut scan_err = false;
Expand All @@ -41,7 +41,9 @@ impl RepoScanner {
})
{
count += 1;
Self::print_progress(count);
if !dockermode {
Self::print_progress(count);
}
let path = entry.path();
if path.ends_with(".git") {
repo_paths.push(
Expand Down

0 comments on commit 10e023a

Please sign in to comment.