Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add build hash to nightly builds for version #951

Merged
merged 2 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ci: add build hash to nightly builds for version
  • Loading branch information
ClementTsang committed Jan 2, 2023
commit 9ee1255da411d98faee01cc96da5de1ccccddefd
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ body:
label: What version of `bottom` are you running?
description: >
Please provide which version of `bottom` you're running, which you can find with `btm -V`. If you are using
a nightly/non-release version, please specify that and any related details (e.g. the commit hash/which nightly build).
a nightly/non-release version, please also specify that.
placeholder: 0.7.0

- type: input
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ jobs:
uses: ClementTsang/cargo-action@v0.0.3
env:
BTM_GENERATE: true
BTM_BUILD_RELEASE_CALLER: ${{ inputs.caller }}
with:
command: build
args: --release --verbose --locked --target=${{ matrix.info.target }} --features deploy
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ More details on configuration can be found [in the documentation](https://clemen
## Troubleshooting

If some things aren't working, give the [Troubleshooting page](https://clementtsang.github.io/bottom/nightly/troubleshooting) a look. If things still aren't
working, then consider asking a [question by opening a question](https://github.com/ClementTsang/bottom/discussions) or filing a [bug report](https://github.com/ClementTsang/bottom/issues/new/choose).
working, then consider opening [a question](https://github.com/ClementTsang/bottom/discussions) or filing a [bug report](https://github.com/ClementTsang/bottom/issues/new/choose).

## Contribution

Expand Down
44 changes: 36 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::{
env, fs,
io::Result,
env, fs, io,
path::{Path, PathBuf},
};

use clap_complete::{generate_to, shells::Shell};

include!("src/clap.rs");

fn create_dir(dir: &Path) -> Result<()> {
fn create_dir(dir: &Path) -> io::Result<()> {
let res = fs::create_dir_all(dir);
match &res {
Ok(()) => {}
Expand All @@ -23,12 +22,14 @@ fn create_dir(dir: &Path) -> Result<()> {
res
}

fn main() -> Result<()> {
const COMPLETION_DIR: &str = "./target/tmp/bottom/completion/";
const MANPAGE_DIR: &str = "./target/tmp/bottom/manpage/";
fn btm_generate() -> io::Result<()> {
const ENV_KEY: &str = "BTM_GENERATE";

match env::var_os("BTM_GENERATE") {
match env::var_os(ENV_KEY) {
Some(var) if !var.is_empty() => {
const COMPLETION_DIR: &str = "./target/tmp/bottom/completion/";
const MANPAGE_DIR: &str = "./target/tmp/bottom/manpage/";

let completion_out_dir = PathBuf::from(COMPLETION_DIR);
let manpage_out_dir = PathBuf::from(MANPAGE_DIR);

Expand All @@ -53,7 +54,34 @@ fn main() -> Result<()> {
_ => {}
}

println!("cargo:rerun-if-env-changed=BTM_GENERATE");
println!("cargo:rerun-if-env-changed={ENV_KEY}");

Ok(())
}

fn nightly_version() {
const ENV_KEY: &str = "BTM_BUILD_RELEASE_CALLER";

match env::var_os(ENV_KEY) {
Some(var) if !var.is_empty() && var == "nightly" => {
if let Ok(output) = std::process::Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
{
let version = env!("CARGO_PKG_VERSION");
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=NIGHTLY_VERSION={version}-nightly-{git_hash}");
}
}
_ => {}
}

println!("cargo:rerun-if-env-changed={ENV_KEY}");
}

fn main() -> Result<()> {
btm_generate()?;
nightly_version();

Ok(())
}
7 changes: 6 additions & 1 deletion src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,14 @@ use CPU (3) as the default instead.
.help("The timespan of data kept.")
.long_help("How much data is stored at once in terms of time. Takes in human-readable time spans (e.g. 10m, 1h), with a minimum of 1 minute. Note higher values will take up more memory. Defaults to 10 minutes.");

const VERSION: &str = match option_env!("NIGHTLY_VERSION") {
Some(nightly_version) => nightly_version,
None => crate_version!(),
};

#[allow(unused_mut)]
let mut app = Command::new(crate_name!())
.version(crate_version!())
.version(VERSION)
.author(crate_authors!())
.about(crate_description!())
.override_usage(USAGE)
Expand Down