Skip to content

添加自动部署静态页面脚本 #2

添加自动部署静态页面脚本

添加自动部署静态页面脚本 #2

Workflow file for this run

name: Deploy talks to GitHub Pages
on:
push:
branches: [main, master]
paths:
- talks/**
- .github/workflows/pages.yml
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: talks
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.22.0
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: talks/pnpm-lock.yaml
- uses: actions/configure-pages@v5
- name: Compute base prefix
id: base
shell: bash
run: |
repo="${GITHUB_REPOSITORY##*/}"
owner="${GITHUB_REPOSITORY_OWNER}"
if [ "$repo" = "${owner}.github.io" ]; then
echo "prefix=" >> "$GITHUB_OUTPUT"
else
echo "prefix=/$repo" >> "$GITHUB_OUTPUT"
fi
- name: Install
run: pnpm install --frozen-lockfile
- name: Build
env:
TALKS_URL_PREFIX: ${{ steps.base.outputs.prefix }}
shell: bash
run: |
pnpm run build
touch dist/.nojekyll
# Simple landing page at https://<user>.github.io/<repo>/
dirs=$(find dist -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort)
{
echo '<!doctype html>'
echo '<meta charset="utf-8">'
echo '<meta name="viewport" content="width=device-width, initial-scale=1">'
echo '<title>Talks</title>'
echo '<style>body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;max-width:960px;margin:40px auto;padding:0 16px;line-height:1.5}h1{margin:0 0 12px}ul{padding-left:18px}a{color:#2563eb;text-decoration:none}a:hover{text-decoration:underline}</style>'
echo '<h1>Talks</h1>'
echo '<ul>'
for d in $dirs; do
if [ -f "dist/$d/index.html" ]; then
echo " <li><a href=\"./$d/\">$d</a></li>"
fi
done
echo '</ul>'
echo '<p>Built with <a href="https://sli.dev/">Slidev</a>.</p>'
} > dist/index.html
- uses: actions/upload-pages-artifact@v3
with:
path: talks/dist
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4