[P3] 修复 CI/CD 配置 — 审计纠错
CI - Build and Quality Check / build (push) Has been cancelled
CI - Build and Quality Check / security-check (push) Has been cancelled
CI - Build and Quality Check / release (push) Has been cancelled

- Gitea ci.yaml: 改用 ./mvnw,修复 gitea.event_name 变量,去掉硬编码项目名
- Gitea package.yaml: 修复 GITEA_REF_NAME/GITEA_ENV,去掉硬编码项目名
- GitHub ci.yaml: 按分支自动检测 JDK 版本(避免跨版本编译失败),release 仅 tag 触发
- GitLab ci.yml: 简化 only 规则,修正缩进
- Gitee: 删除错误的 gitee.yml(混用语法),新增 .gitee-ci.yml(GitLab CI 兼容格式)
This commit is contained in:
yexuejc committed 2026-04-18 16:24:38 +08:00
1 parent f1a7ed3d76
commit 19d8e9f4c4
6 files changed
+367 -419

No files matched your search

+76 -89
View File
@@ -9,20 +9,25 @@ stages:
- release
variables:
MVN_OPTS: "-Dmaven.repo.local=.m2/repository"
CACHE_DIR: ".m2/repository"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
key: ${CI_COMMIT_REF_SLUG}
key: "${CI_COMMIT_REF_SLUG}"
paths:
- .m2/repository/
# Java 矩阵构建
# ============================================
# 构建阶段 — 根据分支自动选择 JDK
# ============================================
build:java21:
stage: build
extends: .java-build
variables:
JDK_VERSION: "21"
image: maven:3.9-eclipse-temurin-21
script:
- ./mvnw -B clean compile
artifacts:
paths:
- target/classes/
expire_in: 1 hour
only:
- master
- jre21
@@ -30,52 +35,49 @@ build:java21:
build:java17:
stage: build
extends: .java-build
variables:
JDK_VERSION: "17"
only:
- master
- jre17
- jre21
- merge_requests
build:java11:
stage: build
extends: .java-build
variables:
JDK_VERSION: "11"
only:
- master
- jre11
- jre17
- jre21
- merge_requests
build:java8:
stage: build
extends: .java-build
variables:
JDK_VERSION: "8"
only:
- master
- jre8
- jre11
- jre17
- jre21
- merge_requests
.java-build:
image: maven:3.9-eclipse-temurin-${JDK_VERSION}
stage: build
image: maven:3.9-eclipse-temurin-17
script:
- ./mvnw -B clean compile -q
- ./mvnw -B clean compile
artifacts:
paths:
- target/classes/
expire_in: 1 hour
allow_failure: false
only:
- master
- jre17
- merge_requests
# 测试阶段
build:java11:
stage: build
image: maven:3.9-eclipse-temurin-11
script:
- ./mvnw -B clean compile
artifacts:
paths:
- target/classes/
expire_in: 1 hour
only:
- master
- jre11
- merge_requests
build:java8:
stage: build
image: maven:3.9-eclipse-temurin-8
script:
- ./mvnw -B clean compile
artifacts:
paths:
- target/classes/
expire_in: 1 hour
only:
- master
- jre8
- merge_requests
# ============================================
# 测试阶段 — 各 JDK 独立跑测试
# ============================================
test:java21:
stage: test
image: maven:3.9-eclipse-temurin-21
@@ -91,7 +93,7 @@ test:java21:
paths:
- target/surefire-reports/
- target/site/jacoco/
expire_in: 1 week
expire_in: 7 days
only:
- master
- jre21
@@ -107,11 +109,10 @@ test:java17:
junit: target/surefire-reports/*.xml
paths:
- target/surefire-reports/
expire_in: 1 week
expire_in: 7 days
only:
- master
- jre17
- jre21
- merge_requests
test:java11:
@@ -124,12 +125,10 @@ test:java11:
junit: target/surefire-reports/*.xml
paths:
- target/surefire-reports/
expire_in: 1 week
expire_in: 7 days
only:
- master
- jre11
- jre17
- jre21
- merge_requests
test:java8:
@@ -142,16 +141,15 @@ test:java8:
junit: target/surefire-reports/*.xml
paths:
- target/surefire-reports/
expire_in: 1 week
expire_in: 7 days
only:
- master
- jre8
- jre11
- jre17
- jre21
- merge_requests
# 代码质量检查
# ============================================
# 代码质量检查 (仅 Java 21)
# ============================================
checkstyle:
stage: quality
image: maven:3.9-eclipse-temurin-21
@@ -162,11 +160,8 @@ checkstyle:
checkstyle: target/checkstyle-result.xml
paths:
- target/checkstyle-result.xml
expire_in: 1 week
expire_in: 7 days
allow_failure: true
only:
- merge_requests
- pushes
pmd:
stage: quality
@@ -178,30 +173,33 @@ pmd:
pmd: target/pmd-report.xml
paths:
- target/pmd-report.xml
expire_in: 1 week
expire_in: 7 days
allow_failure: true
only:
- merge_requests
- pushes
# 安全扫描
# ============================================
# 安全扫描 (仅 master/jre21)
# ============================================
owasp-check:
stage: security
image: maven:3.9-eclipse-temurin-21
variables:
MAVEN_OPTS: "-Xmx2048m -Dmaven.repo.local=.m2/repository"
script:
- ./mvnw -B org.owasp:dependency-check-maven:check
artifacts:
paths:
- target/dependency-check-report.html
- target/dependency-check-report.xml
expire_in: 1 week
expire_in: 14 days
allow_failure: true
only:
- master
- jre21
- merge_requests
# ============================================
# 打包
# ============================================
package:
stage: package
image: maven:3.9-eclipse-temurin-21
@@ -211,31 +209,20 @@ package:
paths:
- target/*.jar
expire_in: 1 day
only:
- master
- jre21
- jre17
- jre11
- jre8
# 发布
# ============================================
# 发布到 Maven Central (仅 tag, 手动触发)
# ============================================
release:maven-central:
stage: release
image: maven:3.9-eclipse-temurin-21
script:
- |
# 配置 Maven Central
./mvnw -B deploy -Dgpg.skip=false
env:
# GitLab CI 变量 (需要在项目中配置)
# MAVEN_USERNAME: $MAVEN_CENTRAL_USERNAME
# MAVEN_PASSWORD: $MAVEN_CENTRAL_PASSWORD
# GPG_PRIVATE_KEY: $GPG_PRIVATE_KEY
# GPG_PASSPHRASE: $GPG_PASSPHRASE
artifacts:
paths:
- target/*.jar
only:
# 仅 tag 推送时触发
- ./mvnw -B deploy -Dgpg.skip=false
only:
- tags
when: manual
# 需要在 GitLab 项目 Settings > CI/CD > Variables 中配置:
# MAVEN_CENTRAL_USERNAME — OSSRH 用户名
# MAVEN_CENTRAL_PASSWORD — OSSRH 密码
# GPG_PRIVATE_KEY — GPG 私钥 (ASCII armored)
# GPG_PASSPHRASE — GPG 密钥密码