Fix release process issues
- 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
This commit is contained in:
parent
8b3954ff99
commit
86aeec3ce9
2
.github/workflows/main.yaml
vendored
2
.github/workflows/main.yaml
vendored
|
@ -4,6 +4,8 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- v*.*.*
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
|
57
build.rs
57
build.rs
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -8,13 +8,11 @@ pub(crate) const AUTHOR: &str = env!("CARGO_PKG_AUTHORS");
|
|||
|
||||
/// Default value for `created by` torrent metainfo field.
|
||||
///
|
||||
/// Example: imdl/0.0.0 (1234567890AB)
|
||||
/// Example: imdl/0.0.0 (1234567890ab)
|
||||
pub(crate) const CREATED_BY_DEFAULT: &str = concat!(
|
||||
"imdl/",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
" (",
|
||||
env!("GIT_HEAD_PARTIAL_HASH"),
|
||||
")"
|
||||
);
|
||||
|
||||
/// Value for `encoding` torrent metainfo field.
|
||||
|
@ -22,7 +20,7 @@ pub(crate) const ENCODING_UTF8: &str = "UTF-8";
|
|||
|
||||
pub(crate) const HELP_MESSAGE: &str = "Print help message.";
|
||||
|
||||
/// The pogress chars are from the
|
||||
/// The progress chars are from the
|
||||
/// [Block Elements unicode block](https://en.wikipedia.org/wiki/Block_Elements).
|
||||
pub(crate) const PROGRESS_CHARS: &str = "█▉▊▋▌▍▎▏ ";
|
||||
|
||||
|
@ -66,3 +64,32 @@ pub(crate) const TICK_CHARS: &str = concat!(
|
|||
pub(crate) const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
pub(crate) const VERSION_MESSAGE: &str = "Print version number.";
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::common::*;
|
||||
|
||||
#[test]
|
||||
fn created_by() {
|
||||
let pattern = Regex::new(
|
||||
r#"(?x)
|
||||
imdl/
|
||||
[0-9]+.[0-9]+.[0-9]+(-.*)?
|
||||
(
|
||||
[\ ]
|
||||
\(
|
||||
[0-9a-f]{12}
|
||||
\)
|
||||
)?
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
pattern.is_match(CREATED_BY_DEFAULT),
|
||||
"Bad created by string: `{}`",
|
||||
CREATED_BY_DEFAULT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1578,7 +1578,7 @@ mod tests {
|
|||
" Name foo
|
||||
Created By {}
|
||||
Info Hash d3432a4b9d18baa413095a70f1e417021ceaca5b
|
||||
Torrent Size 237 bytes
|
||||
Torrent Size {} bytes
|
||||
Content Size 9 bytes
|
||||
Private no
|
||||
Tracker http://bar/
|
||||
|
@ -1590,7 +1590,8 @@ Content Size 9 bytes
|
|||
├─h
|
||||
└─x
|
||||
",
|
||||
consts::CREATED_BY_DEFAULT
|
||||
consts::CREATED_BY_DEFAULT,
|
||||
212 + consts::CREATED_BY_DEFAULT.len()
|
||||
);
|
||||
assert_eq!(have, want);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user