Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/commands/build/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/utils/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,21 @@ pub fn get_github_base_ref() -> Option<String> {
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<String> {
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<Option<String>> {
let mut non_git = false;
for configured_repo in repos {
Expand Down