Skip to content
name: Preview PR Build
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
preview_url: ${{ steps.deploy.outputs.url }}
steps:
- name: 检出主仓库代码
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
submodules: true
- name: 检出 PR 修改的部分
run: |
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge
git checkout -qf FETCH_HEAD
# - name: 配置 baseURL
# run: |
# sed -i 's|baseURL = "https://mtf.wiki/"|baseURL = "/"|' config/_default/config.toml
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install npm dependencies
run: npm install
- name: Set up Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: latest
extended: true
- name: Build site
run: hugo --minify --enableGitInfo --baseURL "/"
- name: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT }}
command: pages deploy docs/.vitepress/dist --project-name=blog
# 获取预览链接并发送到PR
comment_on_pr:
needs: deploy
uses: project-trans/actions/.github/workflows/comment-pr-preview-link.yml@main
secrets: inherit
with:
previewUrl: ${{ needs.deploy.outputs.preview_url }}