mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-01-12 22:43:06 +08:00
feat: display git-commit
This commit is contained in:
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -109,6 +109,8 @@ jobs:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
file: ./dockerfiles/components/ordhook.dockerfile
|
||||
build-args: |
|
||||
GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
# Only push if (there's a new release on main branch, or if building a non-main branch) and (Only run on non-PR events or only PRs that aren't from forks)
|
||||
|
||||
@@ -1,8 +1,29 @@
|
||||
use std::process::Command;
|
||||
|
||||
fn current_git_hash() -> Option<String> {
|
||||
if option_env!("GIT_COMMIT") == None {
|
||||
let commit = Command::new("git")
|
||||
.arg("log")
|
||||
.arg("-1")
|
||||
.arg("--pretty=format:%h") // Abbreviated commit hash
|
||||
.current_dir(env!("CARGO_MANIFEST_DIR"))
|
||||
.output();
|
||||
|
||||
if let Ok(commit) = commit {
|
||||
if let Ok(commit) = String::from_utf8(commit.stdout) {
|
||||
return Some(commit);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return option_env!("GIT_COMMIT").map(String::from);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// note: add error checking yourself.
|
||||
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap();
|
||||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
||||
if let Some(git) = current_git_hash() {
|
||||
println!("cargo:rustc-env=GIT_COMMIT={}", git);
|
||||
}
|
||||
}
|
||||
@@ -728,8 +728,11 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
|
||||
}
|
||||
|
||||
let ordhook_config = config.get_ordhook_config();
|
||||
let version = env!("GIT_HASH");
|
||||
info!(ctx.expect_logger(), "Starting service (git_hash = {})...", version);
|
||||
let version = env!("GIT_COMMIT");
|
||||
info!(
|
||||
ctx.expect_logger(),
|
||||
"Starting service (git_commit = {})...", version
|
||||
);
|
||||
|
||||
let start_block = match cmd.start_at_block {
|
||||
Some(entry) => entry,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
FROM rust:bullseye as build
|
||||
|
||||
ARG GIT_COMMIT='0000000'
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
RUN apt-get update && apt-get install -y ca-certificates pkg-config libssl-dev libclang-11-dev libunwind-dev libunwind8 curl gnupg
|
||||
|
||||
Reference in New Issue
Block a user