-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (114 loc) · 4.78 KB
/
deploy.yml
File metadata and controls
133 lines (114 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
packages: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
# ──────────────────────────────────────────────────────────────────────────
# 1. 构建 VitePress → GitHub Pages
#
# VITEPRESS_BASE 优先级:
# 1. repo 变量 vars.VITEPRESS_BASE(Settings > Variables > Actions)
# 2. 兜底自动使用 /<仓库名>/ (e.g. /fishxcode/)
#
# 如果已绑定自定义域名 doc.fishxcode.com,在 repo Variables 设置:
# VITEPRESS_BASE = /
# ──────────────────────────────────────────────────────────────────────────
build-pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- uses: actions/cache@v4
with:
path: docs/.vitepress/cache
key: vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-${{ hashFiles('docs/**/*.md', 'docs/.vitepress/config.mts') }}
restore-keys: |
vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-
vitepress-${{ runner.os }}-
- run: bun install --frozen-lockfile
- name: Build (GitHub Pages)
run: bun run docs:build
env:
VITEPRESS_BASE: ${{ vars.VITEPRESS_BASE || format('/{0}/', github.event.repository.name) }}
- uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
# ──────────────────────────────────────────────────────────────────────────
# 2. 部署到 GitHub Pages
# ──────────────────────────────────────────────────────────────────────────
deploy-pages:
needs: build-pages
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
# ──────────────────────────────────────────────────────────────────────────
# 3. 构建并推送 Docker 镜像
#
# Docker 始终以 VITEPRESS_BASE=/ 构建,因为 nginx 从根路径服务。
# 借助 bun + VitePress + Docker 层三重缓存,二次构建极快。
# ──────────────────────────────────────────────────────────────────────────
docker:
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
# 复用与 build-pages 相同的 VitePress 缓存 key
- uses: actions/cache@v4
with:
path: docs/.vitepress/cache
key: vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-${{ hashFiles('docs/**/*.md', 'docs/.vitepress/config.mts') }}
restore-keys: |
vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-
vitepress-${{ runner.os }}-
- run: bun install --frozen-lockfile
- name: Build (Docker, base=/)
run: bun run docs:build
env:
VITEPRESS_BASE: /
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=sha,prefix=sha-,format=short
- uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max