Skip to content

Commit

Permalink
refactor!: rework ci & code cleanup
Browse files Browse the repository at this point in the history
A major cleanup + refactoring of the code to bring it into line with the 
main starship repo.

- release-please and cargo publishing
- (Build) testing for more platforms (including FreeBSD, musl and ARM)
- Upgraded dependencies
- Depdendabot
- Clippy fixes
- removal of disabled clippy lints
- removal of deprecated std-library item (`mem::uninitialized`)
- add audit-check to CI

Marked as a breaking change because this includes the non-exhaustive
removal from svartalf#2.
  • Loading branch information
chipbuster authored May 10, 2022
2 parents de0994c + 9bd8872 commit 2330404
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 178 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- "\U0001F4E6 dependencies"
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- "\U0001F4E6 dependencies"
146 changes: 73 additions & 73 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,125 @@ on: [push, pull_request]

name: Continuous integration

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUST_BACKTRACE: short
RUSTUP_MAX_RETRIES: 10

jobs:
linux:
name: Linux
runs-on: ubuntu-latest
test:
name: Test
strategy:
matrix:
toolchain:
- stable
- 1.46.0 # MSRV
arch:
- 1.46.0 # MSRV
target:
- i686-unknown-linux-gnu
- x86_64-unknown-linux-gnu
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.arch }}
override: true

- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target ${{ matrix.arch }}

- name: Run tests
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --target ${{ matrix.arch }}

- name: Run clippy
if: matrix.toolchain == 'stable'
uses: actions-rs/cargo@v1
with:
use-cross: true
command: clippy
args: --target ${{ matrix.arch }} -- -D warnings

windows:
name: Windows
runs-on: windows-latest
strategy:
matrix:
toolchain:
- stable
- 1.46.0 # MSRV
arch:
- x86_64-unknown-linux-musl
- i686-pc-windows-msvc
- x86_64-pc-windows-msvc
- x86_64-apple-darwin
include:
- target: i686-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: i686-pc-windows-msvc
os: windows-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3.0.2
- uses: actions-rs/toolchain@v1.0.6
with:
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.arch }}
target: ${{ matrix.target }}
override: true

- uses: Swatinem/rust-cache@v1.3.0

- name: Build
uses: actions-rs/cargo@v1
uses: actions-rs/cargo@v1.0.1
with:
use-cross: true
command: build
args: --target ${{ matrix.arch }}
args: --target ${{ matrix.target }} --all-features --all-targets

- name: Run tests
uses: actions-rs/cargo@v1
uses: actions-rs/cargo@v1.0.1
with:
use-cross: true
command: test
args: --target ${{ matrix.arch }}
args: --target ${{ matrix.target }} --all-features --all-targets

- name: Run clippy
if: matrix.toolchain == 'stable'
uses: actions-rs/cargo@v1
uses: actions-rs/cargo@v1.0.1
with:
use-cross: true
command: clippy
args: --target ${{ matrix.arch }} -- -D warnings
args: --target ${{ matrix.target }} -- -D clippy::all

macos:
name: macOS
runs-on: macOS-latest
build_only:
name: Test [Build only]
strategy:
matrix:
toolchain:
- stable
- 1.46.0 # MSRV
arch:
- x86_64-apple-darwin
- 1.46.0 # MSRV
target:
- x86_64-unknown-freebsd
- aarch64-unknown-linux-gnu
- aarch64-unknown-linux-musl
- aarch64-pc-windows-msvc
- aarch64-apple-darwin
include:
- target: x86_64-unknown-freebsd
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
- target: aarch64-apple-darwin
os: macos-latest
exclude:
- target: aarch64-apple-darwin
toolchain: 1.46.0
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3.0.2
# FreeBSD requires latest cross
- run: cargo install cross --git https://github.com/cross-rs/cross

- uses: actions-rs/toolchain@v1.0.6
with:
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.arch }}
target: ${{ matrix.target }}
override: true

- uses: Swatinem/rust-cache@v1.3.0

- name: Build
uses: actions-rs/cargo@v1
uses: actions-rs/cargo@v1.0.1
with:
use-cross: true
command: build
args: --target ${{ matrix.arch }}

- name: Run tests
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --target ${{ matrix.arch }}
args: --target ${{ matrix.target }}

- name: Run clippy
if: matrix.toolchain == 'stable'
uses: actions-rs/cargo@v1
uses: actions-rs/cargo@v1.0.1
with:
use-cross: true
command: clippy
args: --target ${{ matrix.arch }} -- -D warnings
args: --target ${{ matrix.target }} -- -D clippy::all
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy
on:
push:
branches:
- main
env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUST_BACKTRACE: short
RUSTUP_MAX_RETRIES: 10

jobs:
# Update release PR
release_please:
name: Release Please
runs-on: ubuntu-latest
if: github.repository == 'starship/rust-battery'
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: rust

# Publish starship-battery to Crates.io
cargo_publish:
name: Publish Cargo Package
runs-on: ubuntu-latest
needs: release_please
if: ${{ needs.release_please.outputs.release_created == 'true' }}
steps:
- name: Setup | Checkout
uses: actions/checkout@v3.0.2

- name: Setup | Rust
uses: actions-rs/toolchain@v1.0.7
with:
toolchain: stable
profile: minimal
override: true

- name: Build | Publish
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
15 changes: 15 additions & 0 deletions .github/workflows/merge-dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Auto-merge Dependabot PRs
on:
schedule:
- cron: "0 * * * *"
jobs:
auto_merge:
if: (github.event_name == 'schedule' && github.repository == 'starship/rust-battery') || (github.event_name != 'schedule')
name: Auto-merge Dependabot PRs
runs-on: ubuntu-latest
steps:
- uses: akheron/dependabot-cron-action@d020867c009553e279f0200b621459444828a9b0
with:
token: ${{ secrets.DEPENDABOT_GITHUB_API_TOKEN }}
auto-merge: "minor"
merge-method: "squash"
29 changes: 29 additions & 0 deletions .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Security audit
on:
pull_request:
paths:
- "**/Cargo.toml"
- "**/Cargo.lock"
push:
paths:
- "**/Cargo.toml"
- "**/Cargo.lock"
schedule:
- cron: "0 0 * * *"
jobs:
security_audit:
if: (github.event_name == 'schedule' && github.repository == 'starship/rust-battery') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/checkout@v3
- name: Setup | Rust
uses: actions-rs/toolchain@v1.0.7
with:
toolchain: stable
override: true
profile: minimal
- name: Test | Security Audit
uses: actions-rs/audit-check@v1.2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ build = "build.rs"
[dependencies]
cfg-if = "1.0"
num-traits = { version = "0.2", default_features = false }
uom = { version = "0.30", features = ["autoconvert", "f32", "si"] }
uom = { version = "0.32", features = ["autoconvert", "f32", "si"] }

[target.'cfg(target_os = "linux")'.dependencies]
lazycell = "~1.3"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
libc = "^0.2"
mach = "^0.3"
core-foundation = "~0.7"
core-foundation = "~0.9"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version ="~0.3", features = ["impl-default", "devguid", "winbase", "ioapiset", "ntdef", "setupapi", "handleapi", "errhandlingapi", "winerror"] }

[target.'cfg(any(target_os = "dragonfly", target_os = "freebsd"))'.dependencies]
libc = "~0.2"
nix = "~0.23"
nix = { version = "~0.24", default-features = false, features = ["ioctl"] }

[dev-dependencies]
tempfile = "^3.0"
approx = "0.3.2"
approx = "0.5.1"
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,8 @@ fn main() -> Result<(), battery::Error> {
}
```

See the `battery/examples/` folder in the [repository](https://github.com/svartalf/rust-battery/blob/master/battery/examples/simple.rs)
See the `battery/examples/` folder in the [repository](https://github.com/starship/rust-battery/blob/main/battery/examples/simple.rs)
for additional examples.

## FFI bindings

Experimental [battery-ffi](https://crates.io/crates/battery-ffi) crate provides the FFI bindings to the `battery` crate,
so it can be used with other languages, such as C, Python or NodeJS.

Check its [README](https://github.com/svartalf/rust-battery/tree/master/battery-ffi)
and [documentation](https://docs.rs/battery-ffi) for details.

## Users

This an incomplete list of the `battery` crate users. If you are using it too,
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! ## Examples
//!
//! For a quick example see the [Manager](struct.Manager.html) type documentation
//! or [`simple.rs`](https://github.com/svartalf/rust-battery/blob/master/battery/examples/simple.rs)
//! or [`simple.rs`](https://github.com/starship/rust-battery/blob/main/battery/examples/simple.rs)
//! file in the `examples/` folder.
//!
//! [battop](https://crates.io/crates/battop) crate is using this library as a knowledge source,
Expand All @@ -23,7 +23,6 @@
#![deny(unused)]
#![deny(unstable_features)]
#![deny(bare_trait_objects)]
#![allow(clippy::manual_non_exhaustive)] // MSRV is 1.36
#![doc(html_root_url = "https://docs.rs/starship-battery/0.7.9")]

#[macro_use]
Expand Down
4 changes: 1 addition & 3 deletions src/platform/darwin/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ where
T: DataSource,
{
fn from(ds: T) -> IoKitDevice {
IoKitDevice {
source: Box::new(ds),
}
IoKitDevice { source: Box::new(ds) }
}
}

Expand Down
Loading

0 comments on commit 2330404

Please sign in to comment.