Github Action & Github Pages 记录

Github Pages

  1. Github Pages 能做什么?不能做什么?

    • Gtihub只能托管静态页面(前端三大件css/html/js)
    • 所有服务端渲染技术都不能用,如php/jsp/asp/blazor

    所以Github Pages适合做静态博客,比如 Hexo,也可以放前后分离的前端项目,如Vue的部署包

  2. 实操

    配置启用 Github Pages,向仓为推代码

    配置要点:

    1. 发部源

      选择仓库、分支,一般建一个 gh_pages 分支发布

    2. 发部路径

      默认是<username>.github.io/<repository_name>,也可不写仓库名 <username>.github.io ,这样就是配置成Pages的主页

    3. CNAME

      域名重命名,两边都要处理:在域名服务商处配置域名解析CNAME到Pages的发布路径;Pages的CNAME配置指向域名

Github Actions

Actions就是CI/CD,可以打通issues/pull/repository/release等Github所有资源。Actions是跑在容器里的,使用shell脚本非常方便,并且常用功能已经有现成的轮子,可以从Actions Market复制粘贴。

以下是Actions发布Github Pages示例:

name: GitHub Pages
on:
  push:
    branches:
      - master
jobs:
  deploy:
    # 启一个容器
    runs-on: ubuntu-latest
    # Actions权限
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true

      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: "14.x"

      - name: Install Dependencies
        run: npm install

      - name: Build
        run: npm run build
        # 环境变量
        env:
          VITE_API: https://www.ppos.top/api
     
      - name: Deploy
        # 现成轮子:将代码发布到Github Pages,必须先建gh_pages分支,并配置Actions的可写权限
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }} # Actions 后台变量
          publish_dir: ./dist
          force_orphan: true


GitHub Pages 使用入门 - GitHub 文档

了解 GitHub Actions - GitHub 文档

posted @ 2024-01-25 10:30  MangoJuice  阅读(3)  评论(0编辑  收藏  举报