Skip to content

Commit f72867a

Browse files
authored
Merge pull request #5 from reaganmcf/new_ci
New CI workflow
2 parents f0529e7 + f99842a commit f72867a

File tree

7 files changed

+327
-183
lines changed

7 files changed

+327
-183
lines changed

.github/workflows/ci.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master, staging, trying]
5+
pull_request:
6+
branches: [master]
7+
types: [opened, reopened, synchronize]
8+
jobs:
9+
ci:
10+
name: CI
11+
needs: [test, lint]
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Done
15+
run: exit 0
16+
prepare:
17+
name: Prepare
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: fkirc/skip-duplicate-actions@master
21+
with:
22+
github_token: ${{ github.token }}
23+
test:
24+
name: Tests
25+
needs: [prepare]
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
rust: [1.46.0, stable, beta]
30+
os: [windows-latest, macos-latest, ubuntu-latest]
31+
target:
32+
- i686-pc-windows-msvc
33+
- x86_64-pc-windows-msvc
34+
- x86_64-unknown-linux-gnu
35+
- i686-unknown-linux-gnu
36+
- x86_64-apple-darwin
37+
features:
38+
- release
39+
exclude:
40+
- features: release
41+
rust: stable
42+
- features: release
43+
rust: beta
44+
- os: windows-latest
45+
target: x86_64-apple-darwin
46+
- os: windows-latest
47+
target: x86_64-unknown-linux-gnu
48+
- os: windows-latest
49+
target: i686-unknown-linux-gnu
50+
- os: macos-latest
51+
target: i686-pc-windows-msvc
52+
- os: macos-latest
53+
target: x86_64-pc-windows-msvc
54+
- os: macos-latest
55+
target: x86_64-unknown-linux-gnu
56+
- os: macos-latest
57+
target: i686-unknown-linux-gnu
58+
- os: ubuntu-latest
59+
target: i686-pc-windows-msvc
60+
- os: ubuntu-latest
61+
target: x86_64-pc-windows-msvc
62+
- os: ubuntu-latest
63+
target: x86_64-apple-darwin
64+
runs-on: ${{ matrix.os }}
65+
steps:
66+
- name: Install rust
67+
uses: actions-rs/toolchain@v1
68+
with:
69+
profile: minimal
70+
toolchain: ${{ matrix.rust }}
71+
target: ${{ matrix.target }}
72+
override: true
73+
- name: Checkout
74+
uses: actions/checkout@v2
75+
- name: Install linker
76+
if: matrix.target == 'i686-unknown-linux-gnu'
77+
run: |
78+
sudo apt-get update
79+
sudo apt-get install gcc-multilib
80+
- name: Test all features
81+
uses: actions-rs/cargo@v1
82+
with:
83+
command: test
84+
args: --target ${{ matrix.target }}
85+
- name: Check debug statement
86+
uses: actions-rs/cargo@v1
87+
with:
88+
command: check
89+
args: --target ${{ matrix.target }}
90+
- name: Test release
91+
uses: actions-rs/cargo@v1
92+
if: matrix.features == 'release'
93+
with:
94+
command: test
95+
args: --target ${{ matrix.target }}
96+
nightly:
97+
name: Nightly Tests
98+
needs: [prepare]
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: Install rust
102+
uses: actions-rs/toolchain@v1
103+
with:
104+
toolchain: nightly
105+
override: true
106+
- name: Checkout
107+
uses: actions/checkout@v2
108+
- name: Test all features
109+
uses: actions-rs/cargo@v1
110+
with:
111+
command: test
112+
lint:
113+
name: Linting (fmt + clippy)
114+
needs: [prepare]
115+
runs-on: ubuntu-latest
116+
steps:
117+
- name: Install rust
118+
uses: actions-rs/toolchain@v1
119+
with:
120+
profile: minimal
121+
toolchain: stable
122+
override: true
123+
components: rustfmt, clippy
124+
- name: Checkout
125+
uses: actions/checkout@v2
126+
- name: Clippy for all features
127+
uses: actions-rs/cargo@v1
128+
with:
129+
command: clippy
130+
args: -- -D warnings
131+
- name: Format check
132+
uses: actions-rs/cargo@v1
133+
with:
134+
command: fmt
135+
args: -- --check

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ A lightweight, cross-platform, language-agnostic "run code on file change" tool,
88
<p align="left">
99
<img src="https://img.shields.io/static/v1?label=status&message=In%20Development&color=critical"/>
1010
<img src="https://img.shields.io/crates/v/lightmon"/>
11-
<img src="https://github.com/reaganmcf/lightmon/actions/workflows/ubuntu.yml/badge.svg"/>
12-
<img src="https://github.com/reaganmcf/lightmon/actions/workflows/macos.yml/badge.svg"/>
13-
<img src="https://github.com/reaganmcf/lightmon/actions/workflows/windows.yml/badge.svg"/>
11+
<img src="https://github.com/reaganmcf/lightmon/actions/workflows/ci.yml/badge.svg"/>
1412
<img src="https://shields.io/github/license/reaganmcf/lightmon"/>
1513
</p>
1614

src/cli.rs

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,88 @@ use log::LevelFilter;
44

55
#[derive(Debug)]
66
pub enum SupportedLanguage {
7-
Rust,
8-
Node,
9-
Shell
7+
Rust,
8+
Node,
9+
Shell,
1010
}
1111

1212
impl std::fmt::Display for SupportedLanguage {
13-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14-
match self {
15-
SupportedLanguage::Rust => write!(f, "rust"),
16-
SupportedLanguage::Node => write!(f, "node"),
17-
SupportedLanguage::Shell => write!(f, "shell")
13+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14+
match self {
15+
SupportedLanguage::Rust => write!(f, "rust"),
16+
SupportedLanguage::Node => write!(f, "node"),
17+
SupportedLanguage::Shell => write!(f, "shell"),
18+
}
1819
}
19-
}
2020
}
2121

2222
#[derive(Debug)]
2323
pub struct Cli {
24-
pub watch_patterns: Vec<String>, // file patterns to watch
25-
pub project_language: SupportedLanguage,
26-
pub exec_commands: Vec<String>, // list of commands to run
24+
pub watch_patterns: Vec<String>, // file patterns to watch
25+
pub project_language: SupportedLanguage,
26+
pub exec_commands: Vec<String>, // list of commands to run
2727
}
2828

2929
impl Cli {
30-
pub fn new() -> Self {
31-
let yaml = load_yaml!("cli.yaml");
32-
let matches: ArgMatches = App::from_yaml(yaml).get_matches();
33-
34-
if matches.is_present("verbose") {
35-
Builder::new().filter_level(LevelFilter::Debug).init();
36-
} else {
37-
Builder::new().filter_level(LevelFilter::Info).init();
38-
}
39-
40-
let mut watch_patterns: Vec<String> = Vec::new();
41-
let project_language: SupportedLanguage;
42-
let mut exec_commands: Vec<String> = Vec::new();
43-
44-
match matches.subcommand(){
45-
("rust", Some(_)) =>{
46-
debug!("Configuring for rust mode...");
47-
project_language = SupportedLanguage::Rust;
48-
watch_patterns.push("*.rs".to_string());
49-
watch_patterns.push("Cargo.toml".to_string());
50-
exec_commands.push("cargo build".to_string());
51-
exec_commands.push("cargo run".to_string());
52-
},
53-
("node", Some(_)) =>{
54-
debug!("Configuring for node mode...");
55-
project_language = SupportedLanguage::Node;
56-
watch_patterns.push("*.js".to_string());
57-
watch_patterns.push("*.jsx".to_string());
58-
exec_commands.push("npm start".to_string());
59-
},
60-
("python", Some(_)) =>{
61-
error!("Argument configuration not yet supported!");
62-
std::process::exit(1);
63-
},
64-
("shell", Some(sub_matcher)) => {
65-
debug!("Configuring for shell mode...");
66-
project_language = SupportedLanguage::Shell;
67-
debug!("Script Path = {:?}", sub_matcher.value_of("script"));
68-
debug!("Watch Pattern = {:?}", sub_matcher.value_of("watch"));
69-
let split = sub_matcher.value_of("watch").unwrap().split(",");
70-
for s in split{
71-
watch_patterns.push(format!("*{}", s.to_string()));
30+
pub fn new() -> Self {
31+
let yaml = load_yaml!("cli.yaml");
32+
let matches: ArgMatches = App::from_yaml(yaml).get_matches();
33+
34+
if matches.is_present("verbose") {
35+
Builder::new().filter_level(LevelFilter::Debug).init();
36+
} else {
37+
Builder::new().filter_level(LevelFilter::Info).init();
7238
}
73-
exec_commands.push(format!("bash {}",sub_matcher.value_of("script").unwrap()).to_string());
74-
debug!("{:?}", exec_commands);
75-
},
76-
_ => {
77-
error!("Argument configuration not yet supported!");
78-
std::process::exit(1);
79-
}
8039

81-
}
82-
83-
let ret = Cli { watch_patterns, project_language, exec_commands };
84-
debug!("Parsed params = {:?}", ret);
40+
let mut watch_patterns: Vec<String> = Vec::new();
41+
let project_language: SupportedLanguage;
42+
let mut exec_commands: Vec<String> = Vec::new();
8543

86-
ret
87-
}
44+
match matches.subcommand() {
45+
("rust", Some(_)) => {
46+
debug!("Configuring for rust mode...");
47+
project_language = SupportedLanguage::Rust;
48+
watch_patterns.push("*.rs".to_string());
49+
watch_patterns.push("Cargo.toml".to_string());
50+
exec_commands.push("cargo build".to_string());
51+
exec_commands.push("cargo run".to_string());
52+
}
53+
("node", Some(_)) => {
54+
debug!("Configuring for node mode...");
55+
project_language = SupportedLanguage::Node;
56+
watch_patterns.push("*.js".to_string());
57+
watch_patterns.push("*.jsx".to_string());
58+
exec_commands.push("npm start".to_string());
59+
}
60+
("python", Some(_)) => {
61+
error!("Argument configuration not yet supported!");
62+
std::process::exit(1);
63+
}
64+
("shell", Some(sub_matcher)) => {
65+
debug!("Configuring for shell mode...");
66+
project_language = SupportedLanguage::Shell;
67+
debug!("Script Path = {:?}", sub_matcher.value_of("script"));
68+
debug!("Watch Pattern = {:?}", sub_matcher.value_of("watch"));
69+
let split = sub_matcher.value_of("watch").unwrap().split(',');
70+
for s in split {
71+
watch_patterns.push(format!("*{}", s.to_string()));
72+
}
73+
exec_commands.push(format!("bash {}", sub_matcher.value_of("script").unwrap()));
74+
debug!("{:?}", exec_commands);
75+
}
76+
_ => {
77+
error!("Argument configuration not yet supported!");
78+
std::process::exit(1);
79+
}
80+
}
81+
82+
let ret = Cli {
83+
watch_patterns,
84+
project_language,
85+
exec_commands,
86+
};
87+
debug!("Parsed params = {:?}", ret);
88+
89+
ret
90+
}
8891
}

src/exec.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
use std::{thread};
21
use std::process::{Command, Stdio};
32
use std::sync::Arc;
3+
use std::thread;
44

55
pub use crate::cli::Cli;
66
pub use crate::LightmonEvent;
77

88
pub fn start(cli_args: Arc<Cli>) -> std::thread::JoinHandle<()> {
9-
let exec_thread = thread::spawn(move|| {
10-
debug!("thread started");
9+
thread::spawn(move || {
10+
debug!("thread started");
1111

12-
// Build commands from exec commands
13-
for exec_command in &cli_args.exec_commands {
14-
// split into components
15-
let split: Vec<&str> = exec_command.split(" ").collect();
16-
let mut cmd = Command::new(split[0]);
17-
for i in 1..split.len() {
18-
cmd.arg(split[i]);
19-
}
12+
// Build commands from exec commands
13+
for exec_command in &cli_args.exec_commands {
14+
// split into components
15+
let split: Vec<&str> = exec_command.split(' ').collect();
16+
let mut cmd = Command::new(split[0]);
17+
for argument in split.iter().skip(1) {
18+
cmd.arg(argument);
19+
}
2020

21-
debug!("final cmd = {:?}", cmd);
22-
let output = cmd.stdout(Stdio::inherit()).output().unwrap();
23-
debug!("{:?}", output);
24-
}
25-
26-
});
27-
return exec_thread;
21+
debug!("final cmd = {:?}", cmd);
22+
let output = cmd.stdout(Stdio::inherit()).output().unwrap();
23+
debug!("{:?}", output);
24+
}
25+
})
2826
}
29-

0 commit comments

Comments
 (0)