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-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]