最小 GitHub Actions 与 GitLab CI
你不需要一开始就写复杂流水线。一个能跑测试、构建、部署的最小配置就足够。
GitHub Actions 示例
name: deploy
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "run tests here"
- run: echo "build artifact here"
- run: echo "deploy here"
GitHub Actions vs GitLab CI
| 平台 | 特点 |
|---|---|
| GitHub Actions | 生态广、适合 GitHub 仓库 |
| GitLab CI | 集成度高、适合 GitLab 内部流 |
设计原则
- 流水线只做确定性的步骤
- secrets 放平台密钥库
- 失败时立即退出
本节执行清单
- [ ] 为仓库创建最小流水线
- [ ] 把敏感变量放进 secrets
- [ ] 让流水线至少执行一次测试或检查
下一节:构建、测试、部署、回滚串联——把单个 job 变成完整发布链。