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

nx affected:apps fails with error fatal: Not a valid object name master #2170

Closed
whimzyLive opened this issue Dec 10, 2019 · 18 comments
Closed

Comments

@whimzyLive
Copy link

whimzyLive commented Dec 10, 2019

Prerequisites

Please answer the following questions for yourself before submitting an issue.
YOU MAY DELETE THE PREREQUISITES SECTION.

  • [ x ] I am running the latest version
  • [ x ] I checked the documentation (nx.dev) and found no answer
  • [ x ] I checked to make sure that this issue has not already been filed
  • [ x ] I'm reporting the issue to the correct repository (not related to React, Angular or any dependency)

Expected Behavior

nx affected:apps --plain should display list of affected apps.
we use this comma separated list of affected apps to determine what apps to deploy

What is the current behavior?
No

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. upgrade to latest nrwl
  2. init workspace
  3. npm run affected:apps -- --plain

Context

Please provide any relevant information about your setup:

  • Interesting thing to note, I do not see any error when running from my local machine but from ci.
    A minimal reproduction scenario allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.

Failure Logs

Please include any relevant log snippets or files here.
Above command fails with

> [email protected] affected:apps /home/runner/work/xxxx/xxxx
> nx affected:apps

fatal: Not a valid object name master
/home/runner/work/xxxx/xxxx/node_modules/@nrwl/workspace/node_modules/yargs/yargs.js:1109
      else throw err
           ^

Error: Command failed: git merge-base master HEAD
fatal: Not a valid object name master

    at checkExecSyncError (child_process.js:629:11)
    at Object.execSync (child_process.js:666:13)
...
...
...
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] affected:apps: `nx affected:apps`
npm ERR! Exit status 1
npm ERR! 
@FrozenPandaz
Copy link
Collaborator

Hi, do you have a master branch checked out locally?

If master is not your default branch, you should set --base to your default branch:

For Example:

npm run affected:apps -- --plain --base develop

@whimzyLive
Copy link
Author

I am running this on CI and yes I do have a branch called master, but surprising this is that it worked with earlier version, but not after updating to latest.

@andrebraghini
Copy link

I have the same problem on CI using Github Actions and it only happens when running on a branch other than master.

When running on the master it works without problems.

@whimzyLive
Copy link
Author

whimzyLive commented Feb 25, 2020

@DedoxBR I resolved this by replacing above command with nx affected:apps --base=origin/master --head=origin/master --plain
Ref:

@andrebraghini
Copy link

andrebraghini commented Feb 25, 2020

@DedoxBR I resolved this by replacing above command with nx affected:apps --base=origin/master --head=origin/master --plain
Ref:

@whimzyLive it didn't work for me.

If it helps, I created a clean repository simulating the problem here:
https://github.com/andrebraghini/nx-affected-test

@MarcGue
Copy link

MarcGue commented Mar 16, 2020

Is there anything new? Having the same problem. Having a default branch "develop" and trying to test and build affected with GitHub Actions, but no matter what i set as base head or anything else helps.
Always getting "Not a valid object name xxx"

@cprell
Copy link

cprell commented Mar 20, 2020

I run affected:build like this:

npm run affected:build -- --base=$NX_BASE

where NX_BASE is different depending on whether a push event or a pull request triggers the workflow.

In case of a push, we want to look at the commit id of the second newest commit, which translates to
export NX_BASE=$(git rev-parse HEAD~1)

Keep in mind that you need to use the checkout action earlier with a fetch depth of at least 2 for this to work.
- uses: actions/checkout@v2 with: fetch-depth: 2

In case of a pull request, it could look like something like this
export NX_BASE_TEMP=$(git log --format=%H -n 1 origin/${{ github.base_ref }})

This is the newest commit id of the target branch. I needed to use git fetch origin beforehand for this to work.

Hope this helps a bit!

@evtk
Copy link

evtk commented Mar 21, 2020

Is there anything new? Having the same problem. Having a default branch "develop" and trying to test and build affected with GitHub Actions, but no matter what i set as base head or anything else helps.
Always getting "Not a valid object name xxx"

are you sure you aren't forgetting the double dash?

WORKS
npm run affected:apps -- --base develop
vs

DOESN'T WORK
npm run affected:apps --base develop

@creadicted
Copy link

creadicted commented Mar 25, 2020

I had to use git fetch before using it in my CI environment

@Plysepter
Copy link

Plysepter commented Apr 2, 2020

So I encountered this issue in Github Actions and after some debugging I have found the following:

By default Github Actions checkout action only pulls the latest commit in a detached head state. I have found this causes any git operation for comparison to break.

I resolved the issue in Github Actions with these steps:

- uses: actions/checkout@v2
  with:
      ref: ${{ github.event.pull_request.head.ref }}
      fetch-depth: 0
- run: |
       git fetch --no-tags --prune --depth=5 origin master

The key here is changing the default ref so that it pulls the branch instead of just the single commit.
I am comparing for a PR so I am only fetching master and the depth flag could be adjusted/removed for different use cases and you could fetch as many branches as your use case needs.

- name: Lint affected projects
  run: ./node_modules/.bin/nx affected --target=lint --base=origin/master --head=HEAD --parallel --maxParallel=2

To make this work I had to ensure I had origin/master instead of just master for the base flag even though the master branch was pulled. I don't have an exact explanation as to why but this did allow my lint, format and testing jobs to succeed.

I hope this can be of use to others experiencing this issue

Also link to github checkout action thread regarding this use case: actions/checkout#155
(edit: improved formatting, added link to thread)

@devinshoemaker
Copy link
Contributor

@Plysepter thanks for the suggestion, however, I am still having issues.

This is my config:

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 12.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: git fetch --no-tags --prune --depth=5 origin master
    - run: yarn install --frozen-lockfile
    - run: yarn affected:build --base=origin/master --head=HEAD
      env:
        CI: true

And I get the error Error: Command failed: git merge-base origin/master HEAD

Does anything stick out to you that I might be doing wrong?

@whimzyLive
Copy link
Author

@devinshoemaker
In your run step replace yarn affected:build --base=origin/master --head=HEAD with yarn affected:build -- --base=origin/master --head=HEAD

this extra '--' is required to escape args. Have a look at this

also please close the issue this works for you.

@devinshoemaker
Copy link
Contributor

@whimzyLive thanks for the suggestion. That's no longer needed for Yarn while it still is for NPM. I gave it a try anyway and still got the same result, but with the added warning of

warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ nx affected:build --base=origin/master --head=HEAD

@Plysepter
Copy link

@devinshoemaker you may want to replace your - uses: actions/checkout@v2 step with the check out step I have in the first code block of my previous comment.

Github Actions checkout action only pulls the latest commit in a detached head state by default and only pulls in the most recent commit. You have to configure actions/checkout@v2 to pull the branch instead of just the last commit made. This is what fixed the detached head state for myself. Would you mind giving it a try and letting us know if this resolves your error?

@devinshoemaker
Copy link
Contributor

devinshoemaker commented Apr 6, 2020

@Plysepter ah, thank you! That definitely helped. Here's my current best working config:

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 12.x]

    steps:
    - uses: actions/checkout@v2
      with:
        ref: ${{ github.event.pull_request.head.ref }}
        fetch-depth: 0
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: git fetch --no-tags --prune --depth=5 origin master
    - run: yarn install --frozen-lockfile
    - run: yarn affected:build --base=origin/master
      env:
        CI: true

I think this issue can be closed now.

@jaysoo jaysoo closed this as completed Apr 15, 2020
andrebraghini added a commit to andrebraghini/nx-affected-test that referenced this issue Apr 29, 2020
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
gund added a commit to orchestratora/orchestrator that referenced this issue Jun 29, 2020
This should fix issue with NX CLI (see nrwl/nx#2170)
mremolt pushed a commit to clear-group-bu-java/angular-workshop that referenced this issue Dec 4, 2020
echonax added a commit to echonax/nx that referenced this issue Feb 4, 2022
While our team was trying to migrate to Nx, we found out this issue: nrwl#2170
The documentation doesn't mention about this behaviour but in our case setting the --base to origin/{current_branch} fixed it. I've set the env variable accordingly in the md file.
echonax added a commit to echonax/nx that referenced this issue Feb 4, 2022
While our team was trying to migrate to Nx, we found out this issue: nrwl#2170
The documentation doesn't mention about this behaviour but in our case setting the --base to origin/{current_branch} fixed it. I've set the env variable accordingly in the md file.
echonax added a commit to echonax/nx that referenced this issue Feb 4, 2022
While our team was trying to migrate to Nx, we found out this issue: nrwl#2170
The documentation doesn't mention about this behaviour but in our case setting the --base to origin/{current_branch} fixed it. I've set the env variable accordingly in the md file.
@Madebyspeedster
Copy link

@DedoxBR I resolved this by replacing above command with nx affected:apps --base=origin/master --head=origin/master --plain Ref:

Tnx. works for me,
so locally I had branch accessible with branch=x but on CI it should be branch=origin/x

@nurbashanghai
Copy link

same situation, nothing works

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests