Merge pull request #720 from ClementTsang/ci_shortening

Cleaned up and updated the primary GitHub CI workflow. Also fixes a bug caught during this check.
This commit is contained in:
Clement Tsang 2022-05-01 17:08:53 -04:00 committed by GitHub
commit c44e860af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 195 deletions

View File

@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
- name: Install toolchain
uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # https://github.com/actions-rs/toolchain/commit/88dc2356392166efad76775c878094f4e83ff746

View File

@ -3,6 +3,11 @@
# CI pipeline based on:
# - https://github.com/heim-rs/heim/blob/master/.github/workflows/ci.yml
# - https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/ci.yml
#
# CI pipeline should do:
# - cargo fmt on supported platforms
# - cargo test on supported platforms, cargo check on unsupported
# - cargo clippy after (apparently faster) on supported platforms
name: ci
@ -16,6 +21,7 @@ on:
env:
CARGO_INCREMENTAL: 0
CARGO_PROFILE_DEV_DEBUG: 0
CARGO_HUSKY_DONT_INSTALL_HOOKS: true
jobs:
rustfmt:
@ -28,13 +34,14 @@ jobs:
- macOS-latest
- windows-2019
steps:
- id: skip_check
- name: Check if this action should be skipped
id: skip_check
uses: fkirc/skip-duplicate-actions@38c3738dcac87b41e2b7038775457756c793566e # https://github.com/fkirc/skip-duplicate-actions/commit/38c3738dcac87b41e2b7038775457756c793566e
with:
concurrent_skipping: "same_content_newer"
skip_after_successful_duplicate: "true"
paths: '[".cargo/**", ".github/workflows/ci.yml", "sample_configs/**", "src/**", "tests/**", "build.rs", "Cargo.lock", "Cargo.toml", "clippy.toml", "rustfmt.toml"]'
do_not_skip: '["workflow_dispatch"]'
do_not_skip: '["workflow_dispatch", "push"]'
- uses: actions/checkout@v2
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
@ -47,50 +54,87 @@ jobs:
override: true
components: rustfmt
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
- run: cargo fmt --all -- --check
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
clippy:
runs-on: ${{ matrix.os }}
# Runs tests + clippy on the main supported platforms.
supported:
needs: [rustfmt]
runs-on: ${{ matrix.triple.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-2019
triple:
- {
os: "ubuntu-latest",
target: "x86_64-unknown-linux-gnu",
cross: false,
}
- {
os: "ubuntu-latest",
target: "armv7-unknown-linux-gnueabihf",
cross: true,
}
- { os: "macOS-latest", target: "x86_64-apple-darwin", cross: false }
- {
os: "windows-2019",
target: "x86_64-pc-windows-msvc",
cross: false,
}
features: [
"--all-features",
# "--features battery",
# "--features gpu", # Think it's fine to skip this specific test.
"--no-default-features",
]
steps:
- id: skip_check
- name: Check if this action should be skipped
id: skip_check
uses: fkirc/skip-duplicate-actions@38c3738dcac87b41e2b7038775457756c793566e # https://github.com/fkirc/skip-duplicate-actions/commit/38c3738dcac87b41e2b7038775457756c793566e
with:
concurrent_skipping: "same_content_newer"
skip_after_successful_duplicate: "true"
paths: '[".cargo/**", ".github/workflows/ci.yml", "sample_configs/**", "src/**", "tests/**", "build.rs", "Cargo.lock", "Cargo.toml", "clippy.toml", "rustfmt.toml"]'
do_not_skip: '["workflow_dispatch"]'
do_not_skip: '["workflow_dispatch", "push"]'
- uses: actions/checkout@v2
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
- uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # https://github.com/actions-rs/toolchain/commit/88dc2356392166efad76775c878094f4e83ff746
- name: Setup Rust toolchain
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # https://github.com/actions-rs/toolchain/commit/88dc2356392166efad76775c878094f4e83ff746
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- name: Enable Rust cache
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
- run: cargo clippy --all-targets --workspace -- -D warnings
- name: Build tests
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
run: cargo test --no-run --locked ${{ matrix.features }}
env:
RUST_BACKTRACE: full
# Run cargo --check on all platforms
check:
needs: [rustfmt, clippy]
- name: Run tests
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
run: cargo test --no-fail-fast ${{ matrix.features }} -- --nocapture --quiet
env:
RUST_BACKTRACE: full
- name: Run clippy
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
run: cargo clippy ${{ matrix.features }} --workspace -- -D warnings
# Run cargo check on all other platforms
other_check:
needs: [rustfmt]
runs-on: ${{ matrix.triple.os }}
continue-on-error: true
strategy:
@ -98,12 +142,6 @@ jobs:
matrix:
triple:
# x86 or x64
- {
os: "ubuntu-latest",
target: "x86_64-unknown-linux-gnu",
cross: false,
rust: stable,
}
- {
os: "ubuntu-latest",
target: "i686-unknown-linux-gnu",
@ -122,18 +160,6 @@ jobs:
cross: true,
rust: stable,
}
- {
os: "macOS-latest",
target: "x86_64-apple-darwin",
cross: false,
rust: stable,
}
- {
os: "windows-2019",
target: "x86_64-pc-windows-msvc",
cross: false,
rust: stable,
}
- {
os: "windows-2019",
target: "i686-pc-windows-msvc",
@ -167,14 +193,6 @@ jobs:
rust: beta,
}
# aarch64
- {
os: "ubuntu-latest",
target: "aarch64-unknown-linux-gnu",
cross: true,
rust: stable,
}
# armv7
- {
os: "ubuntu-latest",
@ -216,13 +234,14 @@ jobs:
}
steps:
- id: skip_check
- name: Check if this action should be skipped
id: skip_check
uses: fkirc/skip-duplicate-actions@38c3738dcac87b41e2b7038775457756c793566e # https://github.com/fkirc/skip-duplicate-actions/commit/38c3738dcac87b41e2b7038775457756c793566e
with:
concurrent_skipping: "same_content_newer"
skip_after_successful_duplicate: "true"
paths: '[".cargo/**", ".github/workflows/ci.yml", "sample_configs/**", "src/**", "tests/**", "build.rs", "Cargo.lock", "Cargo.toml", "clippy.toml", "rustfmt.toml"]'
do_not_skip: '["workflow_dispatch"]'
do_not_skip: '["workflow_dispatch", "push"]'
- uses: actions/checkout@v2
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
@ -236,7 +255,7 @@ jobs:
override: true
target: ${{ matrix.triple.target }}
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
with:
key: ${{ matrix.triple.target }}
@ -248,133 +267,3 @@ jobs:
command: check
args: --all-targets --verbose --target=${{ matrix.triple.target }} --features "battery" --locked
use-cross: ${{ matrix.triple.cross }}
# Check without the battery feature enabled on x86-64 for supported operating systems
check-without-battery:
needs: [rustfmt, clippy]
runs-on: ${{ matrix.triple.os }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
triple:
- {
os: "ubuntu-latest",
target: "x86_64-unknown-linux-gnu",
cross: false,
rust: stable,
}
- {
os: "macOS-latest",
target: "x86_64-apple-darwin",
cross: false,
rust: stable,
}
- {
os: "windows-2019",
target: "x86_64-pc-windows-msvc",
cross: false,
rust: stable,
}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@38c3738dcac87b41e2b7038775457756c793566e # https://github.com/fkirc/skip-duplicate-actions/commit/38c3738dcac87b41e2b7038775457756c793566e
with:
concurrent_skipping: "same_content_newer"
skip_after_successful_duplicate: "true"
paths: '[".cargo/**", ".github/workflows/ci.yml", "sample_configs/**", "src/**", "tests/**", "build.rs", "Cargo.lock", "Cargo.toml", "clippy.toml", "rustfmt.toml"]'
do_not_skip: '["workflow_dispatch"]'
- uses: actions/checkout@v2
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
- name: Install toolchain
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # https://github.com/actions-rs/toolchain/commit/88dc2356392166efad76775c878094f4e83ff746
with:
profile: minimal
toolchain: ${{ matrix.triple.rust }}
override: true
target: ${{ matrix.triple.target }}
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
with:
key: ${{ matrix.triple.target }}
- name: Check without battery feature on the main 3
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: actions-rs/cargo@v1
with:
command: check
args: --all-targets --verbose --target=${{ matrix.triple.target }} --no-default-features --locked
use-cross: ${{ matrix.triple.cross }}
# Run tests x86-64 for supported operating systems
test:
needs: [rustfmt, clippy]
runs-on: ${{ matrix.triple.os }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
triple:
- {
os: "ubuntu-latest",
target: "x86_64-unknown-linux-gnu",
cross: false,
rust: stable,
}
- {
os: "macOS-latest",
target: "x86_64-apple-darwin",
cross: false,
rust: stable,
}
- {
os: "windows-2019",
target: "x86_64-pc-windows-msvc",
cross: false,
rust: stable,
}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@38c3738dcac87b41e2b7038775457756c793566e # https://github.com/fkirc/skip-duplicate-actions/commit/38c3738dcac87b41e2b7038775457756c793566e
with:
concurrent_skipping: "same_content_newer"
skip_after_successful_duplicate: "true"
paths: '[".cargo/**", ".github/workflows/ci.yml", "sample_configs/**", "src/**", "tests/**", "build.rs", "Cargo.lock", "Cargo.toml", "clippy.toml", "rustfmt.toml"]'
do_not_skip: '["workflow_dispatch"]'
- uses: actions/checkout@v2
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
- name: Install toolchain
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # https://github.com/actions-rs/toolchain/commit/88dc2356392166efad76775c878094f4e83ff746
with:
profile: minimal
toolchain: ${{ matrix.triple.rust }}
override: true
target: ${{ matrix.triple.target }}
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
with:
key: ${{ matrix.triple.target }}
- name: Build tests
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
run: cargo test --no-run --locked
env:
CARGO_HUSKY_DONT_INSTALL_HOOKS: true
RUST_BACKTRACE: full
- name: Run tests
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
run: cargo test --no-fail-fast -- --nocapture --quiet
env:
CARGO_HUSKY_DONT_INSTALL_HOOKS: true
RUST_BACKTRACE: full

View File

@ -23,7 +23,7 @@ jobs:
with:
concurrent_skipping: "same_content_newer"
skip_after_successful_duplicate: "false"
do_not_skip: '["workflow_dispatch"]'
do_not_skip: '["workflow_dispatch", "push"]'
coverage:
needs: pre_job
@ -37,9 +37,8 @@ jobs:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: ${{ matrix.triple.target }}

View File

@ -141,7 +141,7 @@ jobs:
override: true
target: ${{ matrix.triple.target }}
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: ${{ matrix.triple.target }}
@ -249,7 +249,7 @@ jobs:
override: true
target: x86_64-pc-windows-msvc
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: x86_64-pc-windows-msvc-msi
@ -309,7 +309,7 @@ jobs:
override: true
target: x86_64-unknown-linux-gnu
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: x86_64-unknown-linux-gnu-deb

View File

@ -137,7 +137,7 @@ jobs:
override: true
target: ${{ matrix.triple.target }}
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: ${{ matrix.triple.target }}
@ -243,7 +243,7 @@ jobs:
override: true
target: x86_64-pc-windows-msvc
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: x86_64-pc-windows-msvc-msi
@ -303,7 +303,7 @@ jobs:
override: true
target: x86_64-unknown-linux-gnu
- uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 # 1.3.0
- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: x86_64-unknown-linux-gnu-deb

View File

@ -392,7 +392,7 @@ use CPU (3) as the default instead.
.arg(use_old_network_legend)
.arg(whole_word);
let app = if cfg!(feature = "battery") {
if cfg!(feature = "battery") {
let battery = Arg::new("battery")
.long("battery")
.help("Shows the battery widget.")
@ -402,7 +402,5 @@ use CPU (3) as the default instead.
app.arg(battery)
} else {
app
};
app
}
}

View File

@ -916,11 +916,13 @@ fn get_hide_table_gap(matches: &clap::ArgMatches, config: &Config) -> bool {
}
fn get_use_battery(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("battery") {
return true;
} else if let Some(flags) = &config.flags {
if let Some(battery) = flags.battery {
return battery;
if cfg!(feature = "battery") {
if matches.is_present("battery") {
return true;
} else if let Some(flags) = &config.flags {
if let Some(battery) = flags.battery {
return battery;
}
}
}
false