Repository navigation
更新网站构建工作流的 PR 关闭取消机制 #276
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 网站构建与发布 | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| types: [opened, synchronize, reopened, closed] | |
| 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: | |
| if: github.event_name != 'pull_request' || github.event.action != 'closed' | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 25 | |
| env: | |
| # 学习站的代码在私有仓库,用只读的部署密钥检出;别人提的 PR 拿不到密钥,只构建笔记部分 | |
| HAS_LEARN: ${{ secrets.LEARN_DEPLOY_KEY != '' }} | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 1 | |
| ref: ${{ github.event_name == 'pull_request' && github.ref || 'master' }} | |
| persist-credentials: false | |
| - name: 检出学习站 | |
| if: env.HAS_LEARN == 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| repository: CyC2018/CS-Notes-learn | |
| path: learn | |
| fetch-depth: 1 | |
| ssh-key: ${{ secrets.LEARN_DEPLOY_KEY }} | |
| 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: hashFiles('learn/build.py') != '' | |
| run: | | |
| node learn/tests/core.test.cjs website/dist/learn/data.json | |
| python learn/tests/test_content.py | |
| - name: 检查学习站的内容对照 | |
| # 只提醒不阻塞:路线改了但没有运行 learn/maintain.py --write 时,读者的记录仍然保留,只是更新记录没有日期 | |
| if: hashFiles('learn/build.py') != '' | |
| continue-on-error: true | |
| run: python learn/maintain.py | |
| - 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: | | |
| # 发布会覆盖整站:没有带上学习站时停止,避免 /learn/ 被撤下 | |
| test -f website/dist/learn/index.html || { echo '::error::没有检出学习站(检查 LEARN_DEPLOY_KEY),停止发布'; exit 1; } | |
| 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 |