From 672845038addc674a237146bea207256d3df8862 Mon Sep 17 00:00:00 2001 From: huangzheng Date: Tue, 17 Nov 2026 18:05:56 +0800 Subject: [PATCH] ci: add GitHub Pages preview workflow --- .github/workflows/deploy-pages.yml | 67 ++++++++++++++++++++++++++++++ README.md | 11 +++++ 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/deploy-pages.yml diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml new file mode 100644 index 0000000..73d24d8 --- /dev/null +++ b/.github/workflows/deploy-pages.yml @@ -0,0 +1,67 @@ +name: Test and preview PulseZone + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: pages + cancel-in-progress: true + +jobs: + test: + name: Test static site + runs-on: ubuntu-latest + steps: + - name: Check out source + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + - name: Run tests + run: npm test + - name: Check JavaScript syntax + run: | + node --check app.js + node --check calculations.mjs + - name: Prepare preview artifact + uses: actions/upload-artifact@v4 + with: + name: pulsezone-preview-${{ github.sha }} + path: | + index.html + app.js + calculations.mjs + styles.css + README.md + if-no-files-found: error + retention-days: 14 + + deploy: + name: Deploy to GitHub Pages + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: test + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Check out source + uses: actions/checkout@v4 + - name: Configure GitHub Pages + uses: actions/configure-pages@v5 + - name: Upload site + uses: actions/upload-pages-artifact@v3 + with: + path: . + - name: Deploy site + id: deployment + uses: actions/deploy-pages@v4 diff --git a/README.md b/README.md index 6651a4e..4dee191 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,17 @@ python3 -m http.server 4173 npm test ``` +## GitHub Actions 预览与发布 + +仓库包含 GitHub Actions 工作流 `.github/workflows/deploy-pages.yml`: + +- 每次 Pull Request 和手动运行都会执行测试、语法检查,并上传一个可下载的预览构建产物; +- 合并到 `main` 后会自动发布到 GitHub Pages; +- 在 GitHub 的 **Actions** 页面打开对应运行记录,可在 **Artifacts** 下载预览文件; +- 首次发布前,在仓库 **Settings → Pages** 将发布来源设置为 **GitHub Actions**。 + +发布后,工作流运行详情页会显示 GitHub Pages 的预览地址。 + ## 说明 计算结果用于训练规划参考,不替代医生或专业教练建议。运动场景会影响训练感受、测量稳定性和目标设置,实际训练应结合设备、主观体感和专业建议校准。