Skip to content

Commit

Permalink
ci: Use base/head from GH environment. (#180)
Browse files Browse the repository at this point in the history
* Use env vars.

* Fix git.

* Try again.

* Try github context.

* Prepend head with prefix.

* Fix unexpected rev.
  • Loading branch information
milesj committed Jul 7, 2022
1 parent 4d1c76c commit 75f33bd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: run
args: -- --color --log trace ci
args: -- --color --log trace ci --base ${{ github.base_ref || 'master' }}
5 changes: 3 additions & 2 deletions crates/action-runner/src/actions/target/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ pub async fn create_target_hasher(
// For input files, hash them with the vcs layer first
if !task.input_paths.is_empty() {
let files = convert_paths_to_strings(&task.input_paths, &workspace.root)?;
let hashed_files = vcs.get_file_hashes(&files).await?;

hasher.hash_inputs(hashed_files);
if !files.is_empty() {
hasher.hash_inputs(vcs.get_file_hashes(&files).await?);
}
}

// For input globs, it's much more performant to:
Expand Down
29 changes: 21 additions & 8 deletions crates/vcs/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::errors::VcsError;
use crate::vcs::{TouchedFiles, Vcs, VcsResult};
use async_trait::async_trait;
use ignore::gitignore::{Gitignore, GitignoreBuilder};
use moon_utils::fs;
use moon_utils::process::{output_to_string, output_to_trimmed_string, Command};
use moon_utils::{fs, string_vec};
use regex::Regex;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -41,24 +41,38 @@ impl Git {
}

async fn get_merge_base(&self, base: &str, head: &str) -> VcsResult<String> {
let candidates = [
let mut args = string_vec!["merge-base", head];

// To start, we need to find a working base origin
for candidate in [
base.to_owned(),
format!("origin/{}", base),
format!("upstream/{}", base),
];

for candidate in candidates {
if let Ok(hash) = self
] {
if self
.run_command(
&mut self.create_command(vec!["merge-base", &candidate, head]),
true,
)
.await
.is_ok()
{
return Ok(hash);
args.push(candidate.clone());
}
}

// Then we need to run it again and extract the base hash using the found origins
// This is necessary to support comparisons between forks!
if let Ok(hash) = self
.run_command(
&mut self.create_command(args.iter().map(|a| a.as_str()).collect()),
true,
)
.await
{
return Ok(hash);
}

Ok(base.to_owned())
}

Expand Down Expand Up @@ -322,7 +336,6 @@ impl Vcs for Git {
// are displayed as-is and are not quoted/escaped
"-z",
&base,
revision,
]),
false,
)
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#### 🐞 Fixes

- Fixed an issue with a globally installed moon not being executable in PowerShell.
- Fixed an issue with empty files being passed to `git hash-object`.
- Fixed an issue where a `git merge-base` could not be resolved when base and head are provided.

#### ⚙️ Internal

Expand Down

0 comments on commit 75f33bd

Please sign in to comment.