Welcome to the GitHub Actions kata Ekino!
(For Node.js project)
GitHub Actions is a CI/CD platform that allows you to automate your build, test, and deployment pipeline directly from your GitHub repository. It uses workflows defined in .github/workflows
directory to execute jobs triggered by events like pushes, pull requests, or scheduled tasks.
Objective:
This kata is designed to introduce you to the concept of GitHub Actions, how to create CI/CD pipelines, and the benefits of automation in the development process. By completing each exercise, you'll learn how to configure and customize jobs, steps, and workflows in GitHub Actions.
Before starting, make sure you have the following tools installed on your machine:
-
Git: To clone the repository and manage branches.
Download Git -
Node.js (version 22) and npm: Required to run the project and install dependencies.
Download Node.js -
Docker (optional, for the Docker build & push part):
Get Docker
You will also need a GitHub account with access to the repository.
- Clone the repository
git clone https://github.com/ekino/githubworkflow-handson-nodejs.git
cd githubworkflow-handson-nodejs
- Create your own branch
Example:
git checkout -b john
# or git switch -c john
- Install the project dependencies
npm install
- Create the first empty commit from your account
git commit --allow-empty -m "chore: init kata john"
- Create a folder
.github/workflows
. - Add
ci.yml
inside. - To make your workflow work, you need to add a trigger to your YML file. Several triggers are documented in the official documentation. For the purpose of the katas, we will use a trigger that activates only on your branch.
on:
push:
branches:
- john
For each exercise, you'll probably need the documentation for each community GitHub Action. Here's a list of the actions used in this kata.
- actions/checkout
- actions/setup-node
- davelosert/vitest-coverage-report-action
- docker/setup-buildx-action
- docker/login-action
- docker/metadata-action
- docker/build-push-action
Exercise:
Create a job called lint
that checks the code for linting errors. The job should run on an Ubuntu environment and execute the linting tool Biome.
Tasks:
- Checkout the repository code.
- Set up Node.js with version 22.
- Install the required dependencies using
npm
. - Run the linting command (
npm run lint
).
Exercise:
Create a job called verify-typescript-types
that checks for TypeScript type errors in the codebase. The job should:
- Checkout the repository code.
- Set up Node.js with version 22.
- Install the required dependencies using
npm
. - Run the TypeScript type checking command (
npm run typing-check
).
Exercise:
Create a job called code-coverage
that runs the tests with coverage and reports the coverage results. The job should:
- Checkout the repository code.
- Set up Node.js with version 22.
- Install the required dependencies using
npm
. - Run tests and generate coverage reports (
npm run coverage
). - Report the coverage results using a coverage report action.
Exercise:
Create a job called build-and-push
that builds a Docker image from the Dockerfile and pushes it to GitHub Container Registry (GHCR). The job should:
- Only run when the previous jobs (lint, verify-typescript-types, code-coverage) have completed successfully
- Checkout the repository code
- Set up Docker Buildx for multi-platform builds
- Log in to GitHub Container Registry using GitHub secrets
- Extract metadata from Git for proper image tagging
- Build and push the Docker image with appropriate tags