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

[Feature] yarn version should not fail when exact version is given #4014

Open
1 of 2 tasks
macrozone opened this issue Jan 25, 2022 · 4 comments
Open
1 of 2 tasks

[Feature] yarn version should not fail when exact version is given #4014

macrozone opened this issue Jan 25, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@macrozone
Copy link

  • I'd be willing to implement this feature (contributing guide)
  • 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

@macrozone macrozone added the enhancement New feature or request label Jan 25, 2022
@macrozone
Copy link
Author

macrozone commented Jan 25, 2022

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"]

@gunwooa
Copy link

gunwooa commented Mar 30, 2022

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"]

감사합니다

@rstaib
Copy link

rstaib commented Sep 23, 2022

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!!!

@psychobolt
Copy link

psychobolt commented Dec 13, 2023

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 # (optional) fallback, omit if BASE_REF is diverged from here
# .env.defaults
BASE_REF=origin/main # 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...

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

No branches or pull requests

4 participants