GitHub: Automation
Many organizations use the terms DevOps and Automation interchangeably. DevOps can be defined as a combination of process and technology automations along with a collaborative culture intended to deliver increased business value. Just like how important an engine for a car, automation is one of the core pillars of DevOps. Normally, DevOps adoption roadmap is defined with the combination of well-structured automation along with process and cultural shift.
GitHub provides a very flexible and extensible automation framework - actions. ?? Confused ! GitHub actions are defined as the CI/CD platform to automate build, test and deployment pipeline. Is it only for CICD ? NO. Actions support the event driven programming and respond to various events from internal and external sources. External event handling supported through Webhook.
Sometimes, workflow and actions are used interchangeably. In simple terms, a workflow consists of event triggers and actions to execute. You will be able to define a workflow with external actions and inline actions, as shown below.
steps:
# Checks-out your repository - external action
- uses: actions/checkout@v3
# inline action
- run: |
gh api graphql -f query='...........
In this article, we will be using actions to denote the workflow defined under 'Actions' tab in GitHub. Let us look into some of the main concepts associated with the action
Events
Internal and external events trigger the execution of the action/workflow. As shown in above figure, there are many internal events as part of each of the operations in GitHub platform. GitHub allow you to handle the events in granular levels. Each of the event have activity types associated with them to define the type of activity against it.
For example, 'issues' event supports many activity types such as opened, edited, deleted, pinned, closed, etc. Based on the automation requirement, one can associate the action to a specific activity itself. For example, when an issue opened or edited, the following code snippet will get triggered.
on:
issues:
types: [opened, edited]
If you want further control on event handling, you will be able to define the criteria using the event trigger attributes like if: ${{github.event.issue.<attr> == 'expected val' }} or using context values (context.repo.owner). Refer Events details for further information about the activity types associated with different event sources.
Sometimes, we want to trigger the automation script from an external system/tool. External events will be handled through the Webhook and linked to the workflow using webhook events. Refer the Webhook events for more details.
领英推荐
GitHub Platform Data
Most of the time, the automation script require data from the underlying platform like the repository details, commit data, project boards, issues, etc. GitHub provides different options to query the required data - GitHub GraphQL, API and CLI. These integration options not only support the data extraction to actions, it also supports the integration with external tools/systems.
Runners
Runners are the machines that execute the actions. GitHub offers hosted virtual machines to run workflows/actions. One can use the standard hosted runners provided by GitHub or opt for the Large runners (Beta). Large runners supports high end VMs with more RAM and CPU capacity. Self-hosted runners are systems that you deploy and manage to execute the GitHub actions. Self-hosted runners offer more control on the hardware, OS and tools.
CI/CD
Actions and workflows are mainly used for automating the continuous integration and continuous delivery/deployment pipelines. Actions supports the deployment of various kind of applications based on different technologies including .NET, Java, Angular, etc. It also supports various deployment platforms like on-premises data centre, cloud based deployment to Azure/GCP/AWS, private cloud deployments, etc.
Marketplace
GitHub Marketplace is the place where you will be able to discover and purchase new actions, apps and stacks. Apart from the GitHub provided actions, there are around 14k+ actions available from community - either free or paid. Based on our project requirement, one can plan to integrate the actions from community. Apps are another automation or extensibility feature of GitHub. Stack is a bundle, which offers the quick deployment of a repository along with workflows and other settings.
Custom Action
You will be able to author custom actions and in-line actions using JavaScript, Shell command or Docker containers. I have a simple action - Azure Compliance Checker, published in marketplace ??. This action is based on shell commands only. JavaScript based custom action development is widely adopted and faster than the Docker container actions. Docker container actions brings the benefit of authoring the action using any of the docker supported technologies like Python.
Conclusion
Actions provide a flexible and scalable platform for automation across the DevOps implementation. GitHub provides GitHub Apps to address the automation requirements to handle persistent data. Actions provide the platform centric automation, whereas GitHub Apps provide more extensibility features. For example, using GitHub Apps, you will be able to define a complete test case management module or new dashboard experience for GitHub.