Skip to content

Generate packages and package versions

Managed packages (ISV)

Pre-requisites

sfdx-hardis menus let you create new packages and new package versions, but you first need some pre-requisites.

  • If you need to use a namespace with a package (managed or unmanaged), you also need to link your Dev Hub and a dev org where you will create the namespace.

  • Then you need an sfdx-hardis flavored SFDX project, that you can create with sf hardis:project:create, with the scratch orgs only option.
  • Last, create your package folder (ex: my-package) at the root of the repository, with the same structure as force-app: it will contain your package content.

New package

Use sfdx-hardis menu Packaging -> Create a new package and follow the instructions (select the folder that you just created, do not use force-app)


New package version

Git branch

Create a git sub-branch of your packaging branch (for example pkg/release-v0.1.0)


Increment package version

Before being able to generate a new package version, you need to increment the package version in sfdx-project.json.

{
  "packageDirectories": [
    {
      "path": "package-astran",
      "default": true,
      "package": "Astran",
      "versionName": "ver 0.1",                         # Change version name here to match the incremented package version
      "versionNumber": "0.1.0.NEXT",                    # Increment version here (Respect SEMVER or you will have errors)
      "versionDescription": "Astran for Salesforce"
    },
    {
      "path": "scratch",
      "default": false
    }
  ],
  "name": "astran",
  "namespace": "Astran",
  "sfdcLoginUrl": "https://my-devhub-org.salesforce.com",
  "sourceApiVersion": "57.0"
}

Run create package version command

Run the sfdx-hardis command Packaging -> Create new package version

Create new package version button

Select the package you want to create a version for, and enter an installation password if necessary (otherwise leave it blank)

Select the package

Enter the package installation password

After some time, the new package version will be generated, and you will be able to find its ID in your sfdx-project.json

{
    ...
      "packageAliases": {
        "Astran": "0Ho7S0123010wZWSAU",
        "Astran@0.1.0-1": "04t7S000000gYxPQAF",
        "Astran@0.1.0-2": "04t7S000000gYm1QAE",
        "Astran@0.1.0-3": "04t7S000000gYp7WAG",
}

If you have issues, it might be because you incremented the version as a patch whereas the updates with the previous version require at least a minor version.

For example, 1.1.4.NEXT can fail, and 1.2.0.NEXT will pass


Test the beta version

(optional but recommended)

The latest entry is the one you can use to install the beta package version (every created package version is a beta by default)

Example of URL to append at the end of your org domain name: /packaging/installPackage.apexp?p0=04t7S000000gYp7QAG

Install the beta package in a dummy sandbox to check its content


Pull Request to packaging branch

Once the package is good for you, create a Pull Request to the packaging branch (or main branch, depending on your project config)


Promote the beta

Once your Pull Request is merged in the packaging branch (after checking that the control jobs are green), you can promote the package.

WARNING: Promoting a package is a sensitive operation, because it declares it as production-ready, then you can not remove metadata from it, and you must respect ascending compatibility to generate new package versions.

To promote a package version, run the following command

sf hardis:package:version:promote

Example: sf hardis:package:version:promote

Note: if you later have issues when you create a new scratch org in a new development branch, just increment again the versionNumber in sfdx-project.json


Create version git tag

Once you promoted a package, create a git tag with the version id on the commit corresponding to your merged Pull Request

Example: v1.1.0

Push the git tag to origin

Comments