GitHub Workflows expand GitHub’s features and can be created directly in the github/workflows folder of a repos­i­to­ry. By employing workflows, you can carry out automated actions when certain events occur.

What are GitHub workflows?

In short, a GitHub workflow is nothing more than a col­lec­tion of specific, mostly rep­e­ti­tious actions that are au­to­mat­i­cal­ly carried out when a par­tic­u­lar event occurs in a repos­i­to­ry. A workflow is made up of multiple jobs, which are then further separated into in­di­vid­ual steps. In addition to using workflows for specific events, you can also run them manually or specify a time period when they should be carried out. Workflows are an important part of the con­tin­u­ous in­te­gra­tion platform GitHub Actions.

The person pro­gram­ming the workflow de­ter­mines which specific actions are included in the GitHub workflow. Workflows are commonly used to au­to­mat­i­cal­ly test code as soon as it’s updated in a repos­i­to­ry or to notify team members when changes are made to a repos­i­to­ry.

Tip

If you want to use GitHub for an online project, use IONOS Deploy Now to improve your pro­duc­tiv­i­ty. The pre-pro­grammed GitHub Actions workflow will run your build au­to­mat­i­cal­ly.

How to create your own workflow: Step-by-step in­struc­tions

Creating your own GitHub workflow isn’t difficult. You just need basic knowledge of the pro­gram­ming language YAML and a GitHub repos­i­to­ry in which you can run and create your workflow. If you want to use an in­te­grat­ed de­vel­op­ment en­vi­ron­ment to write your YAML code, GitHub Copilot can help you when creating your workflow code.

Step 1: Set up your workflow

Once you have created a repos­i­to­ry or have chosen an existing one for your GitHub workflow, click on the Actions button in the GitHub Actions menu.

Image: View of a GitHub repository
Select the **Actions** button in your repos­i­to­ry to go to the GitHub Actions menu.

In the GitHub Actions menu, you can now select set up a workflow yourself.

Image: View of the GitHub actions menu
In the GitHub Actions menu, you can now set up a workflow yourself.

Step 2: Write the code for your GitHub workflow

As soon as you have set up your workflow, a new file called main.yml will open au­to­mat­i­cal­ly in the github/workflows folder. You can directly edit this file in GitHub and enter the code you want to put in your workflow. This code must be entered in YAML as the file extension is .yml.

Image: The main.yml file in the GitHub editor
You can directly edit the *main.yml* file in GitHub and then commit it.

Which action you choose to carry out with your code is com­plete­ly up to you. In the example below, we’ve created a workflow called “example”, which is carried out every time there’s a commit to the branch “main”.

name: example
on:
	push:
		branches: [main]
jobs:
	build:
		runs-on: ubuntu-latest
		steps:
-  uses: actions/checkout@v2
    with:
	fetch-depth: 0
- run: make
YAML

Next you need to specify when the GitHub workflow should be carried out. To do so, use the key words “on” and “push”. These will trigger the workflow when the code is behind the keyword “branches”.

The workflow itself is made up of a job called “build”, which is made up of two steps and carried out on an Ubuntu host.

In the first step, a pre-defined GitHub action called “checkout” is used. It ensures that the entire repos­i­to­ry code is down­loaded to the host. The parameter “fetch depth” can be used to specify how many commits are to be down­loaded. By entering “0”, the entire commit process of the “main” branch is down­loaded.

The second step carries out the command “make” on the host. This compiles and manages code by executing commands that are usually specified in a file named Makefile.

Step 3: Save and commit your GitHub workflow

Once you’ve entered your code into your workflow, you just need to save and commit the file. Now, your workflow will always be carried out when the event you entered occurs.

Go to Main Menu