Community程式設計與開發github.com

alfathafp/portofolio-web-design

為專案自動設定 CI/CD 管線,包含品質閘門、測試配置與部署策略。

portofolio-web-design 是什麼?

此技能提供一套完整的 CI/CD 自動化解決方案,重點在於建立自動化品質閘門,確保每次程式碼變更在合併前都必須通過 lint、型別檢查、單元測試、建置、整合測試、端對端測試及安全性稽核等多道關卡。它支援 GitHub Actions,並提供常見場景的 YAML 配置範例,如基本 CI、資料庫整合測試、E2E 測試、預覽部署與手動回滾。技能也涵蓋相依性自動更新 (Dependabot)、功能旗標生命週期管理、分階段部署、環境變數最佳實務以及 CI 管線最佳化策略 (快取、平行化作業、路徑過濾等),旨在幫助開發團隊建立可靠且高效率的持續交付流程。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/ci-cd-and-automation

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

CI/CD 與自動化

概述

自動化品質閘門,確保任何變更在未通過測試、lint、型別檢查和建置之前,絕不會進入正式環境。CI/CD 是所有其他技能的強制執行機制——它能捕捉人類和 AI 代理遺漏的問題,並且對每一次變更都一致地執行此動作。

左移 (Shift Left): 在管線中盡可能提早發現問題。在 lint 階段發現的錯誤只花幾分鐘;在正式環境發現同樣的錯誤則可能耗費數小時。將檢查流程往上游移動——靜態分析在測試之前,測試在暫存環境之前,暫存環境在正式環境之前。

越快越安全: 較小的批次和更頻繁的發佈會降低風險,而非增加。部署包含 3 個變更的版本比包含 30 個變更的版本更容易除錯。頻繁的發佈能建立對發佈流程本身的信心。

使用時機

  • 設定新專案的 CI 管線
  • 新增或修改自動化檢查
  • 配置部署管線
  • 當變更應觸發自動化驗證時
  • 除錯 CI 失敗

品質閘門管線

每一次程式碼變更在合併前都必須通過以下關卡:

Pull Request 已開啟
    │
    ▼
┌─────────────────────┐
│   LINT 檢查          │  eslint, prettier
│   ↓ 通過             │
│   型別檢查            │  tsc --noEmit
│   ↓ 通過             │
│   單元測試            │  jest/vitest
│   ↓ 通過             │
│   建置               │  npm run build
│   ↓ 通過             │
│   整合測試            │  API/DB 測試
│   ↓ 通過             │
│   E2E (選擇性)       │  Playwright/Cypress
│   ↓ 通過             │
│   安全性稽核          │  npm audit
│   ↓ 通過             │
│   套件大小檢查        │  bundlesize check
└─────────────────────┘
    │
    ▼
  準備好進行程式碼審查

沒有任何關卡可以被跳過。 如果 lint 失敗,就修正 lint——不要停用規則。如果測試失敗,就修正程式碼——不要跳過測試。

GitHub Actions 配置

基本 CI 管線

# .github/workflows/ci.yml
name: CI

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'

      - name: 安裝相依套件
        run: npm ci

      - name: Lint
        run: npm run lint

      - name: 型別檢查
        run: npx tsc --noEmit

      - name: 測試
        run: npm test -- --coverage

      - name: 建置
        run: npm run build

      - name: 安全性稽核
        run: npm audit --audit-level=high

含資料庫整合測試

  integration:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:16
        env:
          POSTGRES_DB: testdb
          POSTGRES_USER: ci_user
          POSTGRES_PASSWORD: ${{ secrets.CI_DB_PASSWORD }}
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'
      - run: npm ci
      - name: 執行遷移
        run: npx prisma migrate deploy
        env:
          DATABASE_URL: postgresql://ci_user:${{ secrets.CI_DB_PASSWORD }}@localhost:5432/testdb
      - name: 整合測試
        run: npm run test:integration
        env:
          DATABASE_URL: postgresql://ci_user:${{ secrets.CI_DB_PASSWORD }}@localhost:5432/testdb

注意: 即使是僅用於 CI 的測試資料庫,也應使用 GitHub Secrets 儲存憑證,而非直接寫死數值。這有助於建立良好習慣,並防止測試憑證在其他情境中被意外重用。

E2E 測試

  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'
      - run: npm ci
      - name: 安裝 Playwright
        run: npx playwright install --with-deps chromium
      - name: 建置
        run: npm run build
      - name: 執行 E2E 測試
        run: npx playwright test
      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: playwright-report
          path: playwright-report/

將 CI 失敗回饋給 AI 代理

CI 與 AI 代理結合的強大之處在於反饋迴圈。當 CI 失敗時:

CI 失敗
    │
    ▼
複製失敗輸出
    │
    ▼
提供給 AI 代理:
「CI 管線因以下錯誤而失敗:
[貼上特定錯誤]
修正此問題並在本地端驗證後,再重新推送。」
    │
    ▼
代理修正 → 推送 → CI 重新執行

關鍵模式:

Lint 失敗 → 代理執行 `npm run lint --fix` 並提交
型別錯誤  → 代理讀取錯誤位置並修正型別
測試失敗 → 代理遵循除錯與錯誤復原技能
建置錯誤 → 代理檢查配置和相依套件

部署策略

預覽部署

每個 Pull Request 都獲得一個預覽部署以供手動測試:

# 在 PR 上部署預覽 (Vercel/Netlify 等)
deploy-preview:
  runs-on: ubuntu-latest
  if: github.event_name == 'pull_request'
  steps:
    - uses: actions/checkout@v4
    - name: 部署預覽
      run: npx vercel --token=${{ secrets.VERCEL_TOKEN }}

功能旗標

功能旗標將部署與發佈脫鉤。將未完成或有風險的功能部署在旗標後面,以便:

  • 在不啟用的情況下發佈程式碼。 提早合併到 main,準備好時再啟用。
  • 無需重新部署即可回滾。 停用旗標而非還原程式碼。
  • 金絲雀 (Canary) 發布新功能。 先對 1% 的使用者啟用,然後 10%,最後 100%。
  • 執行 A/B 測試。 比較啟用與未啟用該功能時的行為。
// 簡單的功能旗標模式
if (featureFlags.isEnabled('new-checkout-flow', { userId })) {
  return renderNewCheckout();
}
return renderLegacyCheckout();

旗標生命週期: 建立 → 啟用以供測試 → 金絲雀發布 → 全面上線 → 移除旗標與死程式碼。永久存在的旗標會變成技術債——在建立時就設定清理日期。

分階段部署

PR 合併到 main
    │
    ▼
  暫存環境部署 (自動)
    │ 手動驗證
    ▼
  正式環境部署 (手動觸發或暫存環境驗證後自動)
    │
    ▼
  監控錯誤 (15 分鐘窗口)
    │
    ├── 偵測到錯誤 → 回滾
    └── 乾淨 → 完成

回滾計畫

每個部署都應可逆轉:

# 手動回滾工作流程
name: Rollback
on:
  workflow_dispatch:
    inputs:
      version:
        description: '要回滾到的版本'
        required: true

jobs:
  rollback:
    runs-on: ubuntu-latest
    steps:
      - name: 回滾部署
        run: |
          # 部署指定的先前版本
          npx vercel rollback ${{ inputs.version }}

環境管理

.env.example       → 加入版控 (開發者範本)
.env                → 不加入版控 (本地開發)
.env.test           → 加入版控 (測試環境,無真實機密)
CI secrets          → 儲存在 GitHub Secrets / vault
正式環境 secrets    → 儲存在部署平台 / vault

CI 絕不應擁有正式環境的機密。請為 CI 測試使用獨立的 secrets。

超越 CI 的自動化

Dependabot / Renovate

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: npm
    directory: /
    schedule:
      interval: weekly
    open-pull-requests-limit: 5

Build Cop 角色

指定某人負責維持 CI 綠色狀態。當建置中斷時,Build Cop 的工作是修復或還原——而不是導致該變更的人。這可以防止中斷的建置在大家都以為別人會修復的情況下不斷累積。

PR 檢查

  • 必要審查: 合併前至少需有 1 人核准
  • 必要狀態檢查: CI 必須通過才能合併
  • 分支保護: 禁止強制推送到 main
  • 自動合併: 若所有檢查通過且已核准,則自動合併

CI 管線最佳化

當管線執行時間超過 10 分鐘時,請依影響程度依序套用以下策略:

CI 管線太慢?
├── 快取相依套件
│   └── 使用 actions/cache 或 setup-node 的快取選項來快取 node_modules
├── 平行執行工作
│   └── 將 lint、型別檢查、測試、建置拆分為獨立的平行工作
├── 僅執行有變更的部分
│   └── 使用路徑過濾器跳過不相關的工作 (例如,僅修改文件的 PR 跳過 E2E)
├── 使用矩陣建置
│   └── 將測試套件分散到多個執行器上
├── 最佳化測試套件
│   └── 從關鍵路徑中移除慢速測試,改為排程執行
└── 使用更大的執行器
    └── 對於 CPU 密集型建置,使用 GitHub 託管的較大執行器或自託管執行器

範例:快取與平行化

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: 'npm' }
      - run: npm ci
      - run: npm run lint

  typecheck:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: 'npm' }
      - run: npm ci
      - run: npx tsc --noEmit

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: 'npm' }
      - run: npm ci
      - run: npm test -- --coverage

常見藉口

藉口現實
「CI 太慢了」最佳化管線 (請見上方 CI 最佳化),不要跳過它。一條 5 分鐘的管線能省下數小時的除錯時間。
「這個變更很 trivial,跳過 CI」看起來很小的變更也會破壞建置。而且對 trivial 變更來說,CI 很快。
「測試不穩定,重新執行就好」不穩定的測試會掩蓋真正的錯誤並浪費所有人的時間。請修正不穩定性。
「我們之後再加入 CI」沒有 CI 的專案會累積損壞狀態。請在專案第一天就設定好。
「手動測試就夠了」手動測試無法擴展也無法重複。請盡可能將測試自動化。

紅旗警示

  • 專案中沒有 CI 管線
  • CI 失敗被忽略或靜默處理
  • 為了讓管線通過而在 CI 中停用測試
  • 未經暫存環境驗證就直接部署正式環境
  • 沒有回滾機制
  • 機密資訊儲存在程式碼或 CI 配置檔中 (而非機密管理工具)
  • CI 執行時間過長且未進行最佳化

驗證清單

設定或修改 CI 後:

  • 所有品質閘門都已到位 (lint、型別、測試、建置、稽核)
  • 管線在每次 PR 和推送到 main 時都會執行
  • 失敗會阻止合併 (已配置分支保護)
  • CI 結果會回饋到開發迴圈中
  • 機密資訊儲存在機密管理工具中,而非程式碼中
  • 部署具有回滾機制
  • 管線執行時間在 10 分鐘以內 (針對測試套件)

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相關技能