Skip to content

Commit 3314ca8

Browse files
authored
ci: Pull Request workflow. (#9)
* ci: Pull Request workflow. - build - test - clippy - fmt * lint: Use try_for_each. * Add windows release target. * target: Disable auto_table_width on Windows. This ascii_table feature depends on termion, which does not support windows.
1 parent 2dc9580 commit 3314ca8

File tree

5 files changed

+86
-28
lines changed

5 files changed

+86
-28
lines changed

.github/workflows/pull_request.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
on:
2+
push:
3+
branches:
4+
main
5+
pull_request:
6+
branches:
7+
main
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-test-lint-and-fmt:
12+
name: "Build and Test"
13+
runs-on: ${{ matrix.config.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
config:
18+
- os: ubuntu-latest
19+
rust_target: x86_64-unknown-linux-gnu
20+
- os: macos-latest
21+
rust_target: aarch64-apple-darwin
22+
- os: windows-latest
23+
rust_target: x86_64-pc-windows-msvc
24+
steps:
25+
- uses: actions/checkout@v3
26+
- name: Setup Rust
27+
uses: dtolnay/rust-toolchain@stable
28+
with:
29+
targets: ${{ matrix.config.rust_target }}
30+
- uses: Swatinem/rust-cache@v2
31+
with:
32+
key: ${{ matrix.config.rust_target }}
33+
- name: Build
34+
run: cargo build --tests
35+
- name: Test
36+
run: cargo test
37+
- name: Clippy
38+
# Use bash to support backslash newline escapes.
39+
shell: bash
40+
run: |
41+
cargo clippy -- \
42+
--no-deps \
43+
-D warnings \
44+
-W clippy::unwrap_used \
45+
-W clippy::expect_used \
46+
-A clippy::result_large_err
47+
- name: Format Check
48+
run: cargo fmt -- --check --verbose

.github/workflows/release.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ on:
44
push:
55
tags:
66
- "v*.*.*"
7-
workflow_dispatch:
87

98
permissions:
109
contents: write
1110

1211
jobs:
13-
build:
14-
name: Building for ${{ matrix.config.os }}
12+
build-and-release:
13+
name: Building for ${{ matrix.config.os }} and Release
1514
runs-on: ${{ matrix.config.os }}
1615

1716
strategy:
@@ -27,9 +26,9 @@ jobs:
2726
- os: macos-latest
2827
rust_target: aarch64-apple-darwin
2928
ext: ""
30-
# - os: windows-latest
31-
# rust_target: x86_64-pc-windows-msvc
32-
# ext: ".exe"
29+
- os: windows-latest
30+
rust_target: x86_64-pc-windows-msvc
31+
ext: ".exe"
3332

3433
steps:
3534
- uses: actions/checkout@v3

Cargo.lock

Lines changed: 16 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ bin-dir = "{ name }-{ version }-{ target }/{ bin }{ binary-ext }"
1717
pkg-fmt = "tgz"
1818

1919
[dependencies]
20-
ascii_table = { version = "4.0.3", features = ["auto_table_width"] }
2120
clap = { version = "4.4.6", features = ["derive", "wrap_help"] }
22-
clap-verbosity-flag = "2.1.0"
2321
clap_complete = { version = "4.4.4", optional = true }
22+
clap-verbosity-flag = "2.1.0"
2423
dirs = "5.0.1"
2524
env_logger = "0.10.1"
2625
human_format = "1.0.3"
@@ -34,6 +33,12 @@ serde_json = { version = "1.0.107", features = ["preserve_order"] }
3433
serde_jsonc = { version = "1.0.107", features = ["preserve_order"] }
3534
tar = "0.4.40"
3635

36+
[target.'cfg(windows)'.dependencies]
37+
ascii_table = "4.0.3"
38+
39+
[target.'cfg(unix)'.dependencies]
40+
ascii_table = { version = "4.0.3", features = ["auto_table_width"] }
41+
3742
[features]
3843
default = ["completions"]
3944
completions = ["dep:clap_complete"]

src/registry.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,16 @@ impl Display for LifecycleHook {
6666
LifecycleHook::Single(value) => write!(f, "{value}"),
6767
LifecycleHook::Multiple(values) => write!(f, "{}", values.join(", ")),
6868
LifecycleHook::Named(values) => {
69-
values.iter().enumerate().fold(Ok(()), |r, (index, (key, value))| {
70-
r.and_then(|_| {
71-
let join = if index == 0 { "" } else { "; " };
72-
match value.as_ref() {
73-
LifecycleHook::Single(v) => write!(f, "{join}{key}={v}"),
74-
LifecycleHook::Multiple(vs) => {
75-
write!(f, "{join}{key}={}", vs.join(", "))
76-
},
77-
// Only a single level of nesting makes sense.
78-
LifecycleHook::Named(_) => Err(fmt::Error),
79-
}
80-
})
69+
values.iter().enumerate().try_for_each(|(index, (key, value))| {
70+
let join = if index == 0 { "" } else { "; " };
71+
match value.as_ref() {
72+
LifecycleHook::Single(v) => write!(f, "{join}{key}={v}"),
73+
LifecycleHook::Multiple(vs) => {
74+
write!(f, "{join}{key}={}", vs.join(", "))
75+
},
76+
// Only a single level of nesting makes sense.
77+
LifecycleHook::Named(_) => Err(fmt::Error),
78+
}
8179
})
8280
},
8381
}

0 commit comments

Comments
 (0)