Fix. 删减日志输出 #9
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: Release Static Site | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 8 | |
| - name: Install Dependencies | |
| run: pnpm install | |
| - name: Build and Export | |
| run: | | |
| npx next build | |
| npx next export | |
| - name: Get Version from package.json | |
| id: get_version | |
| run: | | |
| version=v$(jq -r .version package.json) | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| - name: Check if Release Already Exists | |
| id: check_release | |
| run: | | |
| exists=$(gh release view ${{ steps.get_version.outputs.version }} --json tagName -q '.tagName' || echo "not_found") | |
| if [ "$exists" != "not_found" ]; then | |
| echo "release_exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "release_exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Exit if Release Already Exists | |
| if: steps.check_release.outputs.release_exists == 'true' | |
| run: | | |
| echo "Release already exists. Skipping..." | |
| exit 0 | |
| - name: Get Previous Tag | |
| id: prev_tag | |
| run: | | |
| # 获取所有v开头的标签,按版本排序,排除当前版本 | |
| current_version="${{ steps.get_version.outputs.version }}" | |
| tag=$(git tag -l 'v*' --sort=-version:refname | grep -v "^${current_version}$" | head -n1 || echo "none") | |
| echo "Current version: $current_version" | |
| echo "Previous tag found: $tag" | |
| echo "previous_tag=$tag" >> $GITHUB_OUTPUT | |
| - name: Generate Release Notes | |
| id: release_notes | |
| run: | | |
| if [ "${{ steps.prev_tag.outputs.previous_tag }}" != "none" ]; then | |
| echo "🔄 更新日志(${{ steps.prev_tag.outputs.previous_tag }} → ${{ steps.get_version.outputs.version }})" > release.md | |
| echo "" >> release.md | |
| echo "## 📝 变更内容" >> release.md | |
| echo "" >> release.md | |
| git log ${{ steps.prev_tag.outputs.previous_tag }}..HEAD --pretty=format:'- [%s](https://github.com/${{ github.repository }}/commit/%H) by @%an' >> release.md | |
| else | |
| echo "🔄 更新日志(首次发布 ${{ steps.get_version.outputs.version }})" > release.md | |
| echo "" >> release.md | |
| echo "## 📝 变更内容" >> release.md | |
| echo "" >> release.md | |
| echo "- 🎉 首次发布版本" >> release.md | |
| echo "- 📦 包含所有核心功能" >> release.md | |
| fi | |
| echo "Release notes generated successfully" | |
| - name: Create ZIP Archive | |
| run: | | |
| cd out | |
| zip -r ../site-${{ steps.get_version.outputs.version }}.zip ./* | |
| cd .. | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.version }} | |
| name: Release ${{ steps.get_version.outputs.version }} | |
| body_path: release.md | |
| files: site-${{ steps.get_version.outputs.version }}.zip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |