chore: release v0.0.1 #1
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: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: '发布版本 (例如: 1.0.0)' | |
| required: true | |
| type: string | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 设置 Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: 安装 pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| - name: 获取 pnpm store 目录 | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
| - name: 设置 pnpm 缓存 | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| - name: 安装依赖 | |
| run: | | |
| # 尝试使用 frozen lockfile,如果失败则更新 lockfile | |
| pnpm install --frozen-lockfile || { | |
| echo "⚠️ Lockfile 不匹配,正在更新..." | |
| pnpm install --no-frozen-lockfile | |
| } | |
| - name: 格式检查 | |
| run: pnpm run lint | |
| - name: 构建项目 | |
| run: pnpm run build | |
| - name: 获取版本号 | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
| echo "tag_name=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: 更新版本号 (手动触发时) | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add package.json | |
| git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}" | |
| git tag ${{ steps.get_version.outputs.tag_name }} | |
| git push origin HEAD:${{ github.ref_name }} | |
| git push origin ${{ steps.get_version.outputs.tag_name }} | |
| - name: 生成变更日志 | |
| id: changelog | |
| run: | | |
| # 获取上一个标签 | |
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$PREV_TAG" ]; then | |
| # 如果没有上一个标签,获取所有提交 | |
| CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges) | |
| else | |
| # 获取两个标签之间的提交 | |
| CHANGELOG=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| fi | |
| # 保存到文件以避免特殊字符问题 | |
| echo "$CHANGELOG" > changelog.txt | |
| echo "changelog_file=changelog.txt" >> $GITHUB_OUTPUT | |
| - name: 发布到 npm | |
| run: pnpm publish --no-git-checks | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: 创建 GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.tag_name }} | |
| release_name: Release ${{ steps.get_version.outputs.tag_name }} | |
| body_path: ${{ steps.changelog.outputs.changelog_file }} | |
| draft: false | |
| prerelease: false | |
| - name: 通知发布成功 | |
| run: | | |
| echo "🎉 发布成功!" | |
| echo "📦 版本: ${{ steps.get_version.outputs.version }}" | |
| echo "🏷️ 标签: ${{ steps.get_version.outputs.tag_name }}" | |
| echo "📝 npm: https://www.npmjs.com/package/@winner-fed/plugin-check-syntax" |