Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--affected failing to resolve main even on full checkout #9320

Open
1 task done
chris-olszewski opened this issue Oct 23, 2024 · 6 comments
Open
1 task done

--affected failing to resolve main even on full checkout #9320

chris-olszewski opened this issue Oct 23, 2024 · 6 comments
Labels
kind: bug Something isn't working

Comments

@chris-olszewski
Copy link
Member

Verify canary release

  • I verified that the issue exists in the latest Turborepo canary release.

Link to code that reproduces this issue

https://github.com/amannn/next-intl

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Linux

Which canary version will you have in your reproduction?

2.2.3

Describe the Bug

Using --affected results in the following log line:

Failed to resolve base ref 'main' from GitHub Actions event: git error: fatal: ambiguous argument 'main': unknown revision or path not in the working tree.

example in GH Actions

Expected Behavior

We shouldn't have get an ambiguous argument when testing out main. Especially with fetch-depth: 0

To Reproduce

See next-intl attempting to use --affected: example job

Additional context

No response

@chris-olszewski chris-olszewski added kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage and removed needs: triage New issues get this label. Remove it after triage labels Oct 23, 2024
@ryanarmstrong
Copy link

ryanarmstrong commented Oct 31, 2024

Had a similar issue over on GitLab. The issue was that GitLab Runner will checkout in a detached HEAD mode, which is not a branch, and thus main isn't a branch there.

The fix was to set TURBO_SCM_BASE: "origin/main"

Looking at the logs in your CI, you are also running in a detached HEAD mode, so the above may solve your issue. Alternatively, you could checkout the main branch so you're not in detached HEAD.

Since it seems like this can happen pretty easily in both GitLab and GitHub, it might be a good idea for Turborepo to update its docs to talk about this. It took me quite some time to figure this out.

@amannn
Copy link

amannn commented Oct 31, 2024

Thanks for chiming in here @ryanarmstrong!

Preferably, I'd like to avoid setting TURBO_SCM_BASE, so that --affected also works when targeting other branches than origin/main. Maybe github.base_ref could work to set this dynamically?

I was curious if Turbo tries to do this for you since apparently --affected should work with zero config in GitHub Actions.

@Amoodaa

This comment was marked as spam.

@ryanarmstrong
Copy link

So I could be wrong, but I think the reason that it works in GitHub actions without any config is that Turborepo is looking for GItHub variables and knows when it's in CI. So it has built-in support for GitHub actions but not for GitLab CI.

I am basing this off of the documentation here. But I can't say this definitively.

@miikebar
Copy link

miikebar commented Nov 25, 2024

For anyone looking for a solution until the issue gets resolved (based on #800 (reply in thread)):

env:
  TURBO_SCM_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

This will set TURBO_SCM_BASE to:

  • the HEAD commit of the branch you’re merging into if it's a PR
  • the HEAD commit SHA on your target branch before the merge for other contexts (i.e. on push)

@amannn
Copy link

amannn commented Nov 26, 2024

@miikebar Seems to work for me, thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants