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

bad revision 'master' when using Lerna #118

Closed
iansu opened this issue Dec 19, 2019 · 15 comments
Closed

bad revision 'master' when using Lerna #118

iansu opened this issue Dec 19, 2019 · 15 comments

Comments

@iansu
Copy link

iansu commented Dec 19, 2019

I am trying to use the lerna run build --since master command in an action to only build packages that have changed in the branch. Lerna is running this git command to do that: git diff --name-only master -- packages/<package name>. That results in this error: lerna ERR! fatal: bad revision 'master'.

I've tried many different options and commands from the README in this project but nothing seems to work. I've set the fetch depth to 0 to fetch all history and I've tried manually specifying a git command like so:

- uses: actions/checkout@v2
- run: |
    git fetch --prune --unshallow origin master

Nothing seems to make master available for Lerna to compare against. Any help would be appreciated.

@evocateur
Copy link

What happens if you use refs/remotes/origin/master as the argument to --since?

lerna run build --since refs/remotes/origin/master

As far as I can tell, reading the source of this action, the only explicit symbolic ref available in a branch build will be the branch itself, not the default branch (usually master). Using the fully-qualified refs/... path ...might work?

@iansu
Copy link
Author

iansu commented Jan 2, 2020

I did manage to get this working by doing a few things (which might not all be necessary):

  1. I added fetch-depth: 0 to the checkout action
  2. I added git fetch --prune to the checkout action
  3. I changed my lerna command to lerna run build --since origin/master

That seems to do the trick so this issue can probably be closed, however it would be nice if this were in the docs. I'd be happy to submit a PR if this is something others think should be included.

@dmpetrov
Copy link

dmpetrov commented Jan 2, 2020

I had a similar issue with fetching master (not related to Lerna). The last comment from @iansu helped - especially origin/master part.

I agree that it should be in the docs. I'd expect something like "Fetch master branch" item right after "Fetch all branches".

@ericsciple
Copy link
Contributor

Is the issue because fetch depth is 1 by default? I'm updating to docs to make this more clear.

@dmpetrov
Copy link

dmpetrov commented Jan 2, 2020

@ericsciple depth=1 is only one reason. origin/master was another reason (master didn't work).

@ericsciple
Copy link
Contributor

@dmpetrov thanks. Sorry I'm missing something. Excluding lerna from the picture, does anything require origin/master?

The ref inputs master and refs/heads/master both work, but origin/master does not.

Here is my workflow:

on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: master                # works
      - continue-on-error: true
        run: "rm -rf * ; rm -rf .*"
      - uses: actions/checkout@v2
        with:
          ref: refs/heads/master     # works
      - continue-on-error: true
        run: "rm -rf * ; rm -rf .*"
      - uses: actions/checkout@v2
        with:
          ref: origin/master         # does not work

@dmpetrov
Copy link

dmpetrov commented Jan 3, 2020

@ericsciple I needed to get the last sha in master git log -n 1 master --pretty=format:%H while the workflow is working in my last commit in PR. So, I need a full git history before running the command:

      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      ...
      - name: whatever
        run: |
            echo "Fetch the whole repository"
            git fetch --prune

Even with this "full git history" I'm unable to run the command

      - name: whatever2
        run: |
            LAST_COMMIT=$(git log -n 1 master --pretty=format:%H)
>> 
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

If I specify origin/master it works just fine. I'd appreciate it if you give me a better explanation of the issue.

@ericsciple
Copy link
Contributor

@dmpetrov this works for me:

on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: master
      - run: |
          git log -n 1 master --pretty=format:%H

master is the local branch (refs/heads/master) whereas origin/master is the remote branch (refs/remotes/origin/master). Technically they may not point to the same thing.

In your case it appears you don't have a local branch master. What does git branch show?

@iansu
Copy link
Author

iansu commented Jan 3, 2020

If this is running on a branch/PR you can't really set ref: master because you want to checkout the branch not master. So there is no local reference to master even if you run git fetch.

@dmpetrov
Copy link

dmpetrov commented Jan 3, 2020

@iansu is right.
It seems like I have to use origin/ in git log or fetch origin/master.

@ericsciple
Copy link
Contributor

ericsciple commented Jan 4, 2020

Closing this issue now. I updated the docs to mention in the readme summary that only a single commit is fetched by default (with fetch depth 0)

@iansu
Copy link
Author

iansu commented Jan 6, 2020

I think mentioning that in the docs is helpful but it doesn't really solve the problem. You could add an option to the checkout action to always fetch master in addition to the current ref or make it so ref takes an array of things to check out.

It would also be nice to add an example in the documentation that shows how to use Lerna with GitHub Actions. It's a very commonly used tool with monorepos. I'd be happy to help with any of this work.

@bobaaaaa
Copy link

bobaaaaa commented Mar 5, 2020

So for everyone who lands here via google. My workflow looks like:

# example lerna task
lerna run test --since origin/master
- uses: actions/checkout@v2
- run: |
    git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master

I only need the origin/master. If you need all branches use this run command (via docs)

git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*

@maneetgoyal
Copy link

This worked too:

      - name: Checkout Repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0 
      ...
      ...
      ...

      - name: Lint
        run: npx lerna run lint --since origin/master

This looked cleaner but #118 (comment) looks more resource efficient.

@JounQin
Copy link

JounQin commented Mar 25, 2021

--since does not work to me, it is not available anymore. fetch-depth: 0 does the trick to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants