chore: 更新版本v1.3.5 #79
Workflow file for this run
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: Build and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # 当推送以v开头的标签时触发,例如v1.0.0 | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release_id: ${{ steps.create-release.outputs.id }} | |
| upload_url: ${{ steps.create-release.outputs.upload_url }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # 获取完整历史记录用于生成changelog | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 20 | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Generate Changelog | |
| id: changelog | |
| run: | | |
| # 获取最新的标签 | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0") | |
| PREVIOUS_TAG=$(git describe --tags --abbrev=0 "$LATEST_TAG^" 2>/dev/null || echo "") | |
| # 使用npm脚本生成变更日志 | |
| if [ -z "$PREVIOUS_TAG" ]; then | |
| # 首次生成(包含所有历史) | |
| npm run changelog:first | |
| else | |
| # 增量更新 | |
| npm run changelog | |
| fi | |
| # 读取生成的变更日志内容供后续步骤使用 | |
| CHANGELOG_CONTENT=$(cat CHANGELOG.md) | |
| echo "CHANGELOG_CONTENT<<EOF" >> $GITHUB_ENV | |
| echo "$CHANGELOG_CONTENT" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "::set-output name=changelog::$CHANGELOG_CONTENT" | |
| - name: Create Release | |
| id: create-release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| release_name: ${{ github.ref_name }} | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| draft: false | |
| prerelease: false | |
| build: | |
| needs: create-release | |
| strategy: | |
| matrix: | |
| os: [macos-latest, windows-latest] | |
| include: | |
| - os: macos-latest | |
| build_command: npm run build:mac --userconfig=.npmrc.github-actions | |
| - os: windows-latest | |
| build_command: npm run build:win --userconfig=.npmrc.github-actions | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Uninstall sharp | |
| run: npm uninstall sharp | |
| - name: Install sharp with optional dependencies | |
| run: npm install --include=optional sharp | |
| - name: Install sharp for macOS | |
| if: matrix.os == 'macos-latest' | |
| run: npm install --os=darwin --cpu=x64 sharp | |
| - name: Install sharp for Windows | |
| if: matrix.os == 'windows-latest' | |
| run: npm install --os=win32 sharp | |
| - name: Build application | |
| run: ${{ matrix.build_command }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # 添加这个新步骤,在上传前删除 .blockmap 文件 | |
| - name: Check blockmap files (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| echo "检查 .blockmap 文件数量:" | |
| find dist -name "*.blockmap" | wc -l | |
| - name: Remove blockmap files (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| find dist -name "*.blockmap" -type f -delete | |
| echo "已删除所有 .blockmap 文件" | |
| - name: Check blockmap files (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| $count = (Get-ChildItem -Path dist -Filter "*.blockmap" -Recurse).Count | |
| echo "还有 $count 个 .blockmap 文件" | |
| - name: Remove blockmap files (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| Get-ChildItem -Path dist -Filter "*.blockmap" -Recurse | Remove-Item -Force | |
| echo "已删除所有 .blockmap 文件" | |
| # 添加验证步骤 | |
| - name: Verify deletion (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| remaining=$(find dist -name "*.blockmap" | wc -l) | |
| echo "删除后剩余 .blockmap 文件数量:$remaining" | |
| if [ "$remaining" -gt 0 ]; then | |
| echo "警告:仍有 .blockmap 文件未被删除" | |
| find dist -name "*.blockmap" | |
| fi | |
| - name: Verify deletion (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| $remaining = (Get-ChildItem -Path dist -Filter "*.blockmap" -Recurse).Count | |
| echo "删除后剩余 .blockmap 文件数量:$remaining" | |
| if ($remaining -gt 0) { | |
| echo "警告:仍有 .blockmap 文件未被删除" | |
| Get-ChildItem -Path dist -Filter "*.blockmap" -Recurse | ForEach-Object { echo $_.FullName } | |
| } | |
| # 添加强制删除步骤,确保所有 .blockmap 文件都被删除 | |
| - name: Force remove blockmap files (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| rm -f dist/*.blockmap | |
| rm -f dist/**/*.blockmap | |
| echo "已强制删除所有 .blockmap 文件" | |
| - name: Force remove blockmap files (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| if (Test-Path dist/*.blockmap) { Remove-Item -Path dist/*.blockmap -Force } | |
| Get-ChildItem -Path dist -Recurse -Filter "*.blockmap" | Remove-Item -Force | |
| echo "已强制删除所有 .blockmap 文件" | |
| # 修改这个步骤,为不同操作系统使用不同的命令 | |
| - name: List files before upload (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| echo "上传前检查文件列表:" | |
| ls -la dist/ | |
| - name: List files before upload (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| echo "上传前检查文件列表:" | |
| Get-ChildItem -Path dist/ -Force | |
| - name: Upload artifacts to release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| dist/*.exe | |
| dist/*.dmg | |
| dist/latest*.yml | |
| !dist/builder-debug.yml | |
| !dist/**/*.blockmap | |
| tag_name: ${{ github.ref_name }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # 添加新步骤,使用 GitHub API 删除 .blockmap 文件 | |
| - name: Delete blockmap assets from release | |
| if: matrix.os == 'macos-latest' # 只在一个作业中执行,避免冲突 | |
| run: | | |
| TOKEN="${{ secrets.GITHUB_TOKEN }}" | |
| REPO="${{ github.repository }}" | |
| TAG="${{ github.ref_name }}" | |
| echo "开始清理 GitHub Release 中的 .blockmap 文件..." | |
| # 安装 jq 用于解析 JSON | |
| if [ "$(uname)" == "Darwin" ]; then | |
| brew install jq | |
| elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
| sudo apt-get update && sudo apt-get install -y jq | |
| fi | |
| # 获取 Release ID | |
| echo "获取 Release ID..." | |
| RELEASE_ID=$(curl -s -H "Authorization: token $TOKEN" \ | |
| "https://api.github.com/repos/$REPO/releases/tags/$TAG" | \ | |
| jq -r '.id') | |
| if [ "$RELEASE_ID" == "null" ]; then | |
| echo "无法获取 Release ID,可能是 Release 尚未创建或权限不足" | |
| exit 0 | |
| fi | |
| echo "找到 Release ID: $RELEASE_ID" | |
| # 获取所有资产 | |
| echo "获取所有资产..." | |
| ASSETS=$(curl -s -H "Authorization: token $TOKEN" \ | |
| "https://api.github.com/repos/$REPO/releases/$RELEASE_ID/assets") | |
| # 删除 blockmap 文件 | |
| echo "查找并删除 .blockmap 文件..." | |
| echo "$ASSETS" | jq -r '.[] | select(.name | endswith(".blockmap")) | .id' | \ | |
| while read asset_id; do | |
| if [ -n "$asset_id" ]; then | |
| echo "删除资产 ID: $asset_id" | |
| curl -X DELETE -H "Authorization: token $TOKEN" \ | |
| "https://api.github.com/repos/$REPO/releases/assets/$asset_id" | |
| echo "已删除一个 .blockmap 文件" | |
| fi | |
| done | |
| echo "清理完成" |