mirror of
https://github.com/Xevion/banner.git
synced 2025-12-05 23:14:20 -06:00
fix: use wildcard COPY for .git directory, use RAILWAY_GIT_COMMIT_SHA as fallback
This commit is contained in:
@@ -38,8 +38,10 @@ WORKDIR /usr/src/banner
|
|||||||
# Copy dependency files for better layer caching
|
# Copy dependency files for better layer caching
|
||||||
COPY ./Cargo.toml ./Cargo.lock* ./
|
COPY ./Cargo.toml ./Cargo.lock* ./
|
||||||
|
|
||||||
# Copy .git directory for build.rs to access Git information
|
# Copy .git directory for build.rs to access Git information (if available)
|
||||||
COPY ./.git ./.git
|
# This will copy .git (and .gitignore) if it exists, but won't fail if it doesn't
|
||||||
|
# While normally a COPY requires at least one file, .gitignore should still be available, so this wildcard should always work
|
||||||
|
COPY ./.git* ./
|
||||||
|
|
||||||
# Copy build.rs early so it can run during the first build
|
# Copy build.rs early so it can run during the first build
|
||||||
COPY ./build.rs ./
|
COPY ./build.rs ./
|
||||||
|
|||||||
32
build.rs
32
build.rs
@@ -1,19 +1,21 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Get the current Git commit hash
|
// Try to get Git commit hash from Railway environment variable first
|
||||||
let output = Command::new("git").args(["rev-parse", "HEAD"]).output();
|
let git_hash = std::env::var("RAILWAY_GIT_COMMIT_SHA").unwrap_or_else(|_| {
|
||||||
|
// Fallback to git command if not on Railway
|
||||||
let git_hash = match output {
|
let output = Command::new("git").args(["rev-parse", "HEAD"]).output();
|
||||||
Ok(output) => {
|
match output {
|
||||||
if output.status.success() {
|
Ok(output) => {
|
||||||
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
if output.status.success() {
|
||||||
} else {
|
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
||||||
"unknown".to_string()
|
} else {
|
||||||
|
"unknown".to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Err(_) => "unknown".to_string(),
|
||||||
}
|
}
|
||||||
Err(_) => "unknown".to_string(),
|
});
|
||||||
};
|
|
||||||
|
|
||||||
// Get the short hash (first 7 characters)
|
// Get the short hash (first 7 characters)
|
||||||
let short_hash = if git_hash != "unknown" && git_hash.len() >= 7 {
|
let short_hash = if git_hash != "unknown" && git_hash.len() >= 7 {
|
||||||
@@ -26,7 +28,9 @@ fn main() {
|
|||||||
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_hash);
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_hash);
|
||||||
println!("cargo:rustc-env=GIT_COMMIT_SHORT={}", short_hash);
|
println!("cargo:rustc-env=GIT_COMMIT_SHORT={}", short_hash);
|
||||||
|
|
||||||
// Rebuild if the Git commit changes
|
// Rebuild if the Git commit changes (only works when .git directory is available)
|
||||||
println!("cargo:rerun-if-changed=.git/HEAD");
|
if std::path::Path::new(".git/HEAD").exists() {
|
||||||
println!("cargo:rerun-if-changed=.git/refs/heads");
|
println!("cargo:rerun-if-changed=.git/HEAD");
|
||||||
|
println!("cargo:rerun-if-changed=.git/refs/heads");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user