This is an example of a CI/CD pipeline using Vite, Vitest, GitHub Actions and GitHub Pages. The example is a simple React application that uses Vite as a build tool and Vitest as a testing framework. The application is deployed to GitHub Pages using GitHub Actions.
- Node.js
- npm
- GitHub account
- Fork the repository
- Clone the repository
- Checkout the
mainbranch - Install the dependencies
npm installIf at any point you get stuck, you can check out the solution branch for each lesson.
Checkout the different branches to see the solution for each lesson.
List all branches with:
git branch -a- Go to the repository
Settingstab. - Under
General, scroll down toChange repository visibility, and make sure the repository is public. - Go to the
Rules->Rulesetstab. - Select
New branch ruleset. - Enter the following:
- Ruleset name:
main - Enforcement status:
Active - Add target -> Include by pattern:
main - Check
Require a pull request before merging
- Ruleset name:
- Create directory
.github/workflows. - Create file
.github/workflows/build.yml. - Create a workflow that echoes
Hello Worldwhen a pull request receives apushevent.
Lesson 2: Check out the repository, set up Node.js and install dependencies (Solution 02-setup branch)
- Add the following steps to the workflow:
- Check out the repository using
actions/checkout@v4. - Set up Node.js using
actions/setup-node@v4. - Install dependencies using
npm ci.
- Check out the repository using
- Add the following steps to the workflow:
- Lint the application using
npm run lint. - Build the application using
npm run build. - Run tests using
npm run test.
- Lint the application using
- Follow the instructions on the Vite documentation to deploy to GitHub Pages.
- Set
baseinvite.config.jsto'/<REPO>/'.
You have successfully set up a CI/CD pipeline using Vite, Vitest, GitHub Actions and GitHub Pages!
Keep in mind that these are exercises are meant as a starting point. Feel free to build on this example or explore other tools.
| Tools | Alternatives |
|---|---|
| npm | pnpm, yarn |
| Vite | NextJS |
| Vitest | Jest |
| GitHub Actions | Jenkins, GitLab CI/CD, Circle CI |
| GitHub Pages | Netlify, Vercel |
- Add a step to the workflow to run
npm run test:coverageand upload the coverage report to the workflow artifacts. - Add a step to the workflow to integrate with a security scanner or dependency manager like Snyk or Dependabot.
- Add a new workflow to monitor the deployment status of the application and notify via email if the deployment is down.