From 84c4cd96da75993cd53c9ea15edcb2710ff450c1 Mon Sep 17 00:00:00 2001 From: windychen Date: Thu, 16 Jul 2026 11:12:49 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E9=92=89=E9=92=89=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E5=B8=83=E7=BB=93=E6=9E=9C=E8=AF=A6?= =?UTF-8?q?=E6=83=85(skip/publish/fail)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 821c57a..ce373c2 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -29,14 +29,21 @@ jobs: run: npm run build - name: Publish package + id: publish 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 else echo "Version $VERSION not found, publishing..." - npm publish + if npm publish 2>&1; then + echo "published|已发布 v${VERSION} 到 Verdaccio" > /tmp/publish_result.txt + else + echo "failed|npm publish 失败 (v${VERSION})" > /tmp/publish_result.txt + exit 1 + fi fi - name: Notify DingTalk @@ -44,13 +51,25 @@ jobs: run: | STATUS="${{ job.status }}" VERSION=$(node -p "require('./package.json').version") + 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="构建失败,未执行发布" + 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" - DETAIL="包已发布到 Verdaccio http://verdaccio:4873/" + TITLE="✅ windychen-utils v${VERSION} 构建完成 chen-fnos" else TITLE="❌ windychen-utils v${VERSION} 构建失败 chen-fnos" - DETAIL="请检查 Actions 日志" 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${DETAIL}\n\n- 仓库: windychen/windyChenUtils\n- 分支: ${{ github.ref_name }}\n- 提交: ${{ github.sha }}\"}}" + -d "{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"${TITLE}\",\"text\":\"## ${TITLE}\n\n${PUB_LINE}\n\n- 仓库: windychen/windyChenUtils\n- 分支: ${{ github.ref_name }}\n- 提交: ${{ github.sha }}\"}}"