Template for new projects, including tools (mostly shell/bash scripts) i find useful in my day-to-day tasks using SFDX. This repo will be updated with usefulness from time to time.
Some of the scripts may depend on functionality installed. I will try to list here the needs.
-
Click the green 'Use this template' button, for setting up your own repository from this template.
-
Clone your repo locally:
git clone https://github.com/<git_username>/<git_repo_name>.git
-
Make sure that you have Salesforce CLI installed. Run
sfdx force --help
and confirm you see the command output. If you don't have it installed, download and install it from here. -
Setup a JWT-based auth flow for the target orgs that you want to deploy to. This step creates a
server.key
file that is used in subsequent steps. (https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_jwt_flow.htm) -
Confirm that you can perform a JWT-based auth:
sfdx force:auth:jwt:grant --clientid <your_consumer_key> --jwtkeyfile server.key --username <your_username> --setdefaultdevhubusername
Note: For more info on setting up JWT-based auth, see Authorize an Org Using the JWT-Based Flow in the Salesforce DX Developer Guide.
-
Encrypt and store the generated
server.key
. IMPORTANT! Don't store theserver.key
within the project.
- First, generate a key and initializtion vector (iv) to encrypt your
server.key
file locally. Thekey
andiv
are used by GitHub Workflow to decrypt your server key in the build environment.
$ openssl enc -aes-256-cbc -k <passphrase here> -P -md sha1 -nosalt
key=E5E9FA1BA31ECD1AE84F75CAAA474F3A663F05F412028F81DA65D26EE56424B2
iv =E93DA465B309C53FEC5FF93C9637DA58
Make note of the
key
andiv
values output to the screen. You'll use the values followingkey=
andiv =
to encrypt yourserver.key
.
- Encrypt the
server.key
using the newly generatedkey
andiv
values. Use thekey
andiv
values only once. Don't use them to encrypt more than theserver.key
. While you can re-use this pair to encrypt other things, it's considered a security violation to do so. Every time you run the command above, it generates a newkey
andiv
value. You can't regenerate the same pair. If you lose these values, generate new ones and encrypt again.
openssl enc -nosalt -aes-256-cbc -in assets/server.key -out assets/server.key.enc -base64 -K <key from above> -iv <iv from above>
This step replaces the existing server.key.enc
with your encrypted version.
- Store the
key
, andiv
values somewhere safe. You'll use these values in a subsequent step in the Bitbucket Pipeplines UI. These values are considered secret so please treat them as such.
-
From your JWT-based connected app on Salesforce, retrieve the generated
Consumer Key
from your Dev Hub org. -
Set your
Consumer Key
in a Workflow Secrets environment variable namedSF_CONSUMER_KEY
using the UI. Set yourUsername
in a Workflow Secrets environment variable namedSF_USERNAME
using the UI. Note that this username is the username that you use to access your Dev Hub. -
Store the
key
andiv
values used above in Workflow Secrets environment variables namedDECRYPTION_KEY
andDECRYPTION_IV
, respectively. When finished setting the Secrets variables it should look something like the image below.
NB: After you have saved the variables they can not be viewed again - so store them safely somewhere else if you need them.
-
Update the contents of
sfdx-project.json
andproject-scratch-def.json
if needed and save. -
Commit the changes to your master branch, then create a new branch named 'dev'.
Now you're ready to Set up Actions (se image).
Then, when you commit and push a change to the 'dev' branch, your change kicks off a Workflow build which tests the changes. More tests will be added.
Enjoy!
If you have something clever or useful you feel like sharing (i.e. a shell script that automates some process, or generic test functions etc), please follow this:
- Fork this project.
- Create your feature branch (
git checkout -b feature/NewFeature
). - Commit your changes (
git commit -m 'Add NewFeature'
). - Push to your feature branch (
git push origin feature/NewFeature
). - Open a pull request to the
dev
branch.