diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 419863d1..f2562ded 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -9,63 +9,64 @@ on: paths: ['docs/**'] jobs: - checks: - if: github.event_name != 'push' + pull-request-check: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v3 with: - node-version: '17.x' + node-version: 18 + - name: Test Build working-directory: ./docs - env: - NODE_OPTIONS: --openssl-legacy-provider run: | - if [ -e yarn.lock ]; then - yarn install --frozen-lockfile - elif [ -e package-lock.json ]; then npm ci - else - npm i - fi npm run build - gh-release: - if: github.event_name != 'pull_request' + + gh-pages-release: + if: github.event_name == 'push' runs-on: ubuntu-latest + permissions: + contents: write steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 with: - node-version: '17.x' - - name: Add key to allow access to repository - env: - SSH_AUTH_SOCK: /tmp/ssh_agent.sock - NODE_OPTIONS: --openssl-legacy-provider + path: master + + - uses: actions/checkout@v4 + with: + ref: gh-pages + path: gh-pages + + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Build docusaurus + working-directory: master/docs + id: build run: | - mkdir -p ~/.ssh - ssh-keyscan github.com >> ~/.ssh/known_hosts - echo "${{ secrets.GH_PAGES_DEPLOY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - cat <> ~/.ssh/config - Host github.com - HostName github.com - IdentityFile ~/.ssh/id_rsa - EOT - - name: Release to GitHub Pages - working-directory: ./docs - env: - USE_SSH: true - GIT_USER: git - NODE_OPTIONS: --openssl-legacy-provider - run: | - git config --global user.email "actions@gihub.com" - git config --global user.name "gh-actions" - if [ -e yarn.lock ]; then - yarn install --frozen-lockfile - elif [ -e package-lock.json ]; then + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT npm ci - else - npm i - fi - npx docusaurus deploy + npm run build + + - name: Release to github pages + env: + GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} + working-directory: gh-pages + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + + # Remove all files except .git + git rm -r * + + # Copy the build files from master/docs/build to gh-pages + cp -r ../master/docs/build/* . + + # Commit and push + git add . + git commit -m "Update documentation based on ${{ steps.build.outputs.sha }}" + git push origin gh-pages diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index aec81054..ef1718ee 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -54,4 +54,13 @@ module.exports = { }, ], ], + themes: [ + [ + require.resolve("@easyops-cn/docusaurus-search-local"), + /** @type {import("@easyops-cn/docusaurus-search-local").PluginOptions} */ + ({ + hashed: true, + }), + ], + ], }; diff --git a/docs/package.json b/docs/package.json index 6e4ab5f3..0210a1aa 100644 --- a/docs/package.json +++ b/docs/package.json @@ -13,6 +13,7 @@ "dependencies": { "@docusaurus/core": "^2.0.0-beta.15", "@docusaurus/preset-classic": "^2.0.0-beta.15", + "@easyops-cn/docusaurus-search-local": "^0.29.0", "@mdx-js/react": "^1.6.22", "clsx": "^1.1.1", "react": "^16.14.0",