Apa itu GitHub Actions?
GitHub Actions adalah platform CI/CD bawaan GitHub. Workflow didefinisikan dalam file YAML di .github/workflows/.
Konsep Utama
- Workflow — Satu proses otomasi (file YAML)
- Event/Trigger — Apa yang memicu workflow (push, PR, schedule)
- Job — Sekelompok step yang jalan di satu runner
- Step — Satu perintah atau action
- Action — Komponen reusable (dari marketplace atau custom)
Workflow Pertama
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
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
Environment Variables & Secrets
jobs:
deploy:
runs-on: ubuntu-latest
env:
NODE_ENV: production
steps:
- name: Deploy
env:
API_KEY: ${{ secrets.API_KEY }}
run: |
echo "Deploying with key: $API_KEY"
Caching Dependencies
- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}