refactor: 重构课程结构,完善内容和配置 #1
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 Courses to GitHub Pages | |
| on: | |
| push: | |
| branches: [main, master] | |
| pull_request: | |
| branches: [main, master] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| env: | |
| RENV_PATHS_ROOT: ~/.local/share/renv | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Quarto | |
| uses: quarto-dev/quarto-actions/setup@v2 | |
| with: | |
| version: '1.4' | |
| - name: Setup R | |
| uses: r-lib/actions/setup-r@v2 | |
| with: | |
| r-version: '4.3.0' | |
| use-public-rspm: true | |
| - name: Cache R packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ env.RENV_PATHS_ROOT }} | |
| key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-renv- | |
| - name: Install R dependencies | |
| run: | | |
| install.packages(c( | |
| "rmarkdown", | |
| "knitr", | |
| "ggplot2", | |
| "dplyr", | |
| "tidyr", | |
| "readr", | |
| "DT", | |
| "reticulate" | |
| )) | |
| shell: Rscript {0} | |
| - name: Render root website | |
| run: | | |
| echo "Rendering root website..." | |
| quarto render index.qmd | |
| - name: Render courses | |
| run: | | |
| # 查找所有课程目录(包含_quarto.yml的子目录) | |
| for course in r-and-rmarkdown; do | |
| if [ -d "$course" ] && [ -f "$course/_quarto.yml" ]; then | |
| echo "Rendering course: $course" | |
| cd "$course" | |
| quarto render | |
| cd .. | |
| fi | |
| done | |
| - name: Organize build output | |
| run: | | |
| # 创建统一的_site目录 | |
| mkdir -p _site | |
| # 复制根目录构建结果 | |
| if [ -f "index.html" ]; then | |
| cp index.html _site/ | |
| fi | |
| # 复制根目录其他文件 | |
| for file in license.html resources.html syllabus.html robots.txt sitemap.xml search.json; do | |
| if [ -f "$file" ]; then | |
| cp "$file" _site/ | |
| fi | |
| done | |
| # 复制样式和库 | |
| if [ -d "site_libs" ]; then | |
| cp -r site_libs _site/ | |
| fi | |
| if [ -d "styles" ]; then | |
| cp -r styles _site/ | |
| fi | |
| if [ -d "logo" ]; then | |
| cp -r logo _site/ | |
| fi | |
| # 复制各课程构建结果 | |
| for course in r-and-rmarkdown; do | |
| if [ -d "$course/_site" ]; then | |
| echo "Copying $course to _site/" | |
| mkdir -p "_site/$course" | |
| cp -r "$course/_site"/* "_site/$course/" | |
| # 确保logo在课程目录中 | |
| if [ -f "logo/csu_logo.png" ]; then | |
| cp "logo/csu_logo.png" "_site/$course/" | |
| fi | |
| fi | |
| done | |
| echo "Build complete. Site structure:" | |
| ls -la _site/ | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./_site | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |