Fix wrong links

This commit is contained in:
Baohua Yang
2026-02-22 16:04:41 -08:00
parent 4ca47b0ea1
commit 572266b2f4
78 changed files with 626 additions and 1136 deletions

View File

@@ -0,0 +1,53 @@
# 21.2 GitHub Actions
GitHub [Actions](https://github.com/features/actions) 是 GitHub 推出的一款 CI/CD 工具。
我们可以在每个 `job` `step` 中使用 Docker 执行构建步骤
## 21.2.1 最小可用示例
在仓库根目录创建 `/.github/workflows/ci.yml`
```yaml
name: CI
on:
push:
pull_request:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
context: .
push: false
tags: local/test:ci
```
该示例会在 GitHub Actions 中构建当前仓库的 Docker 镜像不推送到 registry
## 21.2.2 最佳实践
* 固定 action 的主版本例如 `@v4` / `@v6`避免使用 `@master` 这类浮动引用
* 设置最小权限例如 `contents: read`需要写入权限时再打开
* 需要依赖缓存时优先使用官方支持的缓存方案例如针对语言包管理器的 cache BuildKit cache
如果你需要在某个步骤里直接运行容器镜像而不是构建镜像可以使用 `docker://` 语法
```yaml
- name: Run container step
uses: docker://golang:alpine
with:
args: go version
```
## 21.2.3 参考资料
* [Actions Docs](https://docs.github.com/en/actions)