-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Trigger GitHub Actions workflow on release tags - Make build script tolerate not being called in git directory - Omit git hash in created by message if not built in git directory - Test created by message format type: distribution
- Loading branch information
Showing
4 changed files
with
85 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
push: | ||
branches: | ||
- master | ||
tags: | ||
- v*.*.* | ||
pull_request: | ||
branches: | ||
- master | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,53 @@ | ||
use std::{error::Error, process::Command, str}; | ||
use std::{ | ||
io::{self, Error, ErrorKind}, | ||
process::Command, | ||
}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stdout = Command::new("git") | ||
fn is_inside_git_work_tree() -> bool { | ||
Command::new("git") | ||
.arg("rev-parse") | ||
.arg("HEAD") | ||
.output()? | ||
.stdout; | ||
let hash = str::from_utf8(&stdout)?; | ||
println!("cargo:rustc-env=GIT_HEAD_PARTIAL_HASH={}", &hash[0..12]); | ||
.arg("--is-inside-work-tree") | ||
.output() | ||
.map(|output| String::from_utf8_lossy(&output.stdout).trim() == "true") | ||
.unwrap_or(false) | ||
} | ||
|
||
fn error(message: String) -> io::Error { | ||
Error::new(ErrorKind::Other, message) | ||
} | ||
|
||
fn commit_hash() -> io::Result<String> { | ||
let output = Command::new("git").arg("rev-parse").arg("HEAD").output()?; | ||
|
||
if !output.status.success() { | ||
return Err(error(format!( | ||
"Status error: `git rev-parse HEAD` failed: {}", | ||
output.status | ||
))); | ||
} | ||
|
||
let hash = String::from_utf8_lossy(&output.stdout) | ||
.into_owned() | ||
.trim() | ||
.to_owned(); | ||
|
||
if !hash.chars().all(|c| "0123456789abcdef".contains(c)) { | ||
return Err(error(format!( | ||
"Invalid hash from `git rev-parse HEAD`: {}", | ||
hash | ||
))); | ||
} | ||
|
||
Ok(hash) | ||
} | ||
|
||
fn main() -> io::Result<()> { | ||
if is_inside_git_work_tree() { | ||
let hash = commit_hash()?; | ||
println!("cargo:rustc-env=GIT_HEAD_PARTIAL_HASH= ({})", &hash[0..12]); | ||
} else { | ||
println!("cargo:rustc-env=GIT_HEAD_PARTIAL_HASH="); | ||
}; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters