Skip to content

Commit 619c318

Browse files
committed
build: fix benchmark sha resolution breaking when compare ref is abbreviated (angular#50767)
When we fetch e.g. `main`, the branch name will not be available locally, and `rev-parse` will fail later. We can make the logic more safe by just using `FETCH_HEAD` then. PR Close angular#50767
1 parent 17a95da commit 619c318

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

scripts/benchmarks/index.mts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ async function prepareForGitHubAction(commentBody: string): Promise<void> {
9797
// Attempt to find the compare SHA. The commit may be either part of the
9898
// pull request, or might be a commit unrelated to the PR- but part of the
9999
// upstream repository. We attempt to fetch/resolve the SHA in both remotes.
100-
let compareRefSha: string|null = null;
101-
try {
102-
compareRefSha = git.run(['rev-parse', compareRefRaw]).stdout.trim();
103-
} catch {
100+
let compareRefSha = git.runGraceful(['rev-parse', compareRefRaw]).stdout.trim();
101+
if (compareRefSha === '') {
104102
git.run(['fetch', '--depth=1', git.getRepoGitUrl(), compareRefRaw]);
105-
compareRefSha = git.run(['rev-parse', compareRefRaw]).stdout.trim();
103+
compareRefSha = git.run(['rev-parse', 'FETCH_HEAD']).stdout.trim();
106104
}
107105

108106
setOutput('compareSha', compareRefSha);

0 commit comments

Comments
 (0)