GitHub Actions
intermediateCI/CD pipelines for testing, building, and deploying.
deploymentci-cdgithubautomation
Tested on⬢20▲16⚛19TS5.9
$ bunx sinew add deployment/github-actionsInteractive demo coming soon
1The Problem
Manual deployments are error-prone and time-consuming:
- Tests are skipped when rushing to ship
- Builds fail in production but passed locally
- No automated quality gates
- Inconsistent deployment process
2The Solution
Use GitHub Actions for automated CI/CD with type checking, testing, and deployment on every push.
3Files
.github/workflows/ci.yml
.github/workflows/ci.ymlYAML
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Type check
run: npm run check-types
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
build:
runs-on: ubuntu-latest
needs: [lint, typecheck, test]
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
SKIP_ENV_VALIDATION: true.github/workflows/release.yml
.github/workflows/release.ymlYAML
name: Release
on:
push:
tags:
- "v*"
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Create Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true.github/workflows/preview.yml
.github/workflows/preview.ymlYAML
name: Preview
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
deploy-preview:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
SKIP_ENV_VALIDATION: true
- name: Deploy to Vercel Preview
id: deploy
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
- name: Comment Preview URL
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 Preview deployed to: ${{ steps.deploy.outputs.preview-url }}`
}).github/dependabot.yml
.github/dependabot.ymlYAML
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
groups:
dependencies:
patterns:
- "*"
exclude-patterns:
- "eslint*"
- "typescript*"
dev-dependencies:
dependency-type: development
patterns:
- "*"4Configuration
Required Secrets
For Vercel deployment, add these secrets to your repository:
VERCEL_TOKEN- Your Vercel API tokenVERCEL_ORG_ID- Your Vercel organization IDVERCEL_PROJECT_ID- Your Vercel project ID
Branch Protection
Enable branch protection on main:
- Go to Settings > Branches
- Add rule for
main - Enable "Require status checks to pass"
- Select the CI jobs as required checks
5Usage
Running Workflows Locally
Use [act](https://github.com/nektos/act) to test workflows locally:
# Install act
brew install act
# Run CI workflow
act push
# Run a specific job
act -j buildBash
Manual Workflow Triggers
Add workflow_dispatch for manual triggers:
on:
workflow_dispatch:
inputs:
environment:
description: "Deployment environment"
required: true
default: "staging"
type: choice
options:
- staging
- productionYAML
6Troubleshooting
Workflows not running
- Check that workflows are in
.github/workflows/ - Verify the
ontrigger matches your event - Check repository settings for Actions permissions
Slow workflows
- Use
concurrencyto cancel redundant runs - Cache dependencies with
actions/cacheoractions/setup-nodecache - Run independent jobs in parallel