Skip to content

Build and Deploy to GitHub Pages #45

Build and Deploy to GitHub Pages

Build and Deploy to GitHub Pages #45

Workflow file for this run

name: Build and Deploy to GitHub Pages
on:
push:
branches: [ "main" ]
paths:
- 'src/**'
- 'package*.json'
- 'build.js'
schedule:
# 每天 UTC 时间 2 点运行 (相当于北京时间晚上 10 点)
- cron: '0 2 * * *'
workflow_dispatch: # 允许手动触发工作流
# Set permissions for GitHub Actions
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build website
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v4
continue-on-error: true # 允许错误继续执行
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
- name: Deploy to GitHub Pages
if: github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
uses: actions/deploy-pages@v4
continue-on-error: true # 允许错误继续执行
with:
github_token: ${{ secrets.GITHUB_TOKEN }}