主题
常用 Actions
基础
actions/checkout
检出仓库,通常作为第一步:
yaml
- uses: actions/checkout@v4
with:
ref: main
submodules: true
fetch-depth: 0| 参数 | 说明 |
|---|---|
ref | 分支 / 标签 / commit |
submodules | 是否检出子模块 |
fetch-depth | 历史深度,0 表示完整 |
actions/cache
缓存依赖或构建产物:
yaml
- uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-环境
actions/setup-node
yaml
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: pnpm
registry-url: https://registry.npmjs.orgcache 可选 npm / yarn / pnpm。
pnpm/action-setup
yaml
- uses: pnpm/action-setup@v4
with:
version: latest
run_install: false部署与发布
JamesIves/github-pages-deploy-action
yaml
- uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: dist
token: ${{ secrets.GITHUB_TOKEN }}softprops/action-gh-release
actions/create-release 已归档,推荐:
yaml
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: |
详见 CHANGELOG。
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}docker/build-push-action
yaml
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/<user>/<repo>:latest
ghcr.io/<user>/<repo>:${{ github.sha }}