berry
                                
                                 berry copied to clipboard
                                
                                    berry copied to clipboard
                            
                            
                            
                        [Feature] `yarn version` should not fail when exact version is given
- [ ] I'd be willing to implement this feature (contributing guide)
- [x] This feature is important to have in this repository; a contrib plugin wouldn't do
Describe the user story
As a developer i want to pass the exact version to yarn version without yarn checking for any git history and fail, because i want to control the exact version.
Currently, yarn version v1.2.3-xxx will fail on branches with Usage Error: No ancestor could be found between any of HEAD and master, origin/master, upstream/master, main, origin/main, upstream/main, altough yarn has no business in checking the branch as it already has been given the exact version to set.
Motiviation: there are a lot of other tools that can derive a version string based on a commit. yarn isn't the only one (e.g. semantic-release). This is in particular important if you need the exact same version string for other artifacts during a pipeline. yarn
Describe the solution you'd like
When passing the explicit version, yarn should not check any git history and fail.
Describe the drawbacks of your solution
there is no drawback. In my opinion its even a bug, not a missing feature.
Describe alternatives you've considered
dropping yarn completly and going back to npm or writing the versions manually
i thought i could set changesetBaseRefs: [] in yarnrc.yml, but that yields:
"Can't run this command with zero base refs specified."
edit:
also changesetBaseRefs: ["*"] does not work.
EDIT 2:
workaround
setting changesetBaseRefs: ["HEAD"]
i thought i could set
changesetBaseRefs: []in yarnrc.yml, but that yields:"Can't run this command with zero base refs specified."
edit:
also
changesetBaseRefs: ["*"]does not work.EDIT 2:
workaround
setting
changesetBaseRefs: ["HEAD"]
감사합니다
i thought i could set changesetBaseRefs: [] in yarnrc.yml, but that yields:
"Can't run this command with zero base refs specified."
edit:
also changesetBaseRefs: ["*"] does not work.
EDIT 2:
workaround
setting changesetBaseRefs: ["HEAD"]
worked for me 👍🏻 thanks @macrozone!!!
I believe yarn check computes the latest reachable ref. Yarn supports environment variables in the config. You can also set a environment variable in github CI workflows, however it doesn't override the defaults without a .env file:
# .yarnrc.yml
injectEnvironmentFiles:
  - .env.defaults
  - .env?
changesetBaseRefs:
  - ${BASE_REF:-origin/main}
# .env.defaults
BASE_REF=origin/your-branch # to be overriden
# .github/workflows/pull-request.yml
on:
  pull-request:
    - main
    - release/**
# ...
jobs:
  check-version:
    runs-on: ubuntu-latest
    steps:
      - name: Version check
        run: yarn version check
        env: # FYI, does not override defaults from injectEnvironmentFiles (it only fills missing variables)
          BASE_REF: origin/${{ github.base_ref }} # base_ref only avail in pull-request events. 
If you have injectEnvironmentFiles, you can't override them even in POSIX e.g. BASE_REF=origin/feature/v1 yarn .... So you need a step before version check or any other yarn scripts in the workflow that writes to the .env file:
    steps:
      - name: Inject base ref variable
        run: echo "BASE_REF=origin/${{ github.base_ref }}" >> .env
    # version check...
another solution is to set fetch-depth: 0 on actions/checkout if you're using github actions