diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml deleted file mode 100644 index 3d2655c1..00000000 --- a/.github/workflows/alpha.yml +++ /dev/null @@ -1,116 +0,0 @@ -name: Alpha Release - -on: - push: - branches: - - test - workflow_dispatch: - -concurrency: ${{ github.workflow }}-${{ github.ref }} - -permissions: - contents: write - pull-requests: write - -jobs: - alpha: - name: Alpha Release - 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: 10 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20.x' - cache: 'pnpm' - registry-url: 'https://registry.npmjs.org/' - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Run tests - run: pnpm run test:ci - - - name: Release alpha version - run: | - # 确保在正确的分支 - git checkout test - - # 获取当前时间戳和短commit hash - TIMESTAMP=$(date +%Y%m%d%H%M%S) - SHORT_COMMIT=$(git rev-parse --short HEAD) - - # 读取当前版本,移除任何现有的预发布标识 - CURRENT_VERSION=$(node -p "require('./package.json').version.split('-')[0]") - - # 生成唯一的alpha版本号:base-alpha.timestamp.commit - ALPHA_VERSION="${CURRENT_VERSION}-alpha.${TIMESTAMP}.${SHORT_COMMIT}" - - echo "生成alpha版本号: $ALPHA_VERSION" - - # 直接设置版本号 - npm version $ALPHA_VERSION --no-git-tag-version - - # 使用pnpm发布alpha版本 - pnpm publish --tag alpha --no-git-checks - - # 输出版本信息供后续步骤使用 - echo "ALPHA_VERSION=$ALPHA_VERSION" >> $GITHUB_ENV - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.ORG_NPM_TOKEN }} - NODE_AUTH_TOKEN: ${{ secrets.ORG_NPM_TOKEN }} - - - name: Comment on related PRs - if: success() - uses: actions/github-script@v7 - with: - script: | - const { execSync } = require('child_process'); - - // 获取alpha版本号 - const version = process.env.ALPHA_VERSION; - - // 查找相关的PR - const { data: prs } = await github.rest.pulls.list({ - owner: context.repo.owner, - repo: context.repo.repo, - state: 'open', - base: 'test' - }); - - const comment = `🚀 **Alpha版本已发布!** - - 📦 版本号: \`${version}\` - 🔗 安装命令: \`npx dpml-prompt@${version} \` - 或者: \`npx dpml-prompt@alpha \` - - 📚 使用示例: - \`\`\`bash - npx dpml-prompt@${version} hello - npx dpml-prompt@${version} init - npx dpml-prompt@${version} action - \`\`\` - - 💡 你可以使用这个alpha版本测试最新的test分支功能。 - - 🧪 **Alpha定位**: 精选功能测试版本,适合功能验证和用户测试。`; - - // 为每个相关PR添加评论 - for (const pr of prs) { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pr.number, - body: comment - }); - } \ No newline at end of file diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index d19f55c8..d6bdbd1f 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -4,9 +4,6 @@ on: push: branches: - test - paths: - - 'package.json' - - 'CHANGELOG.md' permissions: contents: write @@ -16,10 +13,6 @@ jobs: release-alpha: name: Release Alpha Version runs-on: ubuntu-latest - # 只在版本号变更时运行 - if: | - contains(github.event.head_commit.message, 'chore: release') || - contains(github.event.head_commit.message, 'chore(release)') steps: - name: Checkout repository @@ -54,8 +47,21 @@ jobs: - name: Publish alpha version run: | - # 发布为alpha版本 - npm version ${{ env.PACKAGE_VERSION }}-alpha.0 --no-git-tag-version + # 检查是否已存在alpha版本 + EXISTING_ALPHA=$(npm view dpml-prompt versions --json | jq -r '.[]' | grep "^${{ env.PACKAGE_VERSION }}-alpha" | sort -V | tail -1 || echo "") + + if [ -z "$EXISTING_ALPHA" ]; then + # 第一个alpha版本 + ALPHA_VERSION="${{ env.PACKAGE_VERSION }}-alpha.0" + else + # 提取现有版本号并递增 + CURRENT_NUM=$(echo $EXISTING_ALPHA | sed -E 's/.*-alpha\.([0-9]+)$/\1/') + NEXT_NUM=$((CURRENT_NUM + 1)) + ALPHA_VERSION="${{ env.PACKAGE_VERSION }}-alpha.$NEXT_NUM" + fi + + echo "Publishing alpha version: $ALPHA_VERSION" + npm version $ALPHA_VERSION --no-git-tag-version npm publish --tag alpha --access public env: NODE_AUTH_TOKEN: ${{ secrets.ORG_NPM_TOKEN }}