GitHub Actions 和 GitLab CI/CD 流水线设计

以下是关于 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-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v3
    
    - name: Setup Node
      uses: actions/setup-node@v3
      with:
        node-version: 18
    
    - name: Install & Build
      run: |
        npm ci
        npm run build
    
    - name: Upload Artifact
      uses: actions/upload-artifact@v3
      with:
        name: dist
        path: dist/
2. GitLab CI 基础模板
stages:
  - build
  - test
  - deploy

build:
  stage: build
  image: node:18
  script:
    - npm ci
    - npm run build
  artifacts:
    paths:
      - dist/
  rules:
    - if: $CI_COMMIT_BRANCH == "main"

test:
  stage: test
  needs: [build]
  

你可能感兴趣的:(前端核心知识总结,前端,架构,前端框架,github,gitlab,ci/cd)