8 GitHub Actions for Setting Up Your CI/CD Pipelines
Many individuals, organizations, and open source projects moved their CI/CD pipelines to GitHub since GitHub Actions was announced in 2018. They enable users to automate workflows and create various automation, build development cycles and, of course, create CI/CD pipelines.
GitHub actions are event-driven, and this is perhaps the best part of it. You can trigger actions to run on-demand workflows by your events in a GitHub repository.
These eight GitHub actions can make an impact on organizations getting started with their CI/CD pipelines.
You can monitor your GitHub Actions workflows and tests by setting up Foresight’s GitHub application. It lets you monitor your GitHub Actions workflows, tests and untested code changes on a single dashboard. It visualizes your running and completed GitHub Actions workflows by status, duration and cost.
1.1. Foresight’s Workflow Kit Action
It tracks and monitors the resource metrics of your GitHub Action workflow runs. If the run is triggered via a pull request, it will create a comment on the connected PR with the results and/or publish the results to the job summary. The action collects the following metrics:
- CPU load (user and system) in percentage.
- Memory usage (used and free) in MB.
- Network I/O (receive and transmit) in MB.
- Disk I/O (read and write) in MB.
1.2. Foresight’s Test Kit Action
Foresight’s Test Kit analyzes test and/or coverage results. It integrates with your GitHub Actions pipelines.
It makes it simple to see failed tests, visualize the performance of your tests and see their logs. It is the fastest way to access failed test results in your workflow runs. It correlates the changes to the codebase with the test coverage reports to determine how much of the changes are covered by the tests.
Visit runforesight.com for more information.
You can download and set up a requested version of the runtime with most of the setup actions. With the programming language of your choice, there are a lot of actions called Setup which allow you to set up your GitHub workflows.
Merge pull requests adds an automerge label on the pull requests before running its tasks. It merges the PRs automatically when they are ready.
This action looks at the base branch and gets the changes when there is a change. Then when the PR is ready to go, it automatically merges the PR.
The merge pull requests action does not do the cleanup, meaning that the branch created by this action won’t be deleted after the successful merge. That’s why you need to use another deletion action for that purpose.
You don’t have to download frequently used dependencies using the Cache action. You can cache dependencies and improve your workflow execution time with its outputs.
If you are cost-sensitive when building your CI/CD pipeline, then Cache helps save money and free up network capacity.
5. Create a Pull Request
You can use create a pull request for changes to your repository.
When used with other actions, it makes it easier to add, remove or modify files to your repositories. This action creates a pull request by automatically committing changes to a new branch.
You can download your Git repository to your local environment using Checkout. It lets your workflow access your Git repository locally and checks out your target repository to run GitHub Actions on top of it.
Many possibilities are available with Checkout. For example, using the built-in token, you can push a commit. Or you can fetch the history for the defined tags and branches if you wish. See the scenarios on GitHub Marketplace.
7. Upload Artifact
Upload Artifact automates sharing data between jobs and enables you to upload your artifacts from your workflow, allowing you to share data between jobs and store data once a workflow is complete.
You should be cautious if your workflow uploads a high number of artifacts in a short period of time, though. You may be exceeding usage and see them blocked.
You can reduce the number of HTTP calls made during artifact upload by zipping or archiving the contents of your artifact before an upload starts to overcome this small hurdle.
8. Docker Build and Push Action
You can create a Docker image by using the Docker Build and Push Action and push it into a desired registry like GitHub Docker Hub, Docker Registry, Amazon Elastic Container Registry (ECR) or Google Container Registry (GCR).
This action is mostly used to pass data between jobs in a workflow, but definitely you can do a lot of things with it. You can copy Docker images between registries without changing the commit ID. You can handle tags and labels. You can also build images on multiple platforms. If you want to see your build results on Docker, you can export images as well.
Unlike some others, GitHub Actions is an invaluable tool when it comes to automation. The GitHub Marketplace is very rich. There are many actions available for doing almost anything.
Lastly, I want to mention the need to monitor CI pipelines. When a workflow, build, job or test fails, we tend to rerun the whole workflow from the start, try to reproduce the bug locally, or dig into the log piles. Troubleshooting failures and latencies become easy with a CI monitoring tool that visualizes GitHub Actions workflows by status, duration, and cost, and gives insights about performance.