Fix images display & Modify textual expression #11
Workflow file for this run
This file contains hidden or 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
| 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 | |
| - 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/ | |
| 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('## 📖 文档预览') | |
| ); | |
| 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, | |
| }); | |
| } |