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

[Bug?]: 'yarn version checkout' fails with "UsageError: No ancestor could be found..." #5291

Closed
1 task
CSHawley opened this issue Feb 23, 2023 · 1 comment
Closed
1 task
Labels
bug Something isn't working

Comments

@CSHawley
Copy link

CSHawley commented Feb 23, 2023

Self-service

  • I'd be willing to implement a fix

Describe the bug

Our CI began failing during yarn version check with the following error:

YN0001: UsageError: No ancestor could be found between any of HEAD and packages/publish, origin/packages/publish, upstream/packages/publish

It's been a while since this was last run, but it was confirmed working on Sep 22, 2022 and no significant changes were made to our Github Actions workflow since.

Executing the command locally produces no errors. The workflow file was also run successfully using https://github.com/nektos/act, which pulls down the necessary images and claims to be configured to match Github's system.

To reproduce

We have not been able to reproduce outside of Github Actions.

.yarnrc.yml

changesetBaseRefs:
  - packages/publish
  - origin/packages/publish
  - upstream/packages/publish
  
...

nodeLinker: node-modules

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-version.cjs
    spec: "@yarnpkg/plugin-version"

yarnPath: .yarn/releases/yarn-3.3.1.cjs

open-pr.yml

name: Package - Open PR

on:
  pull_request:
    types: [opened, synchronize, reopened]
    paths:
      - 'packages/{MY_PACKAGE}/**'

jobs:
  validate-package:
    runs-on: ubuntu-latest
    container:
      image: node:16

    steps:

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

    - name: Get yarn cache directory path
      id: yarn-cache-dir-path
      run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

    - uses: actions/cache@v2
      id: yarn-cache
      with:
        path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
        key: yarn-${{ hashFiles('**/yarn.lock') }}
        restore-keys: |
          yarn-

    - name: yarn install
      shell: bash
      run: yarn install
      env:
        YARN_NPM_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}

    - name: yarn run test
      shell: bash
      run: yarn workspace MY_WORKSPACE run test
      
    - name: yarn run lint
      shell: bash
      run: yarn workspace MY_WORKSPACE run lint

    - name: yarn run build
      shell: bash
      run: yarn workspace MY_WORKSPACE run build

    - name: yarn version check
      shell: bash
      run: yarn version check

Environment

Github Actions
- Image: ubuntu-22.04 (latest)
- Image Version: 20230217.1
- Node: 16.19.1
- Yarn: 3.3.1

The .yarn/** and .yarnrc.yml files are committed to our repo, so the yarn version is consistent across our CI and dev environments.

Additional context

We use this workflow to validate that our Github package updates are properly versioned before being published.

I've experienced the same issue using different runner images (ubuntu-20.04, ubuntu-18.04) and an older version of yarn (3.2.1)

Failure log example:

Run yarn version check
➤ YN0001: UsageError: No ancestor could be found between any of HEAD and packages/publish, origin/packages/publish, upstream/packages/publish
    at Object.MAe (/__w/project/.yarn/releases/yarn-3.3.1.cjs:593:8009)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async $v (/__w/project/.yarn/plugins/@yarnpkg/plugin-version.cjs:433:8625)
    at async /__w/project/.yarn/plugins/@yarnpkg/plugin-version.cjs:446:10281
    at async Function.start (/__w/project/.yarn/releases/yarn-3.3.1.cjs:409:2347)
    at async t_.executeStandard (/__w/project/.yarn/plugins/@yarnpkg/plugin-version.cjs:446:10192)
    at async t_.execute (/__w/project/.yarn/plugins/@yarnpkg/plugin-version.cjs:446:3414)
    at async t_.validateAndExecute (/__w/project/.yarn/releases/yarn-3.3.1.cjs:63:13148)
    at async OA.run (/__w/project/.yarn/releases/yarn-3.3.1.cjs:77:2354)
    at async OA.runExit (/__w/project/.yarn/releases/yarn-3.3.1.cjs:77:2538)
➤ YN0000: Failed with errors in 0s 54ms
Error: Process completed with exit code 1.

Some things I've tried:

  • Cleared/disabled all CI caches and ran yarn install from scratch
  • Updated to the latest Github actions (i.e. actions/checkout@v3), ruled out issues with fetch-depth, etc.
  • Tried running the workflow on different branches
@CSHawley CSHawley added the bug Something isn't working label Feb 23, 2023
@CSHawley
Copy link
Author

CSHawley commented Mar 3, 2023

I determined this is not an issue with Yarn itself, but with actions/checkout. Checkout is not correctly adding the repository to git's safe directory list when run inside a container, as observed here: actions/checkout#1169. My understanding is yarn version check uses git diff to evaluate changes, which is likely failing internally with "fatal: detected dubious ownership..."

Following checkout with git config --system --add safe.directory <path> did unblock us. I hope this helps anyone else experiencing similar issues. Closing as resolved.

@CSHawley CSHawley closed this as completed Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant