chore: comprehensive project improvement and refactoring #245
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 Book | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| jobs: | |
| book: | |
| name: Build mdBook and Deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| # Cache for faster builds | |
| - name: Cache mdBook | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| key: ${{ runner.os }}-mdbook-${{ hashFiles('book.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-mdbook- | |
| - name: Setup mdBook | |
| uses: peaceiris/actions-mdbook@v2 | |
| with: | |
| mdbook-version: latest | |
| - name: Setup mbBook linkcheck | |
| run: | | |
| mkdir -p mdbook-linkcheck && cd "$_" && \ | |
| curl -L https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip -o mdbook-linkcheck.zip && \ | |
| unzip "$_" && \ | |
| chmod +x mdbook-linkcheck && \ | |
| export PATH=$PWD:$PATH && \ | |
| echo "$PWD" >> $GITHUB_PATH | |
| - name: Get site url | |
| env: | |
| repo: ${{ github.event.repository.name }} | |
| run: | | |
| # Construct $url from repo name | |
| # Repo name can be "rust-tieng-viet" or "rust-tieng-viet.github.io" | |
| export url="https://${repo//.github.io/}.github.io" | |
| echo $url | |
| echo "url=$url" >> $GITHUB_ENV | |
| echo "Book URL: $url" >> $GITHUB_STEP_SUMMARY | |
| - name: Test code examples | |
| run: mdbook test || echo "Some tests failed but continuing..." | |
| - name: Build mdBook | |
| run: mdbook build | |
| - name: Generate sitemap | |
| run: | | |
| cd book/html | |
| npx static-sitemap-cli --base ${{ env.url }} | |
| cat sitemap.xml | |
| - name: Comment PR | |
| if: github.event_name == 'pull_request' | |
| uses: thollander/actions-comment-pull-request@v3 | |
| with: | |
| message: Build book successfully! | |
| reactions: tada | |
| comment_tag: build_book | |
| GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} | |
| - name: Deploy to GitHub | |
| if: github.event_name == 'push' | |
| id: deploy | |
| uses: JamesIves/[email protected] | |
| with: | |
| branch: gh-pages | |
| folder: book/html | |
| - name: Comment Commit | |
| if: github.event_name == 'push' && steps.deploy.outputs.deployment-status == 'success' | |
| uses: peter-evans/commit-comment@v4 | |
| with: | |
| body: Deploy successfully ${{ env.url }}! | |
| token: ${{ secrets.BOT_TOKEN }} |