Belajar
← Semua pelajaran

Cara kerja CI/CD

Dari git push sampai production

Kamu
Git host
CI runner
Production

.github/workflows/deploy.yml

on:  push:    branches: [main]jobs:  ship:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v7      - run: npm ci      - run: npm test      - run: npm run build      - run: ./deploy.sh dist/

runner.js

// yang dilakukan runner dengan tiap langkahfor (const step of job.steps) {  const code = await exec(step);  if (code !== 0) {    return report("failure"); // langkah sesudahnya tidak pernah jalan  }}report("success");

Push sebuah perubahan dan lihat apa yang ter-deploy

Branchmainfix-taxPerubahanUbah READMERefactor total()Bulatkan ke bawah
Diff-nya
Pipeline
Production menjalankanv12 · 7d03be1

Branch fitur juga dites. Hanya main yang di-deploy

.github/workflows/ci.yml

on: pushjobs:  ship:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v7      - run: npm ci      - run: npm test      - run: npm run build      # hanya push ke main yang di-deploy      - if: github.ref == 'refs/heads/main'        run: ./deploy.sh dist/

price.test.js

import { total } from "./price.js"; test("adds 11% tax", () => {  expect(total(10000)).toBe(11100);});test("rounds half a cent up", () => {  expect(total(1050)).toBe(1166);});test("free stays free", () => {  expect(total(0)).toBe(0);});

Topik

Berikutnya: Cara kerja semantic versioning

Buka pelajaran