mirror of
https://github.com/byoungd/up.git
synced 2026-10-02 08:04:40 +08:00
93 lines
3.4 KiB
YAML
93 lines
3.4 KiB
YAML
name: Deploy GitHub Pages
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
pages: write
|
|
id-token: write
|
|
|
|
concurrency:
|
|
group: pages
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- uses: actions/setup-node@v7
|
|
with:
|
|
node-version: 24
|
|
cache: npm
|
|
- uses: actions/setup-python@v6
|
|
with:
|
|
python-version: "3.12"
|
|
- uses: actions/configure-pages@v6
|
|
- run: npm ci
|
|
- run: python -m pip install -r requirements-pdf.txt
|
|
- run: npm run check
|
|
- run: npm run docs:build
|
|
- uses: actions/upload-pages-artifact@v5
|
|
with:
|
|
path: docs/.vitepress/dist
|
|
|
|
deploy:
|
|
environment:
|
|
name: github-pages
|
|
url: ${{ steps.deployment.outputs.page_url }}
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
steps:
|
|
- name: Deploy to GitHub Pages
|
|
id: deployment
|
|
uses: actions/deploy-pages@v5
|
|
- name: Verify published entry points
|
|
env:
|
|
PAGE_URL: ${{ steps.deployment.outputs.page_url }}
|
|
EXPECTED_SHA: ${{ github.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
entries=(
|
|
$'/|人生进阶指南'
|
|
$'/en/|Life Level-up Guide'
|
|
$'/threads/part-3/5-evidence-and-transfer|证据篇:变化要如何被看见'
|
|
$'/en/threads/part-3/5-evidence-and-transfer|Evidence: How Change Becomes Visible'
|
|
)
|
|
for entry in "${entries[@]}"; do
|
|
IFS='|' read -r path expected_title <<< "$entry"
|
|
url="${PAGE_URL%/}${path}"
|
|
body="$(curl --fail --location --retry 8 --retry-delay 5 --connect-timeout 15 --max-time 45 "$url")"
|
|
if ! grep -Fq "$expected_title" <<< "$body"; then
|
|
printf 'Unexpected title for %s; expected %s\n' "$url" "$expected_title" >&2
|
|
exit 1
|
|
fi
|
|
if ! grep -Fq "name=\"build-revision\" content=\"$EXPECTED_SHA\"" <<< "$body"; then
|
|
printf 'Unexpected build revision for %s; expected %s\n' "$url" "$EXPECTED_SHA" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
downloads=(
|
|
$'/downloads/life-level-up-guide-zh.epub|application/epub+zip|0-3|504b0304'
|
|
$'/downloads/life-level-up-guide-en.epub|application/epub+zip|0-3|504b0304'
|
|
$'/downloads/life-level-up-guide-zh.pdf|application/pdf|0-4|255044462d'
|
|
$'/downloads/life-level-up-guide-en.pdf|application/pdf|0-4|255044462d'
|
|
)
|
|
for entry in "${downloads[@]}"; do
|
|
IFS='|' read -r path expected_type byte_range expected_signature <<< "$entry"
|
|
url="${PAGE_URL%/}${path}"
|
|
headers="$(curl --fail --head --location --retry 8 --retry-delay 5 --connect-timeout 15 --max-time 45 "$url")"
|
|
if ! grep -Fiq "content-type: ${expected_type}" <<< "$headers"; then
|
|
printf 'Unexpected content type for %s; expected %s\n' "$url" "$expected_type" >&2
|
|
exit 1
|
|
fi
|
|
signature="$(curl --fail --silent --show-error --location --retry 8 --retry-delay 5 --connect-timeout 15 --max-time 45 --range "$byte_range" "$url" | od -An -tx1 | tr -d ' \n')"
|
|
if [[ "$signature" != "$expected_signature" ]]; then
|
|
printf 'Unexpected file signature for %s; expected %s, received %s\n' "$url" "$expected_signature" "$signature" >&2
|
|
exit 1
|
|
fi
|
|
done
|