将网站托管到GitHub上

98 阅读1分钟

项目地址

1、创建公开仓库

image.png

2、打开pages,选择分支,默认是root,可以选择docs

image.png

3、上传项目,如果根目录下有index.html文件或者README.md文档,会自动完成发布

4、使用actions 完成自动构建和自动发布,yml文件,配置如下

根据文档上的来,没有完成自动发布,将pages的分支改为master的docs文档,打包也到根目录下的docs文件夹

提交后自动打包commit,触发自动发布,完成网站的部署

# 参考文档 https://blog.csdn.net/SiShen654/article/details/132471133
name: CI

run-name: ${{ github.actor }} is update repo, start building...

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
  # 允许您从“操作”选项卡手动运行此工作流
  workflow_dispatch:
# 设置权限(文件是可以被读写修改的)
permissions:
  contents: write
  pages: write
  id-token: write
jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x]

    steps:
    - uses: actions/checkout@v3

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
    - name: Build
      run: |
        npm install
        npm run build
    - name: Commit and push
      run: |
        git config --global user.email "*****"
        git config --global user.name "****"
        git add docs/*
        git commit -m "Deploy build artifact"
        git push origin master