Skip to content

Commit e7d877b

Browse files
committed
ci: refactor publish workflow with enhanced test package publishing
Refactor the CI/CD workflow configuration to improve test package publishing process. The old publish-test job in ci.yml has been removed and replaced with a more robust system in publish.yml that includes CI wait step, automatic version determination using git SHA, and Trusted Publishers integration for secure publishing. The workflow now supports both automatic test package publishing on push and official releases through GitHub Releases, with separate jobs for different publishing scenarios and improved version management. ci: 重构发布工作流并增强测试包发布功能 重构 CI/CD 工作流配置以改进测试包发布流程。ci.yml 中的旧 publish-test 作业已被移除,并在 publish.yml 中替换为更强大的系统,该系统包含 CI 等待步骤、使用 git SHA 自动确定版本,以及可信发布者的集成为安全发布 提供支持。 该工作流现在支持在推送时自动发布测试包和通过 GitHub Releases 进行官方发布,针对不同的发布场景有单独的作业和改进的版本管理。 Change-Id: I32febf161f4061df812ab6df9bc4df5311723451 Signed-off-by: OhYee <[email protected]>
1 parent cf1036f commit e7d877b

File tree

3 files changed

+235
-216
lines changed

3 files changed

+235
-216
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -64,97 +64,3 @@ jobs:
6464
token: ${{ secrets.CODECOV_TOKEN }}
6565
files: ./coverage/coverage-final.json
6666
fail_ci_if_error: false
67-
68-
# 自动发布测试包(所有分支 push 且测试通过时)
69-
publish-test:
70-
name: Publish Test Package
71-
runs-on: ubuntu-latest
72-
needs: [build, coverage]
73-
if: github.event_name == 'push'
74-
permissions:
75-
contents: write
76-
id-token: write
77-
steps:
78-
- name: Checkout
79-
uses: actions/checkout@v4
80-
with:
81-
fetch-depth: 0
82-
83-
- name: Setup Node.js
84-
uses: actions/setup-node@v4
85-
with:
86-
node-version: '18'
87-
registry-url: 'https://registry.npmjs.org'
88-
always-auth: true
89-
90-
- name: Determine version
91-
id: version
92-
run: |
93-
# 测试包名
94-
PACKAGE_NAME="@agentrun/sdk-test"
95-
echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
96-
97-
# 从 npm 获取当前最新版本
98-
NPM_RESPONSE=$(npm view "$PACKAGE_NAME" version 2>/dev/null || echo "")
99-
100-
if [ -z "$NPM_RESPONSE" ]; then
101-
CURRENT_VERSION="0.0.0"
102-
echo "Package not found on npm, starting from 0.0.0"
103-
else
104-
CURRENT_VERSION="$NPM_RESPONSE"
105-
echo "Latest version on npm: $CURRENT_VERSION"
106-
fi
107-
108-
# 解析版本号并递增 patch
109-
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
110-
PATCH=$((PATCH + 1))
111-
VERSION="${MAJOR}.${MINOR}.${PATCH}"
112-
113-
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
114-
echo "New version: ${VERSION}"
115-
116-
- name: Update package.json for test publish
117-
run: |
118-
VERSION="${{ steps.version.outputs.VERSION }}"
119-
PACKAGE_NAME="${{ steps.version.outputs.PACKAGE_NAME }}"
120-
121-
node -e "
122-
const fs = require('fs');
123-
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
124-
pkg.name = process.env.PACKAGE_NAME;
125-
pkg.version = process.env.VERSION;
126-
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
127-
"
128-
echo "Updated package.json:"
129-
cat package.json | head -10
130-
env:
131-
VERSION: ${{ steps.version.outputs.VERSION }}
132-
PACKAGE_NAME: ${{ steps.version.outputs.PACKAGE_NAME }}
133-
134-
- name: Clean and install dependencies
135-
run: |
136-
rm -rf node_modules package-lock.json
137-
npm install
138-
139-
- name: Build
140-
run: npm run build
141-
142-
- name: Publish test package
143-
env:
144-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
145-
run: |
146-
PACKAGE_NAME="${{ steps.version.outputs.PACKAGE_NAME }}"
147-
VERSION="${{ steps.version.outputs.VERSION }}"
148-
echo "Publishing ${PACKAGE_NAME}@${VERSION} with tag=test"
149-
npm publish --tag test --access public
150-
151-
- name: Summary
152-
run: |
153-
PACKAGE_NAME="${{ steps.version.outputs.PACKAGE_NAME }}"
154-
VERSION="${{ steps.version.outputs.VERSION }}"
155-
echo "## 🧪 Test Package Published!" >> $GITHUB_STEP_SUMMARY
156-
echo "" >> $GITHUB_STEP_SUMMARY
157-
echo "- **Package:** ${PACKAGE_NAME}@${VERSION}" >> $GITHUB_STEP_SUMMARY
158-
echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
159-
echo "" >> $GITHUB_STEP_SUMMARY
160-
echo "Install: \`npm install ${PACKAGE_NAME}@${VERSION}\`" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)