Groundswell identified a need for an easier way for various DevOps teams to adapt to SFDX-based CI/CD and therefore created GS DevOps Mate, our Open Source, first-of-its-kind deployment tool. In this blog post, we will show you how to configure DevOps Mate with GitHub Actions.
If you are not familiar with our GS DevOps Mate tool then feel free to read our previous blog posts below:
- Introducing GS DevOps Mate
- Part Two in the series: Features and Unique Benefits
- Step by Step guide to configuring
Steps to Configure DevOps Mate with GitHub Actions:
- Runtime Configuration
- Define Environment Variables
- Define Repo Variables
- Define Personal access token
- Configure a Workflow
- Test the Workflow
Runtime Configuration
Configure workflow by navigating to the Actions tab in GitHub repository.
Click the set up a workflow yourself link
Define Environment Variables
- Configure Environments by navigating to the Settings tab => Environments tab on the left side.
- Create QA, UAT, PROD environments under Test, Staging, and Production environments, respectively
Define Repo Variables
Go to Settings > Secrets
Keep all the Org-specific passwords either in Actions Secrets or Environment-Specific Secrets.
Action Secrets
Environment Specific secret
Define Personal Access Token
This step is required to send a Slack notification.
Navigate to Profile > Settings > Developer Settings > Personal access tokens
Generate a new token and store it in repo secrets.
Configure a Workflow
Workflow configuration for Git flow branching strategy.
The approach is to validate the metadata against QA org on Pull request creation and deploy the changes to QA/Production on Pull request merge to the Master/Main branch.
The process contains two workflows,
- Pull request workflow to validate the metadata against QA org.
- Merge workflow to deploy the metadata to a higher environment.
Pull request workflow(pr_workflow.yaml)
#Unique name for this workflow
name: PR_workflow
env:
GITHUB_PR_DESTINATION_BRANCH: ${{ github.event.pull_request.base.ref }}
PACKAGE_DIR: 'ArchiveDir'
QA_ORG_USERNAME: 'YOUR_QA_ORG_USERNAME'
QA_ORG_PASSWORD: ${{ secrets.QA_ORG_PASSWORD }}
QA_ORG_TYPE: 'SANDBOX'
TEST_LEVEL: 'RunSpecifiedTests'
CI_CD_PROVIDER: 'GithubActions'
LOGGING_LEVEL: 'debug'
MANIFEST_VERSION: 52.0
SLACK_NOTIFICATION_URI: 'SLACK NOTIFICATION WEBHOOK URL'
SLACK_MESSAGES: 'on'
on:
pull_request:
branches: [ master ]
paths-ignore:
- '.github/**'
# Jobs to be executed
jobs:
# create deployment archive
create_deployment_archive:
runs-on: ubuntu-latest
container:
image: gscloudsolutions/devops-mate-test:github
steps:
# Checkout the source code
- name: Checkout Repository
uses: actions/checkout@v1
- name: Creating Deployment Package for QA Org Validation
run: sfPackages source-combined -v 1.0.0.$GITHUB_RUN_NUMBER -p $GITHUB_WORKSPACE/$PACKAGE_DIR -n HEAD -i $GITHUB_RUN_NUMBER -o origin/$GITHUB_PR_DESTINATION_BRANCH || if test $? -eq 21; then exit 0; else exit 1; fi
#Archive deployment package
- name: Archive Deployment Package
uses: actions/upload-artifact@v2
with:
name: fair_ci_cd_artifact
path: ${{ github.workspace }}/${{ env.QA_PACKAGE_DIR }}/*
retention-days: 14
validate_qa:
name: 'PR-Validate against QA env'
runs-on: ubuntu-latest
container:
image: gscloudsolutions/devops-mate-test:github
needs: create_deployment_archive
steps:
- name: Downloading artifact
uses: actions/download-artifact@v2
with:
name: fair_ci_cd_artifact
path: ${{ github.workspace }}/${{ env.PACKAGE_DIR }}/
- name: Validate against QA
run: sfDeploy mdapipackage -b true -c true -u $QA_ORG_USERNAME -s $QA_ORG_PASSWORD -t $QA_ORG_TYPE --notificationTitle 'QA Sandbox Validation' -v 1.0.0.$GITHUB_RUN_NUMBER -p $GITHUB_WORKSPACE/$PACKAGE_DIR --successSHA $GITHUB_SHA -i $GITHUB_RUN_NUMBER -k "SampleTest" -l ${TEST_LEVEL}
Merge Workflow(main_merge_workflow.yaml)
name: Main_Merge_Workflow
env:
PACKAGE_DIR: 'ArchiveDir'
QA_ORG_USERNAME: 'YOUR_QA_ORG_USERNAME'
QA_ORG_PASSWORD: ${{ secrets.QA_ORG_PASSWORD }}
QA_ORG_TYPE: 'SANDBOX'
PROD_ORG_TYPE: 'PRODUCTION'
TEST_LEVEL: 'RunSpecifiedTests'
CI_CD_PROVIDER: 'GithubActions'
LOGGING_LEVEL: 'debug'
MANIFEST_VERSION: 52.0
SLACK_NOTIFICATION_URI: 'SLACK NOTIFICATION WEBHOOK URL'
SLACK_MESSAGES: 'on'
on:
push:
branches: [ master ]
paths-ignore:
- '.github/**'
jobs:
deploy_qa:
runs-on: ubuntu-latest
container:
image: gscloudsolutions/devops-mate-test:github
environment: 'QA'
steps:
- name: Checkout Repository
uses: actions/checkout@v1
- name: Deployment Info
run: sfDeploymentInfo get -u $QA_ORG_USERNAME -t $QA_ORG_TYPE -i $GITHUB_RUN_NUMBER -n All -s $QA_ORG_PASSWORD
- name: Creating Deployment Package for QA Org Deployment
run: sfPackages source-combined -p $GITHUB_WORKSPACE/$PACKAGE_DIR -n HEAD -i $GITHUB_RUN_NUMBER || if test $? -eq 21; then exit 0; else exit 1; fi
- name: Deploy QA Sandbox
run: sfDeploy mdapipackage -u $QA_ORG_USERNAME -s $QA_ORG_PASSWORD -t $QA_ORG_TYPE --notificationTitle 'QA Sandbox Deployment' -p $GITHUB_WORKSPACE/$PACKAGE_DIR --successSHA $GITHUB_SHA -i $GITHUB_RUN_NUMBER -k "SampleTest" -l ${TEST_LEVEL}
- name: Archive Deployment Package
uses: actions/upload-artifact@v2
with:
name: ci_cd_artifact
path: ${{ github.workspace }}/${{ env.PACKAGE_DIR }}/*
retention-days: 14
deploy_prod:
runs-on: ubuntu-latest
container:
image: gscloudsolutions/devops-mate-test:github
environment: 'PROD'
steps:
- name: Checkout Repository
uses: actions/checkout@v1
- name: Deployment Info
run: sfDeploymentInfo get -u $PROD_ORG_USERNAME -t $PROD_ORG_TYPE -i $GITHUB_RUN_NUMBER -n All -s $PROD_ORG_PASSWORD
- name: Creating Deployment Package for PROD Org Deployment
run: sfPackages source-combined -p $GITHUB_WORKSPACE/$PACKAGE_DIR -n HEAD -i $GITHUB_RUN_NUMBER || if test $? -eq 21; then exit 0; else exit 1; fi
- name: Deploy QA Sandbox
run: sfDeploy mdapipackage -u $QA_ORG_USERNAME -s $QA_ORG_PASSWORD -t $QA_ORG_TYPE --notificationTitle 'QA Sandbox Deployment' -p $GITHUB_WORKSPACE/$PACKAGE_DIR --successSHA $GITHUB_SHA -i $GITHUB_RUN_NUMBER -k "SampleTest" -l ${TEST_LEVEL}
}
- name: Archive Deployment Package
uses: actions/upload-artifact@v2
with:
name: ci_cd_artifact
path: ${{ github.workspace }}/${{ env.PACKAGE_DIR }}/*
retention-days: 14
Test the Workflow
GitHub actions are configured and it’s time to validate your changes.
Create a Pull Request to the Main branch to start validating your changes.
Please feel free to let us know if you have any questions.