Files
plugin-library/.gitea/workflows/.gitlab-ci.yml
root dd26da3757
Some checks failed
Plugin Library CI (Optimized) / detect-changes (push) Failing after 5m19s
Plugin Library CI (Optimized) / prepare (push) Has been skipped
Plugin Library CI (Optimized) / publish (push) Has been skipped
Plugin Library CI (Optimized) / cleanup (push) Failing after 1m30s
更新 .gitea/workflows/.gitlab-ci.yml
2026-04-11 11:21:43 +08:00

137 lines
4.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Plugin Library CI (Optimized)
on:
push:
branches: [master, main]
paths:
- 'Assets/**/package.json' # 只在版本文件变更时触发
- '.gitea/workflows/**'
workflow_dispatch:
env:
SERVER_HOST: ${{ vars.SERVER_HOST }}
AuthToken: ${{ vars.AUTH_TOKEN }}
jobs:
# ========== 阶段1检测变更模块 ==========
detect-changes:
runs-on: dev
container:
image: node:18-alpine # 建议替换为包含git的自定义镜像
outputs:
modules: ${{ steps.filter.outputs.modules }}
matrix-empty: ${{ steps.filter.outputs.empty }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2 # 需要对比上一个commit
- name: Detect Changed Modules
id: filter
run: |
# 获取变更的文件
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
# 检测哪些模块的package.json变更了
MODULES=()
for module in $(ls -d Assets/*/); do
MODULE_NAME=$(basename $module)
if echo "$CHANGED_FILES" | grep -q "^${module}package.json"; then
MODULES+=("\"$MODULE_NAME\"")
fi
done
# 输出JSON数组给矩阵使用
if [ ${#MODULES[@]} -eq 0 ]; then
echo "empty=true" >> $GITHUB_OUTPUT
echo "modules=[]" >> $GITHUB_OUTPUT
echo "📭 无模块版本变更,跳过发布"
else
echo "empty=false" >> $GITHUB_OUTPUT
echo "modules=[${MODULES[*]}]" >> $GITHUB_OUTPUT
echo "📦 待发布模块: ${MODULES[*]}"
fi
# ========== 阶段2准备代码仅当有变更时 ==========
prepare:
needs: detect-changes
if: needs.detect-changes.outputs.matrix-empty == 'false'
runs-on: dev
container:
image: node:18-alpine
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: source-${{ github.sha }}
path: ./Assets/
retention-days: 1
# ========== 阶段3并行发布仅发布变更的模块 ==========
publish:
needs: [detect-changes, prepare]
if: needs.detect-changes.outputs.matrix-empty == 'false'
runs-on: dev
container:
image: node:18-alpine
strategy:
fail-fast: false
# max-parallel: 4 # 根据你的Runner资源调整4-6通常安全
matrix:
module: ${{ fromJSON(needs.detect-changes.outputs.modules) }} # 动态矩阵,只跑变更的模块
steps:
# 直接下载artifact无需tar/untar
- name: Download Source
uses: actions/download-artifact@v3
with:
name: source-${{ github.sha }}
path: ./Assets/
# 使用setup-node缓存如果Gitea支持
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'http://${{ env.SERVER_HOST }}/npm'
cache: 'npm'
cache-dependency-path: './Assets/${{ matrix.module }}/package.json'
# 配置npm认证
- name: Configure NPM
working-directory: ./Assets/${{ matrix.module }}
run: |
echo "//${{ env.SERVER_HOST }}/:_authToken=${{ env.AuthToken }}" > .npmrc
echo "registry=http://${{ env.SERVER_HOST }}/npm" >> .npmrc
- name: Publish ${{ matrix.module }}
working-directory: ./Assets/${{ matrix.module }}
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "🚀 发布 ${{ matrix.module }}@$CURRENT_VERSION"
# 先检查是否已存在该版本,避免重复发布错误
if npm view ${{ matrix.module }}@$CURRENT_VERSION version &>/dev/null; then
echo "⚠️ 版本 $CURRENT_VERSION 已存在,跳过"
exit 0
fi
npm publish --access public || echo "❌ 发布失败"
# ========== 阶段4清理 ==========
cleanup:
needs: [publish, detect-changes]
if: always()
runs-on: dev
steps:
- name: Delete Artifact
uses: actions/delete-artifact@v3
with:
name: source-${{ github.sha }}
failOnError: false