Skip to content

Instantly share code, notes, and snippets.

@AltiusRupert
Last active June 10, 2020 09:09
Show Gist options
  • Save AltiusRupert/7a8e849432b08a0f441b7f2d6ac0db4b to your computer and use it in GitHub Desktop.
Save AltiusRupert/7a8e849432b08a0f441b7f2d6ac0db4b to your computer and use it in GitHub Desktop.
In SFDX, script to identify all changes made on this branch, to generate package.xms and destructiveChanges.xml

In SFDX, script to identify all changes made on this branch, to generate package.xml and destructiveChanges.xml

Introduction

Make changes on feature branches, then merge them into a sandbox branch. This script identifies all changes made on this sandbox branch since it was created, and generates the package.xml (and destructiveChanges.xml) to push changes to the sandbox. If you are doing CI (Continuous Integration), it will let you find changes since the previous commit.

Flow

In feature branch, VS Code feature workspace, and scratch org :

  1. make changes on a feature branch in scratch orgs
  2. generate pull requests for these features towards the sandbox branch

In GitHub :

  1. merge pull requests into the sandbox branch

In sandbox branch, VS Code sandbox workspace, and sandbox org :

  1. pull into your VS Code workspace changes merged previously
  2. run script prepare-deploy.sh to generate package.xml of ALL changes already made on this sandbox branch
  3. in VS Code, right-click on manifest/deploy/package.xml and choose "SFDX: Deploy Source in Manifest to Org"
#!/usr/bin/env sh
# Where did this branch originate from ?
TRUNK=master
# What branch am I on ?
THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Find the base of this branch :
BASE=$(git log $TRUNK..$THIS_BRANCH | grep commit | tail -n 1 | sed 's/commit //g')
# If you just want to find changes since last commit (for CI, for example), use this :
#BASE=HEAD^
FROM=$BASE
# Generate manifest/deploy/package.xml containing changes on this branch since the BASE
# It generates the following output :
# manifest/deploy/package.xml
# manifest/deploy/destructiveChanges/package.xml
# manifest/deploy/destructiveChanges/destructiveChanges.xml
# This uses https://github.com/scolladon/sfdx-plugin-ci which in turn uses https://github.com/scolladon/sfdx-git-delta
#sfdx plugins:install sfdx-plugin-ci
sfdx source:delta:generate --repo . --from $BASE --to HEAD --output manifest/deploy/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment