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 all commits
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
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ build_task:
BTM_GENERATE: true
COMPLETION_DIR: "target/tmp/bottom/completion/"
MANPAGE_DIR: "target/tmp/bottom/manpage/"
# -PLACEHOLDER FOR CI-
matrix:
- name: "FreeBSD 13 Build"
alias: "freebsd_13_1_build"
Expand Down Expand Up @@ -104,6 +105,7 @@ build_task:
- . $HOME/.cargo/env
- cargo build --release --verbose --locked --features deploy
- mv ./target/release/btm ./
- ./btm -V
- mv "$COMPLETION_DIR" completion
- mv "$MANPAGE_DIR" manpage
- tar -czvf bottom_$NAME.tar.gz btm completion
Expand Down
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
50 changes: 42 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,40 @@ 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" => {
let version = env!("CARGO_PKG_VERSION");

if let Some(git_hash) = option_env!("CIRRUS_CHANGE_IN_REPO")
.and_then(|cirrus_sha: &str| cirrus_sha.get(0..8))
{
println!("cargo:rustc-env=NIGHTLY_VERSION={version}-nightly-{git_hash}");
} else if let Ok(output) = std::process::Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
{
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}");
println!("cargo:rerun-if-env-changed=CIRRUS_CHANGE_IN_REPO");
}

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

Ok(())
}
10 changes: 9 additions & 1 deletion scripts/cirrus/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@
def make_query_request(key: str, branch: str, build_type: str):
print("Creating query request.")
mutation_id = "Cirrus CI Build {}-{}-{}".format(build_type, branch, int(time()))

# Dumb but if it works...
config_override = (
Path(".cirrus.yml").read_text().replace("# -PLACEHOLDER FOR CI-", 'BTM_BUILD_RELEASE_CALLER: "nightly"')
)
query = """
mutation CreateCirrusCIBuild (
$repo: ID!,
$branch: String!,
$mutation_id: String!
$mutation_id: String!,
$config_override: String,
) {
createBuild(
input: {
repositoryId: $repo,
branch: $branch,
clientMutationId: $mutation_id,
configOverride: $config_override
}
) {
build {
Expand All @@ -52,6 +59,7 @@ def make_query_request(key: str, branch: str, build_type: str):
"repo": "6646638922956800",
"branch": branch,
"mutation_id": mutation_id,
"config_override": dedent(config_override),
}
data = {"query": dedent(query), "variables": params}
data = json.dumps(data).encode()
Expand Down
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