|
| 1 | +name: 部署文档 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] # 确保这是你正在使用的分支名称 |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 12 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 13 | +concurrency: |
| 14 | + group: "pages" |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + deploy-gh-pages: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: 环境 - 构建库 |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 1 |
| 25 | + repository: LincZero/LincZero.github.io |
| 26 | + ref: 'main' # 分支,旧raw |
| 27 | + |
| 28 | + - name: 环境 - 安装 pnpm |
| 29 | + uses: pnpm/action-setup@v2 |
| 30 | + with: |
| 31 | + run_install: true |
| 32 | + version: 8 |
| 33 | + |
| 34 | + - name: 环境 - 设置 Node.js |
| 35 | + uses: actions/setup-node@v3 |
| 36 | + with: |
| 37 | + node-version: 20 |
| 38 | + cache: pnpm |
| 39 | + |
| 40 | + # 获取仓库的相关配置 |
| 41 | + # https://docs.github.com/zh/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables |
| 42 | + # TODO:若 “仓库无前缀名” 是.github.io结尾,则设置为"/" |
| 43 | + - name: 配置 - 获取仓库配置 |
| 44 | + id: config1 # 用于给其他步骤引用 |
| 45 | + working-directory: ./scripts/ |
| 46 | + run: | |
| 47 | + > git_config.json # 先清空 |
| 48 | + echo "{" >> git_config.json |
| 49 | + echo " \"GITHUB_WORKSPACE\": \"${GITHUB_WORKSPACE}\"," >> git_config.json # 工作路径 |
| 50 | + echo " \"GITHUB_ACTION_PATH\": \"${GITHUB_ACTION_PATH}\"," >> git_config.json # action路径 |
| 51 | + echo " \"GITHUB_ACTION_REPOSITORY\": \"${GITHUB_ACTION_REPOSITORY}\"," >> git_config.json # action仓库 |
| 52 | + echo " \"GITHUB_REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\"," >> git_config.json # 仓库所属(格式: 可以是组织) |
| 53 | + echo " \"GITHUB_ACTOR\": \"${GITHUB_ACTOR}\"," >> git_config.json # 仓库作者(格式: 不会是组织) |
| 54 | + echo " \"GITHUB_REPOSITORY\": \"${GITHUB_REPOSITORY}\"," >> git_config.json # 仓库标识(格式: 个人或组织/仓库名) |
| 55 | + echo " \"CALC_URL\": \"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/\"," >> git_config.json # 仓库url |
| 56 | + REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d"/" -f2) |
| 57 | + echo " \"CALC_REPO_NAME\": \"${REPO_NAME}\"" >> git_config.json # 仓库无前缀名 |
| 58 | + echo "}" >> git_config.json |
| 59 | + echo "::set-output name=REPO_NAME::$REPO_NAME" |
| 60 | +
|
| 61 | + # [!code] 根据实际情况修改 |
| 62 | + - name: 配置 - 设置 |
| 63 | + working-directory: ./ |
| 64 | + run: | |
| 65 | + # sed -i 's/base: \"\/\"/base: \"\/${{steps.config1.outputs.REPO_NAME}}\/\"/g' ./src/.vuepress/config.ts |
| 66 | + cat ./scripts/git_config.json |
| 67 | + rm -f ./src/.vuepress/config_cover.js |
| 68 | + rm -f ./src/.vuepress/theme_cover.js |
| 69 | + pnpm run gen-config |
| 70 | +
|
| 71 | + # 文档的克隆、构建、部署。注意 `clone --depth 1` 只拉最近一次提交,减少时间 |
| 72 | + - name: 文档 - 文档库克隆 |
| 73 | + working-directory: ./src/ |
| 74 | + run: | |
| 75 | + git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git temp_repo |
| 76 | + rsync -a temp_repo/ . |
| 77 | + rm -rf temp_repo |
| 78 | + # git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git # 如果有多个clone项则替换成这个,避免冲突 |
| 79 | +
|
| 80 | + - name: 文档 - 构建 |
| 81 | + env: |
| 82 | + NODE_OPTIONS: --max_old_space_size=20480 |
| 83 | + run: |- |
| 84 | + node -e 'console.log(v8.getHeapStatistics())' |
| 85 | + pnpm run docs:build |
| 86 | + > src/.vuepress/dist/.nojekyll |
| 87 | +
|
| 88 | + - name: 文档 - 部署 |
| 89 | + uses: JamesIves/github-pages-deploy-action@v4 |
| 90 | + with: |
| 91 | + # 这是文档部署到的分支名称 |
| 92 | + branch: gh-pages |
| 93 | + folder: src/.vuepress/dist |
0 commit comments