sfpowerscripts icon indicating copy to clipboard operation
sfpowerscripts copied to clipboard

feat: CI should automatically increment unlocked package versions in sfdx-package.json

Open ruslan-kurchenko opened this issue 1 year ago • 2 comments

Describe the feature Context: https://dxatscale.slack.com/archives/CN9N54GF5/p1664371890200189

"These version number changes should be made in the sfdx-project.json file before the final package build and promotion."

I understand that .NEXT provides auto-increment, but it increments the build-number. In our workflow, in the hardening stage of the release, we add a bunch of fixes to the upcoming release through the release branch & cherry-picks. In such cases, most of our packages' versions should be incremented manually before the production deployment/installation. Basically, that adds complexity as our release-engineering team has to 1) increment the version of all Beta packages and build them, 2) reinstall them to "staging" (env before prod), promote packages (or use auto promote), and only then 3) release them to production.

DX@Scale practitioners have shared great tools which definitely help to simplify package versioning on the client side (engineer machine):

  • https://docs.dxatscale.io/projects/sfp-cli
  • https://www.npmjs.com/package/@eon-com/eon-sfdx

Though those tools are amazing they do not provide a solution to automate package versioning.

Proposal

Implement an additional "pre-build" step (stage) which is executed as part of a build process. The jobs will use a diff between a current commit and the latest-successful-build-<branch-name> floating tag. Then resolve info about changed packages and their type - increment unlocked packages versions and commit sfdx-project.json. Push to the repository with an additional flag to skip the pre-build stage or trigger regular build without push if no unlocked packages are changed. And, of course, push (override) latest-successful-build-<branch-name> floating tag to the current commit.

Notes:

  • CI server should be configured to cancel in progress pre-build stage if a new commit pushed to the branch
  • Fast-forward merge strategy recommended
  • A job (script) should handle package dependencies and their versioning

ruslan-kurchenko avatar Dec 21 '22 09:12 ruslan-kurchenko

We have implemented a script described above using bash.

In GitLab, on the "main" branch and release branches, we have the "pre-build" stage, which executes a script to handle package versioning automatically: Screenshot 2022-12-21 at 11 20 52

Here is the porting of logs at the end of the script with info about incremented package version, etc: Screenshot 2022-12-21 at 11 42 24

Important note: when a pre-build is executed for the main branch, it increments a minor package version, but for release branches, it increments a patch version: Screenshot 2022-12-21 at 11 45 39

As a result, our engineers can use any tools they prefer to commit their changes, and they do not care about package versions at all.

ruslan-kurchenko avatar Dec 21 '22 09:12 ruslan-kurchenko

This looks very nice. I hope this proposal gets consideration.

pogilvieCB avatar Dec 21 '22 15:12 pogilvieCB