Skip to content

Commit ef599c9

Browse files
authored
Fix tools execution (#38)
1 parent 4e3dbae commit ef599c9

File tree

3 files changed

+90
-20
lines changed

3 files changed

+90
-20
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ on:
1010
- master
1111

1212
jobs:
13-
build:
13+
checks:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Rustfmt
20+
run: cargo fmt -- --check
21+
22+
- name: Clippy
23+
run: cargo clippy
1424

25+
build:
1526
runs-on: ubuntu-latest
1627

1728
strategy:
@@ -30,8 +41,16 @@ jobs:
3041
- name: Run tests
3142
run: cargo test --locked --verbose
3243

33-
- name: Rustfmt and Clippy
44+
end-to-end-tests:
45+
runs-on: ubuntu-latest
46+
needs: build
47+
48+
steps:
49+
- uses: actions/checkout@v2
50+
51+
- name: End-to-end tests
3452
run: |
35-
cargo fmt -- --check
36-
cargo clippy
37-
if: matrix.rust_version == 'stable'
53+
cargo install --path .
54+
foreman --version
55+
PATH=$PATH:~/.foreman/bin
56+
./scripts/end-to-end-tests.sh

scripts/end-to-end-tests.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
verify_tool_version () {
6+
echo "verify tool" $1
7+
TOOL_VERSION=$($1 -V)
8+
9+
if [[ $TOOL_VERSION != "$1 $2" ]]; then
10+
echo "version did not match:" $TOOL_VERSION
11+
exit 1
12+
else
13+
echo $1 "is there!"
14+
fi
15+
}
16+
17+
write_foreman_toml () {
18+
echo "[tools]" > foreman.toml
19+
echo "$2 = { $1 = \"$3\", version = \"=$4\" }" >> foreman.toml
20+
}
21+
22+
verify_github_tool () {
23+
write_foreman_toml github $1 $2 $3
24+
foreman install
25+
verify_tool_version $1 $3
26+
rm foreman.toml
27+
28+
# for compatibility, verify that `source` also works
29+
write_foreman_toml source $1 $2 $3
30+
foreman install
31+
verify_tool_version $1 $3
32+
rm foreman.toml
33+
}
34+
35+
verify_gitlab_tool () {
36+
write_foreman_toml gitlab $1 $2 $3
37+
foreman install
38+
verify_tool_version $1 $3
39+
rm foreman.toml
40+
}
41+
42+
verify_github_tool Rojo "rojo-rbx/rojo" "6.0.0"
43+
verify_github_tool remodel "rojo-rbx/remodel" "0.9.1"
44+
verify_github_tool stylua "JohnnyMorganz/stylua" "0.11.3"
45+
46+
verify_gitlab_tool darklua "seaofvoices/darklua" "0.7.0"

src/main.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,16 @@ impl ToolInvocation {
3939
}
4040

4141
fn main() -> Result<(), Box<dyn Error>> {
42-
let app = Options::from_args();
43-
44-
{
45-
let log_filter = match app.verbose {
46-
0 => "warn,foreman=info",
47-
1 => "info,foreman=debug",
48-
2 => "info,foreman=trace",
49-
_ => "trace",
50-
};
51-
52-
let env = env_logger::Env::default().default_filter_or(log_filter);
42+
paths::create()?;
5343

44+
if let Some(invocation) = ToolInvocation::from_env() {
45+
let env = env_logger::Env::new().default_filter_or("foreman=info");
5446
env_logger::Builder::from_env(env)
5547
.format_module_path(false)
5648
.format_timestamp(None)
5749
.format_indent(Some(8))
5850
.init();
59-
}
6051

61-
paths::create()?;
62-
63-
if let Some(invocation) = ToolInvocation::from_env() {
6452
let config = ConfigFile::aggregate()?;
6553

6654
if let Some(tool_spec) = config.tools.get(&invocation.name) {
@@ -145,6 +133,23 @@ struct GitLabAuthCommand {
145133
fn actual_main() -> io::Result<()> {
146134
let options = Options::from_args();
147135

136+
{
137+
let log_filter = match options.verbose {
138+
0 => "warn,foreman=info",
139+
1 => "info,foreman=debug",
140+
2 => "info,foreman=trace",
141+
_ => "trace",
142+
};
143+
144+
let env = env_logger::Env::default().default_filter_or(log_filter);
145+
146+
env_logger::Builder::from_env(env)
147+
.format_module_path(false)
148+
.format_timestamp(None)
149+
.format_indent(Some(8))
150+
.init();
151+
}
152+
148153
match options.subcommand {
149154
Subcommand::Install => {
150155
let config = ConfigFile::aggregate()?;

0 commit comments

Comments
 (0)