GitHub Actions
GitHub is one of the most popular distributed version control system we have witnessed and been used by over 100 million developers. GitHub is not just a repository management and version control system but also provides users to create their own workflows with its platform called GitHub Actions. The workflow tasks would run when ever there is an event occurs in their git repository.
As more and more teams use GitHub Actions in some form or the other to orchestrate few automation steps, it becomes important for Salesforce DevOps solution like Gearset to integrate with GitHub Actions, so that the existing workflows of teams can be utilised the way they are and for the new automation tasks that are not available directly through Gearset.
Following are few scenarios of teams where they could be using GitHub Actions -
Team has a 3rd party automated testing tool which they run using GitHub Actions post package deployment and want Gearset to trigger such GitHub workflow which in-turn executes tests. For example: Running selenium test suite.
Team is using GitHub Action to orchestrate steps to run some additional scripts/ executable post merge or post deployment
Having a requirement for Gearset to trigger an executable available on Windows or Linux machine.
Repository Dispatches
As many systems integrate with GitHub, there is a need for such systems to trigger an action in GitHub based on particular event occurring in those integrating systems (like successful deployment to an org in Gearset). When we want to trigger a workflow for the activity that happens outside of GitHub we can use the GitHub API called repository_dispatch .
In the following simple example, we will try to call a GitHub Action workflow (.yml file) that we have added in our git repository which executes a echo batch command when the workflow is triggered by the Gearset's outgoing webhook post successful package deployment. You can think of calling a maven build or Selenium test execution similar to batch command.
Step 1.
Added a workflow file named executeBatch.yml under the directory .github/workflows in one of the git repository. We need to create .github & workflows directories as they will not be available by default.
Step 2.
Added the content to executeBatch.yml in YAML programming language which in the end runs a simple echo command as shown in the line 27 below. To understand what each line of code in the script below means, please refer to GitHub's repository_dispatch documentation.
Step 3.
In Gearset, navigate to the settings of the CI job where we would want to trigger GitHub Action workflow post successful package deployment.
Click on Edit Settings and then click on Outgoing webhooks > Add outgoing webhook.
Outgoing webhook url: https://api.github.com/repos/:owner/:repo/dispatches
Triggers: Success events
Payload: Custom
Authentication: Authorization
Credentials: Type in Bearer<space><Personal Access Token>
For example: Bearer 2df23339e38nlray429ad5
(Refer GitHub documentation on how to create Personal Access Token)
Content-Type: application/json
Payload: {
"event_type": "run_my_bat"
}
event_type value must be same as what is specified in .yml file against types: [value]
In this case the value is run_my_bat
Click Save outgoing webhook
Step 4.
Now it is the time to test to check if GitHub workflow is invoked post successful run of the CI job.
If everything has worked as expected after a successful run of the CI job in Gearset, one should be able to see a successful execution run of event named run_my_bat under actions tab in GitHub's repository
In case if you have further questions on how to configure outgoing webhook in Gearset for your own usecase, please reach out to our Support team via the in-app chat.