diff --git a/src/commands/build/upload.rs b/src/commands/build/upload.rs index ab2de1d462..630e904e2a 100644 --- a/src/commands/build/upload.rs +++ b/src/commands/build/upload.rs @@ -24,7 +24,7 @@ use crate::utils::fs::TempDir; use crate::utils::fs::TempFile; use crate::utils::progress::ProgressBar; use crate::utils::vcs::{ - self, get_github_base_ref, get_github_pr_number, get_provider_from_remote, + self, get_github_base_ref, get_github_head_ref, get_github_pr_number, get_provider_from_remote, get_repo_from_remote_preserve_case, git_repo_base_ref, git_repo_base_repo_name_preserve_case, git_repo_head_ref, git_repo_remote_url, }; @@ -150,7 +150,11 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { .map(String::as_str) .map(Cow::Borrowed) .or_else(|| { - // Try to get the current ref from the VCS if not provided + // First try GitHub Actions environment variables + get_github_head_ref().map(Cow::Owned) + }) + .or_else(|| { + // Fallback to git repository introspection // Note: git_repo_head_ref will return an error for detached HEAD states, // which the error handling converts to None - this prevents sending "HEAD" as a branch name // In that case, the user will need to provide a valid branch name. diff --git a/src/utils/vcs.rs b/src/utils/vcs.rs index 93f190650f..1b436205ca 100644 --- a/src/utils/vcs.rs +++ b/src/utils/vcs.rs @@ -375,6 +375,21 @@ pub fn get_github_base_ref() -> Option { Some(base_ref) } +/// Attempts to get the head branch from GitHub Actions environment variables. +/// Returns the head branch name if running in a GitHub Actions pull request environment. +pub fn get_github_head_ref() -> Option { + let event_name = std::env::var("GITHUB_EVENT_NAME").ok()?; + + if event_name != "pull_request" { + debug!("Not running in pull_request event, got: {}", event_name); + return None; + } + + let head_ref = std::env::var("GITHUB_HEAD_REF").ok()?; + debug!("Auto-detected head ref from GitHub Actions: {}", head_ref); + Some(head_ref) +} + fn find_reference_url(repo: &str, repos: &[Repo]) -> Result> { let mut non_git = false; for configured_repo in repos {