📋JSON Templates
GitHub Actions Workflow
GitHub Actions workflow configuration for CI/CD pipelines.
Explanation
GitHub Actions automate build, test, and deployment workflows.
Examples
Node.js CI Workflow
Output
{
"name": "CI",
"on": {
"push": {
"branches": [
"main"
]
},
"pull_request": {
"branches": [
"main"
]
}
},
"jobs": {
"test": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v3"
},
{
"name": "Setup Node.js",
"uses": "actions/setup-node@v3",
"with": {
"node-version": "20"
}
},
{
"name": "Install dependencies",
"run": "npm ci"
},
{
"name": "Run tests",
"run": "npm test"
}
]
}
}
}Code Examples
GitHub Actions YAML
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
- name: Build
run: npm run buildTry it Now
💡 Tips
- Use YAML format (more readable than JSON)
- Cache dependencies to speed up runs
- Use matrix for multiple versions
- Store secrets in GitHub Secrets
- Use actions from GitHub Marketplace
⚠️ Common Pitfalls
- Workflows must be in .github/workflows/
- Syntax errors prevent workflow from running
- Be careful with secrets in logs
- Rate limits on external API calls