name: Publish Release on: push: branches: - main # 在同一个工作流中处理发布任务 concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: contents: write issues: write pull-requests: write jobs: publish: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Configure Git to use HTTPS instead of SSH run: | git config --global url."https://github.com/".insteadOf git@github.com: git config --global url."https://".insteadOf git:// - name: Setup pnpm uses: pnpm/action-setup@v4 with: version: 9 run_install: | - recursive: true args: [--frozen-lockfile=false] - name: Get pnpm store directory id: pnpm-cache run: | echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT - name: Setup pnpm cache uses: actions/cache@v4 with: path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-store- - name: Install dependencies run: pnpm install --no-frozen-lockfile env: NPM_CONFIG_LEGACY_PEER_DEPS: true - name: Setup Git user run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - name: Bump version and generate changelog run: | # 根据 commit 信息自动更新版本和生成 changelog pnpm release # 获取新版本号 VERSION=$(node -p "require('./package.json').version") echo "VERSION=$VERSION" >> $GITHUB_ENV - name: Push changes run: | git push origin main git push origin v${{ env.VERSION }} - name: Build for all platforms run: pnpm build:all env: # 在 macOS 上禁用代码签名 CSC_IDENTITY_AUTO_DISCOVERY: false # GitHub token 用于发布 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: v${{ env.VERSION }} name: Release v${{ env.VERSION }} body_path: CHANGELOG.md draft: false prerelease: false files: | release/${{ env.VERSION }}/* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}