Skip to main content

Configuring DevOps Mate with Github Actions

Avatar photoGroundswell Team
On , In Tips & Tricks

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:

  1. Introducing GS DevOps Mate
  2. Part Two in the series: Features and Unique Benefits 
  3. Step by Step guide to configuring 

Steps to Configure DevOps Mate with Github Actions:

  1. Runtime Configuration
  2. Define Environment Variables
  3. Define Repo Variables
  4. Define Personal access token
  5. Configure a workflow
  6. Test the workflow

Runtime Configuration

Configure workflow by navigating to the Actions tab in Github repository.
Click the set up a workflow yourself link

Let's get started with GitHub Actions!
The above action will create .github/workflows/***.yml in your repository.

Define Environment Variables

  1. Configure Environments by navigating to the Settings tab => Environments tab on the left side.
  1. 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 secret. 

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 Master/Main branch.

The process contains two workflow,

  1. Pull request workflow to validate the metadata against QA org.
  2. 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.

Let’s connect

We’d love to get to know your business better, and chat about how we can harness the power of Salesforce to help achieve your long-term goals.

Start the conversation

Let’s connect

Whether you’re looking for a quick fix, a major transformation, or expert consulting to help you navigate through it all, we’d love to hear from you.
Want to join our team?
Visit our careers page for current openings.
Our HQ
650 W Georgia St Suite 1300 Vancouver, BC V6B 4N8 (604) 628-3421
General inquiries
info@gscloudsolutions.com