diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml new file mode 100644 index 0000000..ec65678 --- /dev/null +++ b/.github/workflows/pr-preview.yml @@ -0,0 +1,33 @@ +name: Deploy PR preview + +on: + pull_request: + types: [opened, reopened, synchronize, closed] + +concurrency: preview-${{ github.ref }} + +jobs: + deploy-preview: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install and build + if: github.event.action != 'closed' + run: | + npm install + npm run build + + - name: Deploy preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./dist + preview-branch: gh-pages + umbrella-dir: pr-preview diff --git a/README.md b/README.md index 6b6f453..5b3e40a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ 2. 在仓库设置中启用 GitHub Pages 3. 选择 GitHub Actions 作为部署源 4. 推送代码时将自动触发构建和部署 +5. 每个 PR 会自动生成预览链接,合并前即可在线查看效果 ## 📝 使用指南