Github 创建 Action 部署到 GithubPage

Github 创建 Action 部署到 GithubPage

获取 github-token

Settings / Developer settings / Personal access tokens,授权 Action 的读写。

创建脚本

项目内创建工作流的脚本.github/workflows/deploy-gh.yml

 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
name: Deploy to GitHub Pages

on:
  # 每当 push 到 main 分支时触发部署
  push:
    branches: [master]
  # 手动触发部署
  workflow_dispatch:

jobs:
  docs:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          # “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          # 选择要使用的 node 版本
          node-version: '16'

      # 安装依赖
      - name: Install dependencies
        run: npm i

      - name: Install vite
        run: npm i -g vite

      # 运行构建脚本
      - name: Build frontend
        run: vite build

      - name: Deploy to GitHub Pages
        uses: crazy-max/ghaction-github-pages@v2
        with:
          # 部署到 gh-pages 分支
          target_branch: gh-pages
          # 部署目录为Vite项目的默认输出目录
          build_dir: ./dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Licensed under CC BY-NC-SA 4.0
Gear(夕照)的博客。记录开发、生活,以及一些不足为道的思考……