pref readme #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to GitHub Pages | |
on: | |
# 在推送到 main 分支时触发 | |
push: | |
branches: [ "main", "master" ] | |
# 允许在 GitHub Actions 页面手动触发 | |
workflow_dispatch: | |
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# 只允许一个并发部署,新的部署会取消正在进行的部署 | |
concurrency: | |
group: "pages" | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build for GitHub Pages | |
run: npm run build:pages | |
- name: Setup Pages | |
# 使用官方 Action 配置 GitHub Pages | |
uses: actions/configure-pages@v4 | |
- name: Upload artifact | |
# 将构建产物上传,以便部署任务使用 | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
# 从 'dist' 目录上传 | |
path: './dist' | |
deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
# `deploy` 任务依赖于 `build` 任务的成功完成 | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |