以下是關于 GitHub Actions 和 GitLab CI/CD 流水線設計 的基本知識總結:
一、核心概念對比
維度 | GitHub Actions | GitLab CI/CD |
---|---|---|
配置方式 | YAML 文件(.github/workflows/*.yml) | .gitlab-ci.yml |
執行環境 | GitHub 托管 Runner / 自托管 | GitLab 共享 Runner / 自托管 |
市場生態 | Actions Marketplace 豐富 | 內置模板庫完善 |
流水線可視化 | 基礎時間軸視圖 | 完整 DAG 圖支持 |
多項目協作 | 需手動配置跨倉庫觸發 | 原生支持跨項目流水線觸發 |
二、基礎流水線設計
1. GitHub Actions 基礎模板
name: Frontend CI
on:push:branches: [ main ]pull_request:branches: [ main ]jobs:build:runs-on: ubuntu-lateststeps:- name: Checkoutuses: actions/checkout@v3- name: Setup Nodeuses: actions/setup-node@v3with:node-version: 18- name: Install & Buildrun: |npm cinpm run build- name: Upload Artifactuses: actions/upload-artifact@v3with:name: distpath: dist/
2. GitLab CI 基礎模板
stages:- build- test- deploybuild:stage: buildimage: node:18script:- npm ci- npm run buildartifacts:paths:- dist/rules:- if: $CI_COMMIT_BRANCH == "main"test:stage: testneeds: [build]