Automating CI with GitHub Actions
Procedures / github-actions-ci.html
A procedure to set up a basic CI workflow that runs tests on every push.
๐ฌ Running checks on every push keeps broken code from being merged.
Before you start
- You need push access to the repository.
- Your test command must pass locally first.
Procedure
# 1) create the workflow folder
mkdir -p .github/workflows
# 2) after writing the file
git add .github/workflows/ci.yml
git commit -m "ci: add CI workflow"
git push
Example workflow (Node.js)
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20, cache: npm }
- run: npm ci
- run: npm test
Check the result
- Open the repository's Actions tab to see pass/fail per run.
- Expand a failed step to read its log.
When it fails
- npm ci fails: make sure package-lock.json is committed.
- Only tests fail: reproduce by running the last command locally.
Sources
- Official docs GitHub Actions docs โ Official docs
- GitHub actions/checkout โ Official action
Verified date indicates freshness. Check applicability conditions for older material.