From 271a14778f94b4955f3487497c4029c2e8990178 Mon Sep 17 00:00:00 2001 From: wuxh Date: Thu, 12 Jan 2023 16:55:22 +0800 Subject: [PATCH 1/2] ci: add docs deploy workflow --- .dumirc.ts | 5 ++ .github/workflows/react-component-ci.yml | 10 ++-- .github/workflows/site-deploy.yml | 73 ++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/site-deploy.yml diff --git a/.dumirc.ts b/.dumirc.ts index d24799e..ff078b3 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -2,6 +2,9 @@ import { defineConfig } from 'dumi'; import path from 'path'; +const basePath = process.env.GITHUB_ACTIONS ? '/collapse/' : '/'; +const publicPath = process.env.GITHUB_ACTIONS ? '/collapse/' : '/'; + export default defineConfig({ alias: { 'rc-collapse$': path.resolve('src'), @@ -14,4 +17,6 @@ export default defineConfig({ }, outputPath: '.doc', exportStatic: {}, + base: basePath, + publicPath, }); diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 432a3fb..5ffd207 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -46,6 +46,7 @@ jobs: lint: runs-on: ubuntu-latest + needs: setup steps: - name: checkout uses: actions/checkout@master @@ -65,10 +66,10 @@ jobs: - name: lint run: npm run lint - needs: setup compile: runs-on: ubuntu-latest + needs: setup steps: - name: checkout uses: actions/checkout@master @@ -87,11 +88,10 @@ jobs: - name: compile run: npm run compile - - needs: setup coverage: runs-on: ubuntu-latest + needs: setup steps: - name: checkout uses: actions/checkout@master @@ -109,6 +109,4 @@ jobs: key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - name: coverage - run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash) - - needs: setup + run: npm run coverage && bash <(curl -s https://codecov.io/bash) diff --git a/.github/workflows/site-deploy.yml b/.github/workflows/site-deploy.yml new file mode 100644 index 0000000..2659c02 --- /dev/null +++ b/.github/workflows/site-deploy.yml @@ -0,0 +1,73 @@ +name: Deploy website +on: + push: + branches: + - master + workflow_dispatch: + +permissions: + contents: write + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: cache package-lock.json + uses: actions/cache@v3 + with: + path: package-temp-dir + key: lock-${{ github.sha }} + + - name: create package-lock.json + run: npm i --package-lock-only --ignore-scripts + + - name: hack for single file + run: | + if [ ! -d "package-temp-dir" ]; then + mkdir package-temp-dir + fi + cp package-lock.json package-temp-dir + - name: cache node_modules + id: node_modules_cache_id + uses: actions/cache@v3 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} + + - name: install + if: steps.node_modules_cache_id.outputs.cache-hit != 'true' + run: npm ci + + build-and-deploy: + runs-on: ubuntu-latest + needs: setup + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: restore cache from package-lock.json + uses: actions/cache@v3 + with: + path: package-temp-dir + key: lock-${{ github.sha }} + + - name: restore cache from node_modules + uses: actions/cache@v3 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} + + - name: build Docs + run: npm run build + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./.doc + force_orphan: true + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' From afe1dcff47bfa5371ecdb97eb096ab3769dea473 Mon Sep 17 00:00:00 2001 From: wuxh Date: Thu, 12 Jan 2023 17:59:57 +0800 Subject: [PATCH 2/2] update trigger event --- .github/workflows/site-deploy.yml | 48 +++++-------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/.github/workflows/site-deploy.yml b/.github/workflows/site-deploy.yml index 2659c02..19eaa7b 100644 --- a/.github/workflows/site-deploy.yml +++ b/.github/workflows/site-deploy.yml @@ -1,65 +1,31 @@ name: Deploy website on: push: - branches: - - master + tags: + - '*' workflow_dispatch: permissions: contents: write jobs: - setup: + build-and-deploy: runs-on: ubuntu-latest steps: - name: checkout uses: actions/checkout@v3 - - name: cache package-lock.json - uses: actions/cache@v3 + - name: setup node + uses: actions/setup-node@v1 with: - path: package-temp-dir - key: lock-${{ github.sha }} + node-version: 14 - name: create package-lock.json run: npm i --package-lock-only --ignore-scripts - - name: hack for single file - run: | - if [ ! -d "package-temp-dir" ]; then - mkdir package-temp-dir - fi - cp package-lock.json package-temp-dir - - name: cache node_modules - id: node_modules_cache_id - uses: actions/cache@v3 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: install - if: steps.node_modules_cache_id.outputs.cache-hit != 'true' + - name: Install dependencies run: npm ci - build-and-deploy: - runs-on: ubuntu-latest - needs: setup - steps: - - name: checkout - uses: actions/checkout@v3 - - - name: restore cache from package-lock.json - uses: actions/cache@v3 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: restore cache from node_modules - uses: actions/cache@v3 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - name: build Docs run: npm run build