Back in 2018, GitHub introduced a new feature called GitHub Actions. At the very beginning, it served as a useful tool for orchestrating workflows. Based on events, one could perform various effects on GitHub. Over time, the project grew and started to provide more and more possibilities; for example, continuous integration and continuous delivery (CI/CD).
One of the vast advantages GitHub Actions provides is configuring the action to any event occurring on a workflow repository, including opening a pull request, pushing a commit, and many others. We can also configure events that occur outside of GitHub and trigger a repository_dispatch
event on GitHub in response. It’s also possible to schedule run time, or even manually start a workflow. The effect can be any task that can be executed on an assigned runner - such as deploying a project or running tests.
Click here to understand the GitHub Actions basics in more detail.
Advantages of using GitHub Actions
There are many benefits to using GitHub Actions in your workflows as it opens many doors for project optimization. Below, we listed the perks we enjoy the most.
🌐 Cross-platform processing
Runners are the machines that execute jobs in a GitHub Actions workflow. By default, they’re hosted on virtual machines with a variety of choices in their operating systems. You can run your workflows on Linux, macOS, Windows, or even choose your own self-hosted runner. Since it’s all very customizable, you can adjust the setup to your needs. Each runner offers a different size of RAM or disk space.
Read more about runners in GitHub docs.
🕐 Time-saving matrix builds
With GitHub Actions, you can process your workflow in parallel. It’s a great solution for testing, as each entity can be run independently, which can save you a lot of time.
🗣️ Variety of available programming languages
GitHub Actions is very user-friendly and supports many programming languages and environments. The supported languages include the popular ones like Node.js, Java, and Python, but there are various other options.
⏺️ Live logs
GitHub lets you to easily follow a run of your workflow in real-time. It’s extremely handy for debugging and spotting any mistakes in your code. There’s also a convenient option to send your logs to other members of your team. Moreover, the logs support colors and emojis! 🎉😄
Note that the above is only a brief summary. If the topic captures your interests, be sure to check out everything GitHub Action has to offer in their documentation.
Usage
GitHub Actions is extremely simple to use. Workflows have to be defined by YAML files and placed in the .github/workflows
directory of your project. In this file, we need to specify:
- The name of the workflow based under the key
name
. - The action trigger with the key
on
. - The
jobs
that define the effects we want to perform on the repository. Each job is divided intosteps
.
And that’s initially all you’ll need to run your first workflow!
Example
For the first time in LiveChat projects, we used GitHub Actions to solve the problem of broken links in our documentation. Due to the size of the API docs, it was very difficult to manually ensure each redirect was valid and working. As we mentioned before, GitHub Actions lets us specify the scheduled time as a trigger to a workflow, which proved to be very handy in our case. In addition, we used two external actions: lychee-action
to check the links in the Markdown files, and create-issue-from-file
to create a GitHub Issue based on the output of the first action. Take a look at the full example below.
name: Links
on:
repository_dispatch:
workflow_dispatch:
schedule:
- cron: '00 11 * * 1'
jobs:
linkChecker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Link Checker
uses: lycheeverse/lychee-action@v1.0.8
with:
args: --verbose --no-progress **/*.mdx **/*.md **/*.html
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Create Issue From File
uses: peter-evans/create-issue-from-file@v3
with:
title: Link Checker Report
content-filepath: ./lychee/out.md
labels: report, automated issue
Summary
GitHub Actions is a very useful and user-friendly way to automate your repository workflows. Also, the available configuration options are a huge benefit when it comes to customizing GitHub Actions to your company’s environment and expectations. It opens many doors for various use cases, so we highly recommend checking it out. I’m sure we’ll use them for other purposes in our repositories at LiveChat.