Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 17 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,41 @@ permissions:
id-token: write
pages: write

env:
INSTANCE: 'Writerside/xd'
ARTIFACT: 'webHelpXD2-all.zip'
DOCKER_VERSION: '241.18775'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Comment thread
PythonSmall-Q marked this conversation as resolved.
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build docs using Writerside Docker builder
uses: JetBrains/writerside-github-action@v4
with:
instance: ${{ env.INSTANCE }}
artifact: ${{ env.ARTIFACT }}
docker-version: ${{ env.DOCKER_VERSION }}

- name: Save artifact with build results
uses: actions/upload-artifact@v4
with:
name: docs
path: |
artifacts/${{ env.ARTIFACT }}
artifacts/report.json
retention-days: 7
test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
name: docs
path: artifacts
node-version: 20
cache: npm

- name: Test documentation
uses: JetBrains/writerside-checker-action@v1
with:
instance: ${{ env.INSTANCE }}
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: docs
- name: Install dependencies
run: npm ci

- name: Unzip artifact
run: unzip -O UTF-8 -qq '${{ env.ARTIFACT }}' -d dir
- name: Build docs
run: npm run docs:build
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Package and upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: dir
path: .vitepress/dist

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

29 changes: 29 additions & 0 deletions .github/workflows/preview-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR preview cleanup

on:
pull_request:
types: [closed]

permissions:
contents: read

jobs:
cleanup:
name: Delete FTP preview
runs-on: ubuntu-latest
steps:
- name: Install lftp
run: sudo apt-get install -y lftp
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Remove preview directory from FTP
env:
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
lftp -c "
set ftp:ssl-allow no;
Comment thread
PythonSmall-Q marked this conversation as resolved.
open -u $FTP_USERNAME,$FTP_PASSWORD ftpupload.net;
rm -rf htdocs/pr-$PR_NUMBER/;
bye
"
83 changes: 83 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: PR preview

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: read
pull-requests: write

jobs:
preview:
name: Build & deploy preview
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Build docs
run: npm run docs:build -- --base /pr-${{ github.event.pull_request.number }}/

- name: Deploy to FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ftpupload.net
port: 21
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: .vitepress/dist/
Comment thread
PythonSmall-Q marked this conversation as resolved.
server-dir: htdocs/pr-${{ github.event.pull_request.number }}/

- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `http://xmoj-docs.infinityfreeapp.com/pr-${prNumber}/`;
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = [
'## 📖 文档预览',
'',
`构建成功!点击下方链接在线预览文档(PR 关闭后自动删除)。`,
'',
`**[🔗 在线预览](${previewUrl})**`,
'',
`> 预览地址:\`${previewUrl}\``,
`> 构建运行:[#${context.runNumber}](${runUrl})`,
].join('\n');

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(
c => c.user.type === 'Bot' && c.body.includes('## 📖 文档预览')
);
Comment thread
PythonSmall-Q marked this conversation as resolved.

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test build

on:
push:
branches-ignore:
- master
pull_request:

permissions:
contents: read

jobs:
build:
name: Build docs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Build docs
run: npm run docs:build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vitepress/dist
.vitepress/cache
Loading
Loading