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

Branch for dependency (base package) provided in sfdx-project.json is ignored when creating package version. #2183

Closed
avesolovksyy opened this issue Jun 2, 2023 · 9 comments

Comments

@avesolovksyy
Copy link

Summary

Getting an error NoReleaseVersionFoundForBranchError when creating package version with 'sfdx package version create' command for my extension package. Error points to version of base package specified as dependency for extension package in sfdx-project.json. It seems like 'branch' attribute specified for dependency is completely ignored, that's why it's looking for base package version with with sort of empty branch and cannot find it.
Please note, we've already debugged the issue at code level and provided exact place in js code where we made a tweak that works for us - just check additional notes section, issue is very obvious at code base level, since code behaviour doesn't match code description in comments right in provided file.

Steps To Reproduce:

  1. Create simple MyBasePackage
  2. Create e.g. beta version of base package specifying key '--branch=my-test-branch' for package version create command.
  3. Create simple MyExtensionPackage which depends from MyBasePackage version created from 'my-test-branch'. Bellow is sfdx-project.json for MyExtensionPackage
{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true,
      "package": "MyExtensionPackage",
      "versionName": "My Extension Name",
      "versionDescription": "My Extension Description",
      "versionNumber": "1.0.0.NEXT",
      "dependencies": [
        {
          "package": "MyBasePackage",
          "versionNumber": "1.8.0.LATEST",
		  "branch": "my-test-branch"
        }
      ]
    }
  ],
  "packageAliases": {
    "MyBasePackage": "0HoBBBBBBBBBBBBBBB",
    "MyExtensionPackage": "0HoEEEEEEEEEEEEEEE"
  },
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "57.0"
  
}
  1. Try to create package version of MyExtensionPackage, no branch is provided as command key at all.

Expected result

Package version should be created successfully.

Actual result

Error has been thrown with a stack trace:

NoReleaseVersionFoundForBranchError: No version number was found in Dev Hub for package id 0HoBBBBBBBBBBBBBBB and branch undefined and version number 1.8.0.LATEST.
    at Messages.createError (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@salesforce/core/lib/messages.js:428:16)
    at PackageVersionCreate.resolveBuildNumber (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@salesforce/packaging/lib/package/packageVersionCreate.js:175:32)
    at async PackageVersionCreate.retrieveSubscriberPackageVersionId (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@salesforce/packaging/lib/package/packageVersionCreate.js:108:37)
    at async Promise.all (index 1)
    at async PackageVersionCreate.createPackageVersionCreateRequestFromOptions (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@salesforce/packaging/lib/package/packageVersionCreate.js:288:30)
    at async PackageVersionCreate.packageVersionCreate (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@salesforce/packaging/lib/package/packageVersionCreate.js:477:25)
    at async PackageVersion.create (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@salesforce/packaging/lib/package/packageVersion.js:92:30)
    at async PackageVersionCreateCommand.run (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@salesforce/plugin-packaging/lib/commands/package/version/create.js:60:24)
    at async PackageVersionCreateCommand._run (C:/Users/myuser/AppData/Local/sfdx/client/7.203.6-1da7df1/node_modules/@oclif/core/lib/command.js:117:22)

Pay attention, here it's referring to MyBasePackage id and version in error message (again, that's because it is looking for version in empty/undefined branch, i.e. version without branch, and we don't have such version of MyBasePackage). According to official sfdx guide it should respect branch specified for dependency, thus MyBasePackage version 1.0.8.x should be found.

System Information

It's problem in logic at code base level, not windows/linux specific issue, but still:

{
  "cliVersion": "sfdx-cli/7.203.6",
  "architecture": "win32-x64",
  "nodeVersion": "node-v18.15.0",
  "osVersion": "Windows_NT 10.0.19044",
  "shell": "cmd.exe",
  "rootPath": "C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.203.6-1da7df1",
  "pluginVersions": [
    "@dx-cli-toolbox/sfdx-toolbox-package-utils 0.8.4 (user)",
    "@mshanemc/plugin-streaming 1.1.7 (user)",
    "@mshanemc/sfdx-sosl 1.1.0 (user)",
    "@oclif/plugin-autocomplete 2.2.0 (core)",
    "@oclif/plugin-commands 2.2.15 (core)",
    "@oclif/plugin-help 5.2.9 (core)",
    "@oclif/plugin-not-found 2.3.23 (core)",
    "@oclif/plugin-plugins 3.1.0 (core)",
    "@oclif/plugin-search 0.0.17 (core)",
    "@oclif/plugin-update 3.1.15 (core)",
    "@oclif/plugin-version 1.3.4 (core)",
    "@oclif/plugin-warn-if-update-available 2.0.37 (core)",
    "@oclif/plugin-which 2.2.21 (core)",
    "apex 2.2.21 (core)",
    "auth 2.7.16 (core)",
    "community 2.2.12 (core)",
    "custom-metadata 2.1.22 (core)",
    "data 2.3.19 (core)",
    "deploy-retrieve 1.10.1 (core)",
    "info 2.6.14 (core)",
    "limits 2.3.17 (core)",
    "org 2.9.1 (core)",
    "packaging 1.17.1 (core)",
    "schema 2.3.10 (core)",
    "settings 1.4.9 (core)",
    "signups 1.4.19 (core)",
    "source 2.10.10 (core)",
    "telemetry 2.2.0 (core)",
    "templates 55.4.17 (core)",
    "trust 2.4.19 (core)",
    "user 2.3.14 (core)",
    "@salesforce/sfdx-scanner 3.12.0 (user)",
    "dependencies-cli 2.0.1 (user)",
    "etcopydata 2.1.1 (user)",
    "sfdmu 4.27.0 (user)",
    "sfdx-cli 7.203.6 (core)",
    "sfdx-waw-plugin 1.5.0 (user)",
    "sfpowerkit 6.1.0 (user)",
    "shane-sfdx-plugins 4.43.0 (user)",
    "territory-management-toolkit 1.0.0 (user)",
    "texei-sfdx-plugin 1.17.3 (user)"
  ]
}

Additional information

We've investigated the issue and found that branch is evaluated in a wrong way for dependency at code level.
Affected file:
C:\Users\myuser\AppData\Local\sfdx\client\7.203.6-1da7df1\node_modules@salesforce\packaging\lib\package\packageVersionCreate.js

lines 104-105:

        // use the dependency.branch if present otherwise use the branch of the version being created
        const branch = dependency.branch === '' ? dependency.branch : this.options.branch;

^^^ As you can see, here it picks up branch from dependency only when it is empty, which contradicts even the comment above that line. So we've updated the line 105 to the following to match the behaviour described in comment:

        // use the dependency.branch if present otherwise use the branch of the version being created
        const branch = (dependency.branch || dependency.branch === '') ? dependency.branch : this.options.branch;

And we created extension version successfully after this.

Please take a look with priority, since dependency management is a crucial thing for us ISV.
This one seems to be a low-hanging fruit.

Thanks in advance.

@avesolovksyy avesolovksyy added the investigating We're actively investigating this issue label Jun 2, 2023
@github-actions
Copy link

github-actions bot commented Jun 2, 2023

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

@cristiand391
Copy link
Member

Hey @avesolovksyy , sorry for the late reply!

good catch, this was fixed last week and was included in the RC today:
forcedotcom/packaging#310

release notes for sf:
https://github.com/forcedotcom/cli/tree/main/releasenotes/sf#1820-june-14-2023-stable-rc

sfdx RC with this fix will be published tomorrow, if you want to give it try follow this instructions:
https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli_rc.htm

@avesolovksyy
Copy link
Author

@cristiand391
I have some concerns regarding fix you are referring to.
Seems like it doesn't handle correctly the situation when empty branch is specified explicitly in sfdx-project.json file for dependency package.
Please take a look. Added comment with details here: forcedotcom/packaging#310 (comment)

@David-Polehonski
Copy link

David-Polehonski commented Jun 9, 2023

@avesolovksyy thanks for taking a look at this; and I'm glad I wasn't the only person affected!

I've added two new unit tests to describe the intended behaviour more accurately and can verify they fail as per your expectation:
image

I'm opening a pull request to address this on the packaging project. Can you help verify it works before it gets merged?

@avesolovksyy
Copy link
Author

@David-Polehonski
Thank you.
It seems to be working the way I expect now with empty branch for dependency.

@bdovh
Copy link

bdovh commented Jun 20, 2023

@avesolovksyy thanks for posting this

@bdovh
Copy link

bdovh commented Jun 23, 2023

@cristiand391
Copy link
Member

So looks like this was fixed in https://github.com/forcedotcom/cli/tree/main/releasenotes/sfdx#72056-june-15-2023

yep, thanks again @avesolovksyy and David for fixing this 🏆

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

4 participants