Files
Interview-Notebook/.github/workflows/website.yml

81 lines
2.9 KiB
YAML

name: 网站构建与发布
on:
push:
branches: [master]
pull_request:
paths:
- '.github/workflows/website.yml'
- 'README.md'
- 'CONTRIBUTING.md'
- 'notes/**'
- 'assets/**'
- 'docs/_media/**'
- 'website/**'
schedule:
# UTC; Beijing time 09:17 and 21:17.
- cron: '17 1,13 * * *'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: website-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
website:
runs-on: ubuntu-24.04
timeout-minutes: 25
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
ref: ${{ github.event_name == 'pull_request' && github.ref || 'master' }}
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.12'
cache: pip
cache-dependency-path: website/requirements.txt
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
package-manager-cache: false
- name: 安装固定版本依赖
run: |
python -m pip install -r website/requirements.txt
npm ci --prefix website/deploy --ignore-scripts
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: website/.cache/site-assets
key: site-webp-${{ runner.os }}-${{ hashFiles('website/requirements.txt') }}-${{ hashFiles('website/builder/site_assets.py', 'notes/pics/**', 'assets/**', 'docs/_media/**') }}
restore-keys: site-webp-${{ runner.os }}-${{ hashFiles('website/requirements.txt') }}-
- name: 生成并校验网站与配图
run: python website/refresh.py --from-checkout
- name: 检查搜索和发布保护
run: |
python website/builder/test_site_assets.py
python website/deploy/test_package_site.py
node website/builder/test_search.cjs
npm test --prefix website/deploy
- name: 发布网页和图片并校验正式域名
if: github.repository == 'CyC2018/CS-Notes' && github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
env:
EDGEONE_API_TOKEN: ${{ secrets.EDGEONE_API_TOKEN }}
run: node website/deploy/deploy.mjs
- name: 保留小型版本报告
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: website-report-${{ github.run_id }}-${{ github.run_attempt }}
path: |
website/dist/build-info.json
website/dist/asset-manifest.json
website/dist-report.json
website/validation.json
website/deployment-report.json
retention-days: 7
if-no-files-found: warn