From cde97953074521b7ae7d2737273c269b3d1d2064 Mon Sep 17 00:00:00 2001 From: windychen Date: Thu, 16 Jul 2026 14:26:25 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E5=B0=8F=E7=89=88?= =?UTF-8?q?=E6=9C=AC=201.1.7=20=E2=86=92=201.1.8=EF=BC=8CCI=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20Gitea=20=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 62 ++++++++++++++++++++++++------------- package.json | 2 +- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 77273f0..19488cf 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -7,7 +7,7 @@ on: jobs: build: if: contains(github.event.head_commit.message, 'chore') && contains(github.event.head_commit.message, '版本') && contains(github.event.head_commit.message, '更新') - runs-on: docker # 匹配你 runner 的标签 + runs-on: docker steps: - name: Checkout code run: | @@ -27,20 +27,37 @@ jobs: - name: Run build run: npm run build - - name: Publish package - id: publish + - name: Publish to Verdaccio + id: publish-verdaccio run: | VERSION=$(node -p "require('./package.json').version") HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://verdaccio:4873/windychen-utils/$VERSION) if [ "$HTTP_CODE" = "200" ]; then - echo "Version $VERSION already exists in Verdaccio, skipping publish." - echo "skipped|版本 ${VERSION} 已存在,跳过发布" > /tmp/publish_result.txt + echo "Verdaccio: version $VERSION already exists, skipping." + echo "Verdaccio|skipped|版本 ${VERSION} 已存在" > /tmp/publish_result.txt else - echo "Version $VERSION not found, publishing..." if npm publish 2>&1; then - echo "published|已发布 v${VERSION} 到 Verdaccio" > /tmp/publish_result.txt + echo "Verdaccio|published|已发布 v${VERSION}" > /tmp/publish_result.txt else - echo "failed|npm publish 失败 (v${VERSION})" > /tmp/publish_result.txt + echo "Verdaccio|failed|发布失败" > /tmp/publish_result.txt + exit 1 + fi + fi + + - name: Publish to Gitea + id: publish-gitea + run: | + npm config set //gitea:3000/api/packages/windychen/npm/:_authToken ${{ secrets.NPM_GITEA_TOKEN }} + VERSION=$(node -p "require('./package.json').version") + HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://gitea:3000/api/packages/windychen/npm/windychen-utils/$VERSION) + if [ "$HTTP_CODE" = "200" ]; then + echo "Gitea: version $VERSION already exists, skipping." + echo "Gitea|skipped|版本 ${VERSION} 已存在" >> /tmp/publish_result.txt + else + if npm publish --registry http://gitea:3000/api/packages/windychen/npm/ 2>&1; then + echo "Gitea|published|已发布 v${VERSION}" >> /tmp/publish_result.txt + else + echo "Gitea|failed|发布失败" >> /tmp/publish_result.txt exit 1 fi fi @@ -50,20 +67,23 @@ jobs: run: | STATUS="${{ job.status }}" VERSION=$(node -p "require('./package.json').version") + VERD_LINE="⚠️ Verdaccio: 未执行" + GITEA_LINE="⚠️ Gitea: 未执行" if [ -f /tmp/publish_result.txt ]; then - PUBLISH_RAW=$(cat /tmp/publish_result.txt) - PUBLISH_ICON=$(echo "$PUBLISH_RAW" | cut -d'|' -f1) - PUBLISH_DETAIL=$(echo "$PUBLISH_RAW" | cut -d'|' -f2) - else - PUBLISH_ICON="skipped" - PUBLISH_DETAIL="构建失败,未执行发布" + while IFS='|' read -r TARGET ICON DETAIL; do + case "$ICON" in + published) EMOJI="📦" ;; + skipped) EMOJI="⏭️" ;; + failed) EMOJI="❌" ;; + *) EMOJI="⚠️" ;; + esac + LINE="${EMOJI} ${TARGET}: ${DETAIL}" + case "$TARGET" in + Verdaccio) VERD_LINE="$LINE" ;; + Gitea) GITEA_LINE="$LINE" ;; + esac + done < /tmp/publish_result.txt fi - case "$PUBLISH_ICON" in - published) PUB_LINE="📦 发布: ${PUBLISH_DETAIL}" ;; - skipped) PUB_LINE="⏭️ 发布: ${PUBLISH_DETAIL}" ;; - failed) PUB_LINE="❌ 发布: ${PUBLISH_DETAIL}" ;; - *) PUB_LINE="⚠️ 发布: ${PUBLISH_DETAIL}" ;; - esac if [ "$STATUS" = "success" ]; then TITLE="✅ windychen-utils v${VERSION} 构建完成 chen-fnos" else @@ -71,4 +91,4 @@ jobs: fi curl -s -X POST "https://oapi.dingtalk.com/robot/send?access_token=${{ secrets.DINGDING_TOKEN }}" \ -H "Content-Type: application/json" \ - -d "{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"${TITLE}\",\"text\":\"## ${TITLE}\n\n${PUB_LINE}\n\n- 仓库: windychen/windyChenUtils\n- 分支: ${{ github.ref_name }}\n- 提交: ${{ github.sha }}\"}}" + -d "{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"${TITLE}\",\"text\":\"## ${TITLE}\n\n${VERD_LINE}\n${GITEA_LINE}\n\n- 仓库: windychen/windyChenUtils\n- 分支: ${{ github.ref_name }}\n- 提交: ${{ github.sha }}\"}}" diff --git a/package.json b/package.json index fbe63bb..a1ec3a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "windychen-utils", - "version": "1.1.7", + "version": "1.1.8", "main": "dist/windychen-utils.cjs.js", "module": "dist/windychen-utils.esm.js", "browser": "dist/windychen-utils.js",