Skip to content

Commit

Permalink
feat: Self CI (#24)
Browse files Browse the repository at this point in the history
Initial for #6
  • Loading branch information
DmitryDodzin authored Dec 13, 2021
1 parent 2e15f40 commit cc525f2
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/non-non.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"mol": patch
"mol-cargo": patch
"mol-core": patch
---

chore: add more error contexts
6 changes: 6 additions & 0 deletions .changeset/quas-repellendus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"mol": patch
"mol-core": patch
---

fix: add root_path to pacakge path before reading
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Rust

on:
push:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 🔥 Cargo Cache
uses: actions/cache@v1
with:
path: ~/.cargo
key: ${{ runner.os }}-version-cargo-${{ hashFiles('Cargo.toml') }}
restore-keys: |
${{ runner.os }}-version-cargo-${{ hashFiles('Cargo.toml') }}
${{ runner.os }}-version-cargo
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install Mol
run: cargo install --path .
- name: Version
run: cargo mol version --no-build
- name: Add & Commit
uses: EndBug/[email protected]
with:
message: Version Packages
branch: mol/release
branch_mode: create
push: '--force --set-upstream origin mol/release'
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches: [ main ]
pull_request:
paths:
- '**/Cargo.toml'
- 'src/**/*.*'
- 'crates/**/*.*'
branches: [ main ]

env:
Expand Down
22 changes: 15 additions & 7 deletions crates/mol-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ use toml_edit::{value, Document};

use mol_core::prelude::*;

fn remove_start_dot(dir: PathBuf) -> PathBuf {
if dir.starts_with("./") {
dir.iter().skip(1).collect()
} else {
dir
}
}

#[derive(Default)]
pub struct Cargo;

Expand All @@ -22,7 +30,7 @@ impl Cargo {
entry: fs::DirEntry,
) -> std::io::Result<Vec<Package<V>>> {
let mut result = Vec::new();
let entry_path = entry.path();
let entry_path = remove_start_dot(entry.path());

if exists.contains(&entry_path) {
return Ok(result);
Expand All @@ -36,16 +44,16 @@ impl Cargo {

if let Ok(file_type) = entry.file_type().await {
if file_type.is_dir() {
return Cargo::check_read_dir(exists, globs, fs::read_dir(&entry_path).await?).await;
return Cargo::check_read_dir(exists, globs, fs::read_dir(entry.path()).await?).await;
}

if file_type.is_symlink() {
let entry_path = fs::read_link(&entry_path).await?;
return Cargo::check_read_dir(exists, globs, fs::read_dir(&entry_path).await?).await;
let link_value = fs::read_link(entry.path()).await?;
return Cargo::check_read_dir(exists, globs, fs::read_dir(&link_value).await?).await;
}

if globs.is_match(entry.path()) && file_type.is_file() && entry.file_name() == "Cargo.toml" {
result.extend(Cargo.read_package(&entry_path).await?);
if globs.is_match(entry_path) && file_type.is_file() && entry.file_name() == "Cargo.toml" {
result.extend(Cargo.read_package(entry.path()).await?);
}
}

Expand Down Expand Up @@ -90,7 +98,7 @@ impl Cargo {
.arg(command)
.args(args)
.spawn()
.expect("cargo command failed to start")
.expect("Cargo command failed to start")
.wait()
.await?;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/mol-core/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Plugin for PluginManager {
for plugin in &self.plugins {
plugin
.pre_command(command, context)
.with_context(|| format!("{}: faliure at pre-command, plugin", plugin.name()))?;
.with_context(|| format!("Faliure at pre-command for {} plugin", plugin.name()))?;
}

Ok(())
Expand All @@ -185,7 +185,7 @@ impl Plugin for PluginManager {
for plugin in &self.plugins {
plugin
.post_command(command, context)
.with_context(|| format!("{}: faliure at post-command", plugin.name()))?;
.with_context(|| format!("Faliure at post-command for {} plugin", plugin.name()))?;
}

Ok(())
Expand Down
11 changes: 10 additions & 1 deletion src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;
use std::sync::Arc;

use anyhow::Context;
use async_trait::async_trait;

use mol_core::prelude::*;
Expand Down Expand Up @@ -45,7 +46,15 @@ where
pub async fn new(root_dir: PathBuf, dry_run: bool) -> anyhow::Result<Self> {
let package_manager = T::default();

let packages = package_manager.read_package(T::default_path()).await?;
let package_path: PathBuf = root_dir
.iter()
.chain(&PathBuf::from(T::default_path()))
.collect();

let packages = package_manager
.read_package(&package_path)
.await
.with_context(|| format!("Could not open read pacakges at dir {:?}", package_path))?;

Ok(ExecutableContext {
changesets: Changesets::default(),
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Debug;
use std::str::FromStr;
use std::sync::Arc;

use anyhow::Context;
use clap::Parser;
use dialoguer::{console, theme::ColorfulTheme};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -71,7 +72,9 @@ where

for plugin in &opts.plugins {
unsafe {
plugin_manager.load(&plugin, &context.as_plugin())?;
plugin_manager
.load(&plugin, &context.as_plugin())
.with_context(|| format!("Could not load plugin at path {}", plugin))?;
}
}

Expand Down

0 comments on commit cc525f2

Please sign in to comment.