Skip to content

Merge pull request #31 from caoergou/feat/cheat-sheet-iframes #107

Merge pull request #31 from caoergou/feat/cheat-sheet-iframes

Merge pull request #31 from caoergou/feat/cheat-sheet-iframes #107

Workflow file for this run

name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
pull-requests: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install chromium
- name: Install Chinese fonts for screenshot rendering
run: |
sudo apt-get update
sudo apt-get install -y fonts-noto-cjk fonts-noto-cjk-extra
fc-list :lang=zh | head -5
echo "✅ Chinese fonts installed"
- name: Build app and generate all assets
run: npm run build:all
- name: Check for preview image changes
id: check_changes
run: |
# Check if there are any changes in assets/ directory
if git diff --quiet assets/; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "No changes detected in preview images"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Changes detected in preview images:"
git diff --stat assets/
fi
- name: Create PR for updated preview images
if: steps.check_changes.outputs.changed == 'true'
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Ensure 'automated' label exists (ignore error if already exists)
gh label create "automated" --description "Automated PRs by CI" --color "0e8a16" 2>/dev/null || true
# Create a new branch
BRANCH_NAME="update-preview-images-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH_NAME"
# Stage and commit changes
git add assets/
git commit -m "chore: update preview images [skip ci]"
# Push the branch
git push origin "$BRANCH_NAME"
# Create PR using gh CLI
gh pr create \
--title "chore: update preview images" \
--body "$(cat <<'EOF'
## Summary
This PR updates the preview images in the `assets/` directory.
The images were automatically regenerated during the CI build process.
## Changes
$(git diff origin/main --stat assets/)
---
This PR was automatically created by the CI workflow.
EOF
)" \
--base main \
--label "automated"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate sitemap and robots.txt
run: |
chmod +x scripts/generate-sitemap.sh
# 使用站点正式域名,与 index.html / blog 中的 canonical 一致
BASE_URL="https://eric.run.place/MermZen"
./scripts/generate-sitemap.sh "$BASE_URL"
- name: Copy static content into dist
run: |
# 预览图片(合并进 dist/assets/,与 Vite 打包产物共存)
[ -d assets ] && cp assets/* dist/assets/ 2>/dev/null || true
# 博客文章
[ -d blog ] && cp -r blog dist/blog 2>/dev/null || true
# sitemap
[ -f sitemap.xml ] && cp sitemap.xml dist/ || true
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'dist'
- name: Deploy
id: deployment
uses: actions/deploy-pages@v4