forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
491 stars 78 forks source link

`sourceApiVersion` not being respected in `sf package version create` command #2923

Closed Brian-Triplett closed 3 months ago

Brian-Triplett commented 3 months ago

Summary

We are creating a package with the sf package version create command. According to this doc the sourceApiVersion should take precedence; however, the resulting package version is being created with the latest API version (61.0).

Steps To Reproduce

  1. Create a project with sourceApiVersion set to not the latest. Here is the one we are using
    {
    "namespace": "nCinoCB",
    "sfdcLoginUrl": "https://login.salesforce.com",
    "sourceApiVersion": "59.0",
    "packageDirectories": [
    {
      "default": true,
      "path": "src/nCinoCB",
      "package": "Banking Advisor",
      "versionDescription": "nCino Gen AI",
      "versionNumber": "3.0.0.NEXT",
      "ancestorVersion": "HIGHEST",
      "dependencies": [
        {
          "package": "nFORCE@2.2458"
        },
        {
          "package": "nCino Cloud Banking Apex SDK@1.17.0"
        },
        {
          "package": "nCino Cloud Banking Web Component SDK@7.6"
        }
      ]
    }
    ],
    "packageAliases": {
    "Banking Advisor": "0HoHu000000XZMYKA4",
    "nFORCE@2.2458": "redacted",
    "nCino Cloud Banking Apex SDK@1.17.0": "redacted",
    "nCino Cloud Banking Web Component SDK@7.6": "redacted"
    },
    }
  2. Run sf package version create --json --skip-ancestor-check --version-number 3.37.0.NEXT --definition-file config/project-scratch-def.json --package Banking Advisor --installation-key-bypass --code-coverage --version-description https://github.com/ncino/force-banking-advisor/actions/runs/9483764570 --version-name ver 3.37.0

Expected result

A package created with the sourceApiVersion specified in the sfdx-project.json

Actual result

The following error results when installing into orgs not on the Summer '24 release

This package can't be installed.
There are problems that prevent this package from being installed.
Mismatching Versions    
The AppExchange Application or component you have selected is not yet available on your instance of salesforce.com. Please check back in a few days to retry the installation. Press the back button of your browser now and bookmark the AppExchange Directory page so that you can find it later.
{
    "attributes": {
        "type": "Package2Version",
        "url": "/services/data/v61.0/tooling/sobjects/Package2Version/05iHu000000Cd0YIAS"
    },
    "Package2Id": "0HoHu000000XZMYKA4",
    "SubscriberPackageVersionId": "04tHu000003iw5QIAQ",
    "Name": "ver 3.37.0",
    "Description": "https://github.com/ncino/force-banking-advisor/actions/runs/9483764570",
    "Tag": null,
    "Branch": null,
    "AncestorId": "04tHu000003iw4IIAQ",
    "ValidationSkipped": false,
    "MajorVersion": 3,
    "MinorVersion": 37,
    "PatchVersion": 0,
    "BuildNumber": 4,
    "IsReleased": false,
    "ConvertedFromVersionId": " ",
    "ReleaseVersion": 61,
    "BuildDurationInSeconds": 1250,
    "SubscriberPackageVersion": {
        "attributes": {
            "type": "SubscriberPackageVersion",
            "url": "/services/data/v61.0/tooling/sobjects/SubscriberPackageVersion/04tHu000003iw5QIAQ"
        },
        "Dependencies": {
            "ids": [*dependencies redacted*]
        }
    },
    "CreatedById": "0051400000CYKKvAAP",
    "CodeCoveragePercentages": {
        "codeCovPercentages": [*redacted for brevity*]
    },
    "Version": "3.37.0.4",
    "PackageType": "Managed",
    "AncestorVersion": "3.36.0.3",
    "CodeCoverage": {
        "apexCodeCoveragePercentage": 91
    },
    "HasPassedCodeCoverageCheck": true,
    "Package2": {
        "IsOrgDependent": "N/A"
    },
    "HasMetadataRemoved": "No"
}

System Information

Running inside of a Github Action with default Ubuntu image

{
  "architecture": "darwin-x64",
  "cliVersion": "@salesforce/cli/2.44.8",
  "nodeVersion": "node-v20.11.0",
  "osVersion": "Darwin 23.5.0",
  "rootPath": "/Users/briantriplett/.nvm/versions/node/v20.11.0/lib/node_modules/@salesforce/cli",
  "shell": "zsh",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.1.2 (core)",
    "@oclif/plugin-commands 4.0.2 (core)",
    "@oclif/plugin-help 6.1.0 (core)",
    "@oclif/plugin-not-found 3.2.2 (core)",
    "@oclif/plugin-plugins 5.2.2 (core)",
    "@oclif/plugin-search 1.1.1 (core)",
    "@oclif/plugin-update 4.3.3 (core)",
    "@oclif/plugin-version 2.2.2 (core)",
    "@oclif/plugin-warn-if-update-available 3.1.4 (core)",
    "@oclif/plugin-which 3.2.1 (core)",
    "@salesforce/cli 2.45.6 (core)",
    "apex 3.1.14 (core)",
    "auth 3.6.17 (core)",
    "data 3.4.3 (core)",
    "deploy-retrieve 3.8.4 (core)",
    "info 3.3.4 (core)",
    "limits 3.3.10 (core)",
    "marketplace 1.2.10 (core)",
    "org 4.1.19 (core)",
    "packaging 1.22.2 (user) published 302 days ago (Wed Aug 16 2023) (latest is 2.4.6)",
    "schema 3.3.10 (core)",
    "settings 2.3.0 (core)",
    "signups 2.0.28 (user) published 103 days ago (Sun Mar 03 2024) (latest is 2.3.10)",
    "sobject 1.4.8 (core)",
    "source 3.3.21 (core)",
    "telemetry 3.3.12 (core)",
    "templates 56.2.9 (core)",
    "trust 3.7.4 (core)",
    "user 3.5.11 (core)"
  ]
}
github-actions[bot] commented 3 months ago

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.

github-actions[bot] commented 3 months ago

Hello @Brian-Triplett :wave: It looks like you didn't include the full Salesforce CLI version information in your issue. Please provide the output of version --verbose --json for the CLI you're using (sf or sfdx).

A few more things to check:

Thank you!

shetzel commented 3 months ago

Hi @Brian-Triplett. That doc explains the behavior of sourceApiVersion and apiVersion when deploying and retrieving source. There are correlations with packaging though so here is my interpretation of what is happening:

An org connection is created using the target dev hub org. If the --api-version flag is used then that API version will be used by the command. If that flag is not specified, then the highest API version supported by the target dev hub org is used. I believe adding releaseVersion: previous to your definition file also affects this when your target dev hub org is ahead of the package. The sourceApiVersion is not used for this. I.e., I think this URL in the result is correct based on how the command was run: /services/data/v61.0/tooling/sobjects/Package2Version/05iHu000000Cd0YIAS

The sourceApiVersion should be used for the <version> element in the manifests that are generated as part of the package version create process. To verify this, you can add the --preserve flag to your command and you can inspect the package.xml file generated in the temporary directory. If the version is wrong in the manifest then that is a bug and should be fixed. Let me know if that's the case.

However, I believe this is working as designed.

github-actions[bot] commented 3 months ago

Hello @Brian-Triplett :wave: None of the versions of sf you shared match the latest release.

Shared: 2.44.8 Latest: 2.45.6

Update to the latest version of Salesforce CLI (docs) and confirm that you're still seeing your issue. You can also try the rc and nightly releases! (docs)

After updating, share the full output of sf version --verbose --json

Brian-Triplett commented 3 months ago

Thanks for this @shetzel. So if I understand correctly we need BOTH sourceApiVersion in the sfdx-project.json but also need to consider specifying the --api-version in the CLI command as well?

The main thing we want to avoid is having a "dead period" where we have 2GP packages that can't be shipped due to our DevHub being updated but a customer org still on the prior release.

We also want to avoid having to update an --api-version variable though as that's a recipe for forgetting and finding out we're still making packages from 3 API versions ago.

shetzel commented 3 months ago

Sorry, I typed too much in my response and didn't make the solution clear. In this transition period where dev hub orgs are being updated with the new Salesforce major release you might need to set releaseVersion: previous in your definition file (config/project-scratch-def.json) to build the package on the previous release. In this case, that's what you need to do.

shetzel commented 3 months ago

Closing this since the design is to use releaseVersion: previous during transition periods.