What is GitHub Actions?
A way to automate things in GitHub. Automatically run workflows to enable continuous integration / continuous delivery and others.
- Consistent results
Anatomy of a workflow
A workflow has a name.
This decides when the workflow is triggered.
Other trigger events are:
- A test
- Many more
A workflow consists of one or multiple jobs that can run in succession or in parallel. A job can be dependent on another job successfully finishing.
For example, you can have a `test` job and a `lint` job running in parallel because they are not dependent on one another. And then you can have a `deploy` job that depends on both the `test` and ´lint` jobs successfully running. If either of `lint` or `test` jobs fail the `deploy` job will not run.
A job consists of some properties and one or more steps. An important property is `runs-on`. Runs-on defines the runner the job will run on. For example, ubuntu-latest. This can be any type of runner that GitHub offers, or even a self-hosted runner.
The first step in a job will normally check out the source code from the repo we are in:
The following steps depends on what the workflow should do. In this example we will build and deploy the application.
The next step will install npm modules:
Now it’s time to build our project:
And then finally we will deploy it:
You probably want to automate running your tests as part of your CI/CI pipeline. As previously mentioned, you can run your tests in a job:
To make successful running of actions a requirement for your pull requests to be able to merge in to master you need to set this up in your GitHub repository.
Here we require that the project builds properly before being able to merge
This setting can be found in Settings -> Branches -> Branch protection rules.
Workflows can be triggered by different events.
Common events are:
Will run when a pull request is created or updated. This could be tests and linting running as requirements for the pull request to be merged.
This runs when a push is made to the specified branch, in this example: master branch.
Runs when a new release is published
Workflow can be triggered manually.
This can be useful if you want to deploy a branch at will to your test environment.
GitHub Actions can be used to run tests, build your projects and deploy to your environments. Workflows consists of jobs and steps that can be triggered by various events. For example pull requests or a push to master. This saves time compared to doing testing, building and deployment manually.