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: Generate Git History JSON | |
| on: | |
| push: | |
| branches: | |
| - main | |
| # 终极优化 1:源头拦截。当只有这两个 JSON 文件变动时,直接不触发 Workflow。 | |
| paths-ignore: | |
| - 'src/json/build-info.json' | |
| - 'src/json/git-history.json' | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| # Principle of Least Privilege | |
| permissions: | |
| contents: write | |
| actions: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'pnpm' | |
| - name: Install Dependencies | |
| # 跳过依赖包的生命周期脚本,提升安装速度并增强安全性 | |
| run: pnpm install --frozen-lockfile --ignore-scripts | |
| - name: Generate Git History Data | |
| run: pnpm run git | |
| - name: Commit and Push Updated JSON Files | |
| run: | | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add src/json/build-info.json src/json/git-history.json | |
| if ! git diff --staged --quiet; then | |
| # 因为有了 paths-ignore,这里可以去掉 [skip ci],保持 commit 记录干净 | |
| git commit -m "chore(git-info): auto-update git history JSON data" | |
| # 5:推送前 Rebase,解决极限并发导致的 Push 失败 | |
| git pull --rebase origin main | |
| git push | |
| else | |
| echo "No changes detected, skipping commit." | |
| fi |