Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: add workflow for previwing docs site (#4186)
Signed-off-by: Carson Yang <yangchuansheng33@gmail.com>
- Loading branch information
1 parent
bd118ed
commit b6be5be
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
name: Preview Sealos Docs Site | ||
|
||
on: | ||
pull_request_target: | ||
push: | ||
branches: ["main"] | ||
paths: | ||
- "docs/**" | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
env: | ||
BUILD_PATH: "./docs/website" | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
submodules: recursive # Fetch submodules | ||
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod | ||
- name: Copy Files and Directories | ||
run: | | ||
mkdir -p ${{ env.BUILD_PATH }}/i18n/zh-Hans/docusaurus-plugin-content-docs/ | ||
cp -r docs/4.0/i18n/zh-Hans/ ${{ env.BUILD_PATH }}/i18n/zh-Hans/docusaurus-plugin-content-docs/current/ | ||
cp docs/4.0/i18n/zh-Hans/current.json ${{ env.BUILD_PATH }}/i18n/zh-Hans/docusaurus-plugin-content-docs/current.json | ||
cp docs/4.0/code.json ${{ env.BUILD_PATH }}/i18n/zh-Hans/code.json | ||
- name: Detect package manager | ||
id: detect-package-manager | ||
run: | | ||
if [ -f "${{ env.BUILD_PATH }}/yarn.lock" ]; then | ||
echo "manager=yarn" >> $GITHUB_OUTPUT | ||
echo "command=install" >> $GITHUB_OUTPUT | ||
echo "runner=yarn" >> $GITHUB_OUTPUT | ||
exit 0 | ||
elif [ -f "${{ env.BUILD_PATH }}/package.json" ]; then | ||
echo "manager=npm" >> $GITHUB_OUTPUT | ||
echo "command=ci" >> $GITHUB_OUTPUT | ||
echo "runner=npx --no-install" >> $GITHUB_OUTPUT | ||
exit 0 | ||
else | ||
echo "Unable to determine package manager" | ||
exit 1 | ||
fi | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
cache: ${{ steps.detect-package-manager.outputs.manager }} | ||
cache-dependency-path: ${{ env.BUILD_PATH }}/yarn.lock | ||
- name: Install dependencies | ||
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} | ||
working-directory: ${{ env.BUILD_PATH }} | ||
- name: Build with Docusaurus | ||
run: ${{ steps.detect-package-manager.outputs.runner }} run build | ||
working-directory: ${{ env.BUILD_PATH }} | ||
|
||
# Push our generated site to Vercel | ||
- name: Deploy to Vercel | ||
uses: amondnet/vercel-action@v25 | ||
id: vercel-action | ||
with: | ||
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required | ||
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} #Required | ||
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} #Required | ||
github-comment: false | ||
# vercel-args: '--local-config vercel.json' # Optional | ||
working-directory: ${{ env.BUILD_PATH }}/build | ||
|
||
docsOutput: | ||
needs: [ build ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
- name: Write md | ||
run: | | ||
echo "# 🤖 Generated by deploy action" > report.md | ||
echo "[👀 Visit Preview](${{ needs.deploy-preview.outputs.url }})" >> report.md | ||
cat report.md | ||
- name: Gh Rebot for Sealos | ||
uses: labring/gh-rebot@v0.0.6 | ||
if: ${{ (github.event_name == 'pull_request_target') }} | ||
with: | ||
version: v0.0.6 | ||
env: | ||
GH_TOKEN: "${{ secrets.GH_PAT }}" | ||
SEALOS_TYPE: "pr_comment" | ||
SEALOS_FILENAME: "report.md" | ||
SEALOS_REPLACE_TAG: "DEFAULT_REPLACE_DEPLOY" |