Skip to content

Commit 557ff81

Browse files
committed
docs: 补充github action环境变量和github pages设置
1 parent 409044a commit 557ff81

File tree

5 files changed

+78
-9
lines changed

5 files changed

+78
-9
lines changed

Docs/Back-End/Node/通过Github Action将内容部署到vps.md

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# 通过GithubAction将内容部署到vps
2+
3+
## 创建Action文件
4+
在项目根目录创建 `.github/workflows/ci.yml`
5+
6+
```yml
7+
# 标题
8+
name: GitHub Actions 部署 vitepress 博客
9+
# 触发时机:表示推送master分支时触发
10+
on:
11+
push:
12+
branches:
13+
- master
14+
# 任务列表
15+
jobs:
16+
build-and-deploy:
17+
# 运行环境
18+
runs-on: ubuntu-latest
19+
# 步骤
20+
steps:
21+
# 步骤1:安装Node.js
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
# 步骤2:检出代码
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
# 步骤3:安装yarn
30+
- name: Install yarn
31+
run: npm install -g yarn
32+
# 步骤4:安装依赖
33+
- name: Install dependencies
34+
run: yarn install
35+
# 步骤5:构建VitePress
36+
- name: Build VitePress
37+
run: yarn run docs:build
38+
# 步骤6:部署到Github Pages
39+
- name: Deploy to Github Pages
40+
uses: peaceiris/actions-gh-pages@v3
41+
with:
42+
github_token: ${{ secrets.VITEPRESS_BLOG_TOKEN }} # 自定义的action环境变量
43+
publish_dir: .vitepress/dist # 指定部署目录
44+
publish_branch: gh-pages # 指定部署分支
45+
dotfiles: true # 允许使用.gitignore文件
46+
```
47+
48+
## 配置 Action 环境变量
49+
50+
1. 右上角头像 => `Settings` => `Developer Settings` => `Personal access tokens` => `Tokens(classic)` => `Generate new token`
51+
52+
![vitepress_blog_token](/Images/Back-End/Node/通过GithubAction将内容部署到vps/vitepress_blog_token.png "vitepress_blog_token")
53+
54+
::: warning 注意
55+
存储生成的 `token` ,请妥善保管,永远只出现一次。
56+
:::
57+
58+
## 仓库添加环境变量
59+
1. 打开仓库主页 => `Settings` => `Secrets and variables` => `Actions` => `New repository secret` => 填入变量名和 `token`
60+
61+
1. 推送本地代码,`github action` 检测到 `ci.yml` 文件,自动触发部署,将编译后的 `dist` 部署到 `gh-pages` 分支
62+
63+
## 配置github pages
64+
65+
1. 打开仓库主页 => `Settings` => `Pages` => `Source` => 选择 `gh-pages` 分支 => `Save`
66+
67+
![github_pages](/Images/Back-End/Node/通过GithubAction将内容部署到vps/github_pages.png "github_pages")
68+
69+
70+
71+
72+
## 参考
73+
1. [GitHub Actions 入门教程](https://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html)
74+
1. [Github 管理个人访问令牌](https://docs.github.com/zh/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
75+
1. [通过 Github Action 将 GitHub 上的内容部署到 VPS](https://tourcoder.com/deploy-from-github-to-vps-via-github-action/)
76+
1. [使用 GitHub Actions 在代码更新时自动部署代码到 VPS](https://blog.csdn.net/m0_57236802/article/details/134216395)
77+
1. [vitepress项目使用github的action自动部署到github-pages中](https://blog.csdn.net/weixin_43972992/article/details/135123018)
Loading
Loading

index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const rowWrapVal = ref(true)
120120
<a-button href="/Docs/Back-End/Node/koa使用和API实现">koa使用和API实现</a-button>
121121
<a-button href="/Docs/Back-End/Node/Taro command not found多平台解决方案">Taro command not found多平台解决方案</a-button>
122122
<a-button href="/Docs/Back-End/Node/使用Lighthouse分析前端性能">使用Lighthouse分析前端性能</a-button>
123-
<a-button href="/Docs/Back-End/Node/通过Github Action将内容部署到vps">通过Github Action将内容部署到vps</a-button>
123+
<a-button href="/Docs/Back-End/Node/通过GithubAction将内容部署到vps">通过GithubAction将内容部署到vps</a-button>
124124
</a-row>
125125

126126
<!-- Essay -->

0 commit comments

Comments
 (0)