GitHub Pages Deploy Nitro apps to

将 Nitro 应用部署到 GitHub Pages

Preset: github_pages

相关阅读:GitHub Pages

设置

按照以下步骤创建 GitHub Pages 站点

部署

以下是使用 github_pages 预设将站点部署到 GitHub Pages 的 GitHub Actions 工作流示例:

.github/workflows/deploy.yml
yaml
# https://github.com/actions/deploy-pages#usage
name: Deploy to GitHub Pages

on:
  workflow_dispatch:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: corepack enable
      - uses: actions/setup-node@v3
        with:
          node-version: '18'

      - run: npx nypm install
      - run: npm run build
        env:
          NITRO_PRESET: github_pages

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v1
        with:
          path: ./.output/public

  # 部署作业
  deploy:
    # 向构建作业添加依赖项
    needs: build

    # 授予 GITHUB_TOKEN 进行 Pages 部署所需的权限
    permissions:
      pages: write # 部署到 Pages
      id-token: write # 验证部署是否来自适当的来源

    # 部署到 github_pages 环境
    environment:
      name: github_pages
      url: ${{ steps.deployment.outputs.page_url }}

    # 指定运行器 + 部署步骤
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1