From c196a86f732b7bab135df6ca5a1c268720db7d8f Mon Sep 17 00:00:00 2001 From: Northword Date: Sat, 7 Oct 2023 15:30:13 +0800 Subject: [PATCH] Refactor GitHub action workflows --- .../workflows/{build-on-pr.yml => build.yml} | 14 ++++-- .github/workflows/deploy-docs.yml | 44 ------------------- .github/workflows/deploy-gh-pages.yml | 27 ++++++++++++ .github/workflows/lint.yml | 5 ++- .github/workflows/main.yml | 26 +++++++++++ 5 files changed, 67 insertions(+), 49 deletions(-) rename .github/workflows/{build-on-pr.yml => build.yml} (66%) delete mode 100644 .github/workflows/deploy-docs.yml create mode 100644 .github/workflows/deploy-gh-pages.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/build-on-pr.yml b/.github/workflows/build.yml similarity index 66% rename from .github/workflows/build-on-pr.yml rename to .github/workflows/build.yml index 2f6be93a..16e8c16a 100644 --- a/.github/workflows/build-on-pr.yml +++ b/.github/workflows/build.yml @@ -1,14 +1,14 @@ -name: Build on Pull Request +name: Build on: - pull_request: + workflow_call: jobs: build: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 # 如果你文档需要 Git 子模块,取消注释下一行 @@ -28,3 +28,11 @@ jobs: NODE_OPTIONS: --max_old_space_size=8192 run: |- npm run docs:build + > src/.vuepress/dist/.nojekyll + + - name: Upload build result + uses: actions/upload-artifact@v3 + with: + name: build-result + path: | + src/.vuepress/dist diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml deleted file mode 100644 index b64e1724..00000000 --- a/.github/workflows/deploy-docs.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: 部署文档 - -on: - push: - branches: - # 确保这是你正在使用的分支名称 - - main - -permissions: - contents: write - -jobs: - deploy-gh-pages: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - # 如果你文档需要 Git 子模块,取消注释下一行 - # submodules: true - - - name: 设置 Node.js - uses: actions/setup-node@v3 - with: - node-version: 18 - # cache: npm - - - name: 安装依赖 - run: npm install - - - name: 构建文档 - env: - NODE_OPTIONS: --max_old_space_size=8192 - run: |- - npm run docs:build - > src/.vuepress/dist/.nojekyll - - - name: 部署文档 - uses: JamesIves/github-pages-deploy-action@v4 - with: - # 这是文档部署到的分支名称 - branch: gh-pages - folder: src/.vuepress/dist diff --git a/.github/workflows/deploy-gh-pages.yml b/.github/workflows/deploy-gh-pages.yml new file mode 100644 index 00000000..b0169789 --- /dev/null +++ b/.github/workflows/deploy-gh-pages.yml @@ -0,0 +1,27 @@ +name: Deploy GitHub Pages + +on: + workflow_call: + +permissions: + contents: write + +jobs: + deploy-gh-pages: + runs-on: ubuntu-latest + steps: + - name: Restore Build Result + uses: actions/download-artifact@v3 + with: + name: build-result + path: ./src/.vuepress/dist + + - name: Display structure of downloaded files + run: ls -R + + - name: Deploy + uses: JamesIves/github-pages-deploy-action@v4 + with: + # 这是文档部署到的分支名称 + branch: gh-pages + folder: src/.vuepress/dist diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f65f5707..4191c35e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,6 +1,7 @@ -name: Lint 文档 +name: Lint Markdown -on: [push, pull_request] +on: + workflow_call: jobs: lint: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..5a7eaf3d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,26 @@ +name: Main Action + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: write + +jobs: + lint: + uses: ./.github/workflows/lint.yml + + build: + uses: ./.github/workflows/build.yml + + deploy-gh-pages: + if: github.ref_name == 'main' && github.event_name == 'push' + needs: + - lint + - build + uses: ./.github/workflows/deploy-gh-pages.yml