Files
windyChenUtils/.gitea/workflows/build.yaml
T
2026-07-16 14:12:23 +08:00

75 lines
3.1 KiB
YAML

name: Node.js Build
on:
push:
branches: ["main", "master"]
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 的标签
steps:
- name: Checkout code
run: |
git init
git remote add origin http://gitea:3000/windychen/windyChenUtils.git
git fetch --depth 1 origin ${{ github.sha }}
git checkout ${{ github.sha }}
- name: Setup npm for Verdaccio
run: |
npm config set registry http://verdaccio:4873/
npm config set //verdaccio:4873/:_authToken ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: npm i --registry http://verdaccio:4873/
- name: Run build
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..."
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
if: always()
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"
else
TITLE="❌ windychen-utils v${VERSION} 构建失败 chen-fnos"
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 }}\"}}"