microsoft/rushstack

[rush] rush change cannot find head branch on CI

Closed this issue · 6 comments

Please prefix the issue title with the project name i.e. [rush], [api-extractor] etc.

Is this a feature or a bug?

  • Feature
  • Bug

Please describe the actual behavior.
Running rush change -v in Github Actions fails with fatal: origin/master...HEAD: no merge base. Running it locally does not fail.

If the issue is a bug, how can we reproduce it? Please provide detailed steps and include a GitHub branch if applicable. Your issue will get resolved faster if you can make it easy to investigate.
Here's the action with the error: https://github.com/dbartholomae/lambda-middleware/runs/959082417?check_suite_focus=true
And this is the code at the relevant commit: https://github.com/dbartholomae/lambda-middleware/tree/951dc340d44352f417941180cdce3274d7f74a61

What is the expected behavior?
It should also not fail in the Github Action.

If this is a bug, please provide the tool version, Node.js version, and OS.

  • Tool: Rush
  • Tool Version: 5.30.2
  • Node Version: 12.1.8.3
    • Is this a LTS version? Yes
    • Have you tested on a LTS version? Yes
  • OS: Ubuntu 18.04.4

Can you try increasing your checkout depth? The error that you're getting is saying that the git diff operation that rush change -v is tying to execute can't find a common commit between the checked-out branch and origin/master.

Thanks, that's it! It's not related to rush, so sorry for bothering and thanks for the help.
Specifically actions/checkout@v2 by default only fetches depth 1. The change that solved it was:

    - uses: actions/checkout@v2
      with:
        fetch-depth: 0

Hey folks, I stumbled upon this after a week-long debugging session. Changing the depth of the git fetch solved my problem.

I think the error shown is very cryptic and could be nice to have a disclaimer that the depth of the fetch should not be shallow. Could you add at least a note in the docs about this?

Filed related ticket #3805 to improve the error message.

I'm seeing the new error message from #3805 in my new Azure DevOps build pipeline

Starting: Verify Change Logs
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.212.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
rush change --verify
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/92b71b28-c9f4-4d4c-ad4f-cdc10148c113.sh


Rush Multi-Project Build Tool 5.86.0 - https://rushjs.io/
Node.js version is 14.21.1 (LTS)


Starting "rush change"

The target branch is origin/main
Checking for updates to origin/main...
Error fetching git remote branch origin/main. Detected changed files may be incorrect.
Unable to determine merge base for branch "origin/main". This can occur if the current clone is a shallow clone. If this clone is running in a CI pipeline, check your pipeline settings to ensure that the clone depth includes the expected merge base. If this clone is running locally, consider running "git fetch --deepen=<depth>".
##[error]Bash exited with code '1'.
Finishing: Verify Change Logs

However this build pipeline is automatically getting the checkout step injected by Azure DevOps so I'm not quite sure how to override the fetch depth

Does anyone have examples from other ADO build pipelines where they've gotten rush check -v to work after overcoming this issue? Presumably there is some kind of - checkout yaml build step magical incantation that works for rush monorepos

@iclanton would you happen to know?

Nevermind, I found it.

It looks like you can set the Agent.Source.Git.ShallowFetchDepth environment variable to configure the default checkout task to use a specific depth

I did this which resolved the issue

variables:
  - name: Agent.Source.Git.ShallowFetchDepth
    value: 0