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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci tests (#2) #3

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/test-rust.yaml
@@ -0,0 +1,63 @@
name: Test the rust code

on:
pull_request:
push:
branches:
- main

jobs:
build_and_cache_rust:
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v2
- name: Update local toolchain
run: |
rustup update
rustup component add clippy rustfmt
rustup install stable
- name: Toolchain info
run: |
cargo --version --verbose
rustc --version
- name: Cache deps and target
uses: Swatinem/rust-cache@v2
lint:
needs: build_and_cache_rust
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v2
- name: Toolchain info
run: |
cargo --version --verbose
rustc --version
- name: Lint
run: |
cargo fmt -- --check
cargo clippy -- -D warnings
full_ci:
needs: build_and_cache_rust
strategy:
matrix:
toolchain: [ 'stable', 'nightly' ]
os: [ubuntu-22.04, ubuntu-20.04, macos-12, macos-11, windows-2022, windows-2019]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update local toolchain
run: |
rustup update
rustup component add clippy rustfmt
rustup install ${{ matrix.toolchain }}
- name: Toolchain info
run: |
cargo --version --verbose
rustc --version
cargo clippy --version
- name: Run rust tests
run: cargo test --verbose

# Rust target reference: https://doc.rust-lang.org/beta/rustc/platform-support.html#tier-1-with-host-tools
4 changes: 2 additions & 2 deletions src/commands/apply.rs
Expand Up @@ -22,12 +22,12 @@ pub fn run(name: &str, options: ApplyCommands) {
let _ = fs_extra::dir::copy(
&template_dir,
&config.current_dir,
&dir::CopyOptions::from(dir::CopyOptions {
&dir::CopyOptions {
content_only: true,
skip_exist: true,
overwrite: options.overwrite,
..Default::default()
}),
},
)
.map_err(|_| {
eprintln!(
Expand Down
10 changes: 5 additions & 5 deletions src/commands/create.rs
Expand Up @@ -29,10 +29,10 @@ pub fn run(name: &str, options: CreateCommands) {
fs_extra::dir::copy(
&current_dir,
&template_dir,
&dir::CopyOptions::from(dir::CopyOptions {
&dir::CopyOptions {
content_only: true,
..Default::default()
}),
},
)
.expect("Template could not be created based on folder");
}
Expand All @@ -54,13 +54,13 @@ pub fn run(name: &str, options: CreateCommands) {
copy_file_to_template(
&file_path,
&template_dir,
(!file_path.is_dir()).then(|| &file),
(!file_path.is_dir()).then_some(&file),
);
}

println!(
"馃殌 Successfully created cloup {} \n\n{}",
"馃殌 Successfully created cloup {} \n\nApply this cloup with `cloup apply {}`",
&name.to_string().bright_purple(),
format!("Apply this cloup with `cloup apply {}`", &name)
&name,
);
}
2 changes: 1 addition & 1 deletion src/commands/delete.rs
Expand Up @@ -14,7 +14,7 @@ pub fn run(name: &str) {
process::exit(1);
}

if !fs::remove_dir_all(folder).is_ok() {
if fs::remove_dir_all(folder).is_err() {
eprintln!("Was not able to delete template for some reason");
process::exit(1);
}
Expand Down
1 change: 1 addition & 0 deletions src/commands/init.rs
Expand Up @@ -10,6 +10,7 @@ pub fn run(_namespace: Option<String>) {
.join("cloup");

if let Err(e) = fs::create_dir(&config_dirname) {
#[allow(clippy::single_match)]
match e.kind() {
ErrorKind::PermissionDenied => {
eprintln!("Permission denied when creating config directory")
Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Expand Up @@ -59,7 +59,7 @@ pub fn template_dir() -> Result<PathBuf, String> {

pub fn copy_file_to_template(file_path: &PathBuf, template_dir: &PathBuf, file: Option<&String>) {
// If no file is specified, we are working with a folder
if let None = file {
if file.is_none() {
fs_extra::dir::copy(file_path, &template_dir, &dir::CopyOptions::new())
.map_err(|e| {
eprintln!("{}", e);
Expand All @@ -76,15 +76,15 @@ pub fn copy_file_to_template(file_path: &PathBuf, template_dir: &PathBuf, file:
template_path
.parent()
.filter(|p| !p.is_dir())
.map(|p| fs::create_dir_all(p));
.map(fs::create_dir_all);

fs_extra::file::copy(
&file_path,
template_path,
&file::CopyOptions::from(file::CopyOptions {
&file::CopyOptions {
overwrite: true,
..Default::default()
}),
},
)
.map_err(|e| {
fs::remove_dir(&template_dir).expect("Should be allowed to remove dir");
Expand Down