Konsep Dasar GitHub Actions
- Workflow – file YAML di
.github/workflows/ - Trigger (on) – event yang memicu workflow (push, PR, schedule)
- Job – unit eksekusi yang berjalan di runner
- Step – perintah individual dalam job
- Action – reusable unit of code
CI Pipeline Dasar
Trigger: on: [push, pull_request]. Steps: checkout code, setup Node.js, install dependencies, run lint, run tests, build. Semua harus pass sebelum PR bisa di-merge.
CD Pipeline
Trigger: on: push: branches: [main]. Setelah CI pass, build Docker image, push ke registry, dan deploy ke target environment. Gunakan environments dengan protection rules untuk production.
Reusable Workflows
Extract workflow yang dipakai berulang ke .github/workflows/reusable-*.yml dengan on: workflow_call. Panggil dari workflow lain dengan uses: ./.github/workflows/reusable-deploy.yml.
Secrets dan Variables
Simpan credentials (AWS keys, API tokens) di GitHub Secrets. Gunakan environment-level secrets untuk isolasi antara staging dan production. Jangan hardcode credentials di workflow file.
Matrix Strategy
Test di multiple environments simultan: strategy: matrix: node-version: [16, 18, 20]. GitHub Actions menjalankan job paralel untuk setiap kombinasi, mempersingkat waktu keseluruhan.