ci: add manpage generation, migrate build script (#692)
Adds manpage generation to the build process, as well as following the xtask concept of adding additional build scripts that only need to run on deploy/nightly as opposed to `build.rs`. Note this doesn't follow the recommended method of using workplaces because I don't really want to shift the entire repo structure just for this. More on xtask: https://github.com/matklad/cargo-xtask
This commit is contained in:
parent
92ec359936
commit
8087f0b636
|
@ -82,11 +82,7 @@ jobs:
|
|||
target: "i686-unknown-linux-musl",
|
||||
cross: true,
|
||||
}
|
||||
- {
|
||||
os: "macOS-latest",
|
||||
target: "x86_64-apple-darwin",
|
||||
cross: false,
|
||||
}
|
||||
- { os: "macOS-latest", target: "x86_64-apple-darwin", cross: false }
|
||||
- {
|
||||
os: "windows-2019",
|
||||
target: "x86_64-pc-windows-msvc",
|
||||
|
@ -152,11 +148,15 @@ jobs:
|
|||
args: --release --verbose --target=${{ matrix.triple.target }} --features "battery"
|
||||
use-cross: ${{ matrix.triple.cross }}
|
||||
|
||||
- name: Move autocomplete to working directory
|
||||
- name: Build autocompletion
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir completion
|
||||
cp -r ./target/${{ matrix.triple.target }}/release/build/bottom-*/out/. completion
|
||||
cargo run --manifest-path ./xtask/Cargo.toml -- completion completion
|
||||
|
||||
- name: Build manpage
|
||||
shell: bash
|
||||
run: |
|
||||
cargo run --manifest-path ./xtask/Cargo.toml -- manpage manpage
|
||||
|
||||
- name: Bundle release and completion (Windows)
|
||||
if: matrix.triple.os == 'windows-2019'
|
||||
|
@ -188,6 +188,13 @@ jobs:
|
|||
tar -C ./completion -czvf completion.tar.gz .
|
||||
mv completion.tar.gz release/
|
||||
|
||||
- name: Compress manpage files (Linux x86-64 GNU)
|
||||
if: matrix.triple.target == 'x86_64-unknown-linux-gnu' && matrix.triple.container == ''
|
||||
shell: bash
|
||||
run: |
|
||||
tar -C ./manpage -czvf manpage.tar.gz .
|
||||
mv manpage.tar.gz release/
|
||||
|
||||
- name: Save release as artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
|
|
|
@ -144,11 +144,15 @@ jobs:
|
|||
args: --release --verbose --target=${{ matrix.triple.target }} --features "battery"
|
||||
use-cross: ${{ matrix.triple.cross }}
|
||||
|
||||
- name: Move autocomplete to working directory
|
||||
- name: Build autocompletion
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir completion
|
||||
cp -r ./target/${{ matrix.triple.target }}/release/build/bottom-*/out/. completion
|
||||
cargo run --manifest-path ./xtask/Cargo.toml -- completion completion
|
||||
|
||||
- name: Build manpage
|
||||
shell: bash
|
||||
run: |
|
||||
cargo run --manifest-path ./xtask/Cargo.toml -- manpage manpage
|
||||
|
||||
- name: Bundle release and completion (Windows)
|
||||
if: matrix.triple.os == 'windows-2019'
|
||||
|
@ -180,6 +184,13 @@ jobs:
|
|||
tar -C ./completion -czvf completion.tar.gz .
|
||||
mv completion.tar.gz release/
|
||||
|
||||
- name: Compress manpage files (Linux x86-64 GNU)
|
||||
if: matrix.triple.target == 'x86_64-unknown-linux-gnu' && matrix.triple.container == ''
|
||||
shell: bash
|
||||
run: |
|
||||
tar -C ./manpage -czvf manpage.tar.gz .
|
||||
mv manpage.tar.gz release/
|
||||
|
||||
- name: Save release files as artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
|
|
|
@ -230,7 +230,6 @@ dependencies = [
|
|||
"cargo-husky",
|
||||
"cfg-if",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"crossterm",
|
||||
"ctrlc",
|
||||
"dirs",
|
||||
|
@ -325,15 +324,6 @@ dependencies = [
|
|||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "3.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "concurrent-queue"
|
||||
version = "1.2.2"
|
||||
|
|
|
@ -11,7 +11,6 @@ description = "A customizable cross-platform graphical process/system monitor fo
|
|||
documentation = "https://clementtsang.github.io/bottom/stable"
|
||||
readme = "README.md"
|
||||
default-run = "btm"
|
||||
build = "build.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "btm"
|
||||
|
@ -84,10 +83,6 @@ winapi = "0.3.9"
|
|||
assert_cmd = "2.0"
|
||||
predicates = "2.1"
|
||||
|
||||
[build-dependencies]
|
||||
clap = { version = "3.1.6", features = ["default", "cargo", "wrap_help"] }
|
||||
clap_complete = "3.1.1"
|
||||
|
||||
|
||||
[package.metadata.deb]
|
||||
section = "utility"
|
||||
|
|
33
build.rs
33
build.rs
|
@ -1,33 +0,0 @@
|
|||
use clap_complete::{generate_to, shells::Shell};
|
||||
use std::{env, fs, process};
|
||||
|
||||
include!("src/clap.rs");
|
||||
|
||||
fn main() {
|
||||
// OUT_DIR is where extra build files are written to for Cargo.
|
||||
let out_dir = match env::var_os("OUT_DIR") {
|
||||
Some(out_dir) => out_dir,
|
||||
None => {
|
||||
eprintln!("The OUT_DIR environment variable was not set! Aborting...");
|
||||
process::exit(1)
|
||||
}
|
||||
};
|
||||
match fs::create_dir_all(&out_dir) {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"Failed to create a directory at OUT_DIR location {:?}, encountered error {:?}. Aborting...",
|
||||
out_dir, err
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Generate completions
|
||||
let mut app = build_app();
|
||||
generate_to(Shell::Bash, &mut app, "btm", &out_dir).unwrap();
|
||||
generate_to(Shell::Zsh, &mut app, "btm", &out_dir).unwrap();
|
||||
generate_to(Shell::Fish, &mut app, "btm", &out_dir).unwrap();
|
||||
generate_to(Shell::PowerShell, &mut app, "btm", &out_dir).unwrap();
|
||||
generate_to(Shell::Elvish, &mut app, "btm", &out_dir).unwrap();
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# Logging
|
||||
*.log
|
||||
|
||||
# Flamegraph stuff
|
||||
rust-unmangle
|
||||
*.svg
|
||||
*.data
|
||||
*.data.old
|
||||
|
||||
# IntelliJ
|
||||
.idea/
|
||||
|
||||
# Heaptrack files
|
||||
*.zst
|
||||
|
||||
# For testing
|
||||
sample_configs/testing.toml
|
||||
|
||||
# Wix
|
||||
/wix/
|
||||
|
||||
# Cargo-deny
|
||||
deny.toml
|
||||
|
||||
# vscode
|
||||
.vscode
|
||||
|
||||
# mkdocs
|
||||
site/
|
||||
docs/site
|
|
@ -0,0 +1,194 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"lazy_static",
|
||||
"os_str_bytes",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"terminal_size",
|
||||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "3.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_mangen"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0649fb4156bbd7306896025005596033879a2051f9a3aa7416ab915df1f8fdac"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"roff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "roff"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
|
||||
dependencies = [
|
||||
"terminal_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "xtask"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"clap_mangen",
|
||||
]
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "xtask"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.1.6", features = ["default", "cargo", "wrap_help"] }
|
||||
clap_complete = "3.1.1"
|
||||
clap_mangen = "0.1.2"
|
|
@ -0,0 +1,55 @@
|
|||
use clap_complete::{generate_to, shells::Shell};
|
||||
use std::{env, fs, io::Result, path::PathBuf, process};
|
||||
|
||||
include!("../../src/clap.rs");
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let command = if let Some(command) = env::args().nth(1) {
|
||||
command
|
||||
} else {
|
||||
eprintln!("A command was not given!");
|
||||
process::exit(1)
|
||||
};
|
||||
|
||||
let out_dir = if let Some(out_dir) = env::args().nth(2) {
|
||||
PathBuf::from(out_dir)
|
||||
} else {
|
||||
eprintln!("An output directory was not set!");
|
||||
process::exit(1)
|
||||
};
|
||||
|
||||
if let Err(err) = fs::create_dir_all(&out_dir) {
|
||||
eprintln!(
|
||||
"Failed to create a directory at the output director location {:?}, encountered error {:?}. Aborting...",
|
||||
out_dir, err
|
||||
);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
match command.as_str() {
|
||||
"completion" => {
|
||||
// Generate completions
|
||||
let mut app = build_app();
|
||||
generate_to(Shell::Bash, &mut app, "btm", &out_dir)?;
|
||||
generate_to(Shell::Zsh, &mut app, "btm", &out_dir)?;
|
||||
generate_to(Shell::Fish, &mut app, "btm", &out_dir)?;
|
||||
generate_to(Shell::PowerShell, &mut app, "btm", &out_dir)?;
|
||||
generate_to(Shell::Elvish, &mut app, "btm", &out_dir)?;
|
||||
}
|
||||
"manpage" => {
|
||||
// Generate manpage
|
||||
let app = build_app();
|
||||
let man = clap_mangen::Man::new(app);
|
||||
let mut buffer: Vec<u8> = Default::default();
|
||||
man.render(&mut buffer).unwrap();
|
||||
|
||||
std::fs::write(out_dir.join("btm.1"), buffer)?;
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Invalid command given: `{}`", command);
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue