feat: 修正发布报错问题 #10
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: Deploy to GitHub Pages | |
| on: | |
| push: | |
| branches: [main] | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| # Sets permissions of the GITHUB_TOKEN to allow pushing to gh-pages branch | |
| permissions: | |
| contents: write | |
| env: | |
| MDBOOK_VERSION: 0.5.2 | |
| MDBOOK_TYPST_PDF_VERSION: 0.7.0 | |
| TYPST_VERSION: 0.12.0 | |
| jobs: | |
| deploy: | |
| name: Build and Deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. 安装依赖 | |
| - uses: actions/checkout@v4 | |
| - name: Cache cargo registry | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cargo/registry | |
| key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Cache cargo index | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cargo/git | |
| key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Cache cargo build | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cargo/bin | |
| key: ${{ runner.os }}-cargo-bin-mdbook-typst-pdf-${{ env.MDBOOK_TYPST_PDF_VERSION }} | |
| - name: Install Rust | |
| run: | | |
| rustup set profile minimal | |
| rustup toolchain install 1.90 -c rust-docs | |
| rustup default 1.90 | |
| - name: Install mdbook | |
| run: | | |
| mkdir bin | |
| curl -sSL https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin | |
| echo "$(pwd)/bin" >> "${GITHUB_PATH}" | |
| - name: Install typst | |
| run: | | |
| curl -sSL https://github.com/typst/typst/releases/download/v${TYPST_VERSION}/typst-x86_64-unknown-linux-musl.tar.xz | tar -xJ --directory=bin --strip-components=1 | |
| echo "$(pwd)/bin" >> "${GITHUB_PATH}" | |
| - name: Install mdbook-typst-pdf | |
| run: | | |
| if ! command -v mdbook-typst-pdf &> /dev/null; then | |
| cargo install mdbook-typst-pdf --version ${MDBOOK_TYPST_PDF_VERSION} | |
| else | |
| echo "mdbook-typst-pdf already installed (from cache)" | |
| fi | |
| # 2. 编译 | |
| - name: Build book | |
| run: mdbook build | |
| # 2.5. 复制 PDF 到 HTML 目录 | |
| - name: Copy PDF to HTML directory | |
| run: | | |
| mkdir -p book/html/pdf | |
| cp book/typst-pdf/*.pdf book/html/pdf/ || echo "No PDF files found" | |
| # 3. 上传产物到 gh-pages | |
| - name: Deploy to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./book/html | |
| publish_branch: gh-pages | |
| force_orphan: true |