mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2026-10-25 17:20:19 +08:00
[P3] 修复 CI/CD 配置 — 审计纠错
- 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:
1 parent
f1a7ed3d76
commit
19d8e9f4c4
6 files changed
+367
-419
No files matched your search
+16
-17
@@ -29,28 +29,27 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Compile
|
- name: Compile
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base clean compile
|
run: ./mvnw clean compile
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base test
|
run: ./mvnw test
|
||||||
|
|
||||||
- name: Quality check
|
- name: Quality check (Checkstyle + PMD)
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base verify -DskipTests
|
run: ./mvnw verify -DskipTests
|
||||||
|
|
||||||
- name: JaCoCo report
|
- name: JaCoCo report
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base jacoco:report
|
run: ./mvnw jacoco:report
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Checkstyle report
|
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base checkstyle:checkstyle
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: PMD report
|
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base pmd:pmd
|
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base package -DskipTests
|
run: ./mvnw package -DskipTests
|
||||||
|
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: build-artifacts
|
||||||
|
path: target/*.jar
|
||||||
|
retention-days: 7
|
||||||
|
|
||||||
security-check:
|
security-check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -61,7 +60,7 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: OWASP dependency check
|
- name: OWASP dependency check
|
||||||
run: mvn -f ${{ gitea.workspace }}/yexuejc-base org.owasp:dependency-check-maven:check
|
run: ./mvnw org.owasp:dependency-check-maven:check
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
release:
|
release:
|
||||||
@@ -70,7 +69,7 @@ jobs:
|
|||||||
needs: [build]
|
needs: [build]
|
||||||
|
|
||||||
if: >-
|
if: >-
|
||||||
github.event_name == 'push' && (
|
gitea.event_name == 'push' && (
|
||||||
gitea.ref == 'refs/heads/master' ||
|
gitea.ref == 'refs/heads/master' ||
|
||||||
gitea.ref == 'refs/heads/jre21'
|
gitea.ref == 'refs/heads/jre21'
|
||||||
)
|
)
|
||||||
@@ -81,5 +80,5 @@ jobs:
|
|||||||
|
|
||||||
- name: Prepare release
|
- name: Prepare release
|
||||||
run: |
|
run: |
|
||||||
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -f ${{ gitea.workspace }}/yexuejc-base)
|
VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
|
||||||
echo "Releasing version: $VERSION"
|
echo "Releasing version: $VERSION"
|
||||||
@@ -4,8 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
MAVEN_OPTS: -Xmx512m
|
MAVEN_OPTS: -Xmx512m
|
||||||
@@ -23,24 +21,21 @@ jobs:
|
|||||||
|
|
||||||
- name: Get version
|
- name: Get version
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ github.ref_name }}
|
VERSION=${GITEA_REF_NAME#v}
|
||||||
echo "VERSION=${VERSION#v}" >> $GITHUB_ENV
|
echo "VERSION=$VERSION" >> $GITEA_ENV
|
||||||
echo "Release version: ${{ env.VERSION }}"
|
echo "Release version: $VERSION"
|
||||||
|
|
||||||
- name: Update version
|
- name: Update version
|
||||||
run: |
|
run: ./mvnw versions:set -DnewVersion=$VERSION
|
||||||
mvn versions:set -DnewVersion=${{ env.VERSION }} -f ${{ gitea.workspace }}/yexuejc-base
|
|
||||||
|
|
||||||
- name: Build and test
|
- name: Build and verify
|
||||||
run: |
|
run: ./mvnw clean verify
|
||||||
mvn clean verify -f ${{ gitea.workspace }}/yexuejc-base
|
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: |
|
run: ./mvnw package -DskipTests
|
||||||
mvn package -DskipTests -f ${{ gitea.workspace }}/yexuejc-base
|
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-artifacts-${{ env.VERSION }}
|
name: release-artifacts-${{ env.VERSION }}
|
||||||
path: ${{ gitea.workspace }}/yexuejc-base/target/*.jar
|
path: target/*.jar
|
||||||
+219
@@ -0,0 +1,219 @@
|
|||||||
|
# Gitee Go CI/CD 配置
|
||||||
|
# Gitee CI 语法基于 GitLab CI,文件名必须为 .gitee-ci.yml
|
||||||
|
# 放置在项目根目录,推送后自动触发流水线
|
||||||
|
#
|
||||||
|
# 使用方式:
|
||||||
|
# 1. 开启 Gitee 仓库的 CI/CD 功能(管理 > CI/CD)
|
||||||
|
# 2. 确保 .gitee-ci.yml 在项目根目录
|
||||||
|
# 3. 推送代码后自动触发
|
||||||
|
|
||||||
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
- quality
|
||||||
|
- security
|
||||||
|
- package
|
||||||
|
- release
|
||||||
|
|
||||||
|
variables:
|
||||||
|
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
key: "${CI_COMMIT_REF_SLUG}"
|
||||||
|
paths:
|
||||||
|
- .m2/repository/
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 构建阶段 — 根据分支自动选择 JDK
|
||||||
|
# ============================================
|
||||||
|
build:java21:
|
||||||
|
stage: build
|
||||||
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
script:
|
||||||
|
- ./mvnw -B clean compile
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- target/classes/
|
||||||
|
expire_in: 1 hour
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- jre21
|
||||||
|
|
||||||
|
build:java17:
|
||||||
|
stage: build
|
||||||
|
image: maven:3.9-eclipse-temurin-17
|
||||||
|
script:
|
||||||
|
- ./mvnw -B clean compile
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- target/classes/
|
||||||
|
expire_in: 1 hour
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- jre17
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 测试阶段 — 各 JDK 独立跑测试
|
||||||
|
# ============================================
|
||||||
|
test:java21:
|
||||||
|
stage: test
|
||||||
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
script:
|
||||||
|
- ./mvnw -B test
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
junit: target/surefire-reports/*.xml
|
||||||
|
paths:
|
||||||
|
- target/surefire-reports/
|
||||||
|
- target/site/jacoco/
|
||||||
|
expire_in: 7 days
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- jre21
|
||||||
|
|
||||||
|
test:java17:
|
||||||
|
stage: test
|
||||||
|
image: maven:3.9-eclipse-temurin-17
|
||||||
|
script:
|
||||||
|
- ./mvnw -B test
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
junit: target/surefire-reports/*.xml
|
||||||
|
paths:
|
||||||
|
- target/surefire-reports/
|
||||||
|
expire_in: 7 days
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- jre17
|
||||||
|
|
||||||
|
test:java11:
|
||||||
|
stage: test
|
||||||
|
image: maven:3.9-eclipse-temurin-11
|
||||||
|
script:
|
||||||
|
- ./mvnw -B test
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
junit: target/surefire-reports/*.xml
|
||||||
|
paths:
|
||||||
|
- target/surefire-reports/
|
||||||
|
expire_in: 7 days
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- jre11
|
||||||
|
|
||||||
|
test:java8:
|
||||||
|
stage: test
|
||||||
|
image: maven:3.9-eclipse-temurin-8
|
||||||
|
script:
|
||||||
|
- ./mvnw -B test
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
junit: target/surefire-reports/*.xml
|
||||||
|
paths:
|
||||||
|
- target/surefire-reports/
|
||||||
|
expire_in: 7 days
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- jre8
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 代码质量检查 (仅 Java 21)
|
||||||
|
# ============================================
|
||||||
|
checkstyle:
|
||||||
|
stage: quality
|
||||||
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
script:
|
||||||
|
- ./mvnw -B checkstyle:check
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- target/checkstyle-result.xml
|
||||||
|
expire_in: 7 days
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
pmd:
|
||||||
|
stage: quality
|
||||||
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
script:
|
||||||
|
- ./mvnw -B pmd:pmd
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- target/pmd-report.xml
|
||||||
|
expire_in: 7 days
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 安全扫描 (仅 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
|
||||||
|
expire_in: 14 days
|
||||||
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- jre21
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 打包
|
||||||
|
# ============================================
|
||||||
|
package:
|
||||||
|
stage: package
|
||||||
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
script:
|
||||||
|
- ./mvnw -B package -DskipTests
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- target/*.jar
|
||||||
|
expire_in: 30 days
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# 发布到 Maven Central (仅 tag, 手动触发)
|
||||||
|
# ============================================
|
||||||
|
release:maven-central:
|
||||||
|
stage: release
|
||||||
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
script:
|
||||||
|
- ./mvnw -B deploy -Dgpg.skip=false
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
when: manual
|
||||||
|
# 需要在 Gitee 仓库设置中配置 CI/CD 变量:
|
||||||
|
# MAVEN_CENTRAL_USERNAME — OSSRH 用户名
|
||||||
|
# MAVEN_CENTRAL_PASSWORD — OSSRH 密码
|
||||||
|
# GPG_PRIVATE_KEY — GPG 私钥 (ASCII armored)
|
||||||
|
# GPG_PASSPHRASE — GPG 密钥密码
|
||||||
+48
-25
@@ -15,57 +15,74 @@ on:
|
|||||||
- jre11
|
- jre11
|
||||||
- jre17
|
- jre17
|
||||||
- jre21
|
- jre21
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
# ==========================================
|
||||||
|
# 根据分支自动选择 JDK 版本
|
||||||
|
# ==========================================
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
java: ['21', '17', '11', '8']
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Java ${{ matrix.java }}
|
- name: Detect JDK version from branch
|
||||||
|
id: jdk
|
||||||
|
run: |
|
||||||
|
BRANCH="${GITHUB_REF#refs/heads/}"
|
||||||
|
case "$BRANCH" in
|
||||||
|
jre8) echo "version=8" >> $GITHUB_OUTPUT ;;
|
||||||
|
jre11) echo "version=11" >> $GITHUB_OUTPUT ;;
|
||||||
|
jre17) echo "version=17" >> $GITHUB_OUTPUT ;;
|
||||||
|
jre21) echo="version=21" >> $GITHUB_OUTPUT ;;
|
||||||
|
*) echo "version=21" >> $GITHUB_OUTPUT ;; # master 默认 21
|
||||||
|
esac
|
||||||
|
|
||||||
|
- name: Setup Java ${{ steps.jdk.outputs.version }}
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: ${{ matrix.java }}
|
java-version: ${{ steps.jdk.outputs.version }}
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Compile
|
||||||
run: ./mvnw -B clean compile -q
|
run: ./mvnw -B clean compile
|
||||||
env:
|
|
||||||
JAVA_HOME: ${{ runner.temp }}/jdk-${{ matrix.java }}
|
|
||||||
|
|
||||||
- name: Checkstyle
|
- name: Checkstyle
|
||||||
run: ./mvnw -B checkstyle:check -q
|
run: ./mvnw -B checkstyle:check
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: PMD
|
- name: PMD
|
||||||
run: ./mvnw -B pmd:pmd -q
|
run: ./mvnw -B pmd:pmd
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: ./mvnw -B test -q
|
run: ./mvnw -B test
|
||||||
|
|
||||||
- name: JaCoCo Report
|
- name: JaCoCo Report
|
||||||
run: ./mvnw -B test jacoco:report -q
|
run: ./mvnw -B test jacoco:report
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: ./mvnw -B package -DskipTests -q
|
run: ./mvnw -B package -DskipTests
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: artifacts-java-${{ matrix.java }}
|
name: artifacts-jdk${{ steps.jdk.outputs.version }}
|
||||||
path: target/*.jar
|
path: target/*.jar
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
|
|
||||||
|
# ==========================================
|
||||||
|
# 安全扫描 (仅用 Java 21)
|
||||||
|
# ==========================================
|
||||||
security-check:
|
security-check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -76,7 +93,7 @@ jobs:
|
|||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
|
|
||||||
- name: OWASP Dependency Check
|
- name: OWASP Dependency Check
|
||||||
run: ./mvnw -B org.owasp:dependency-check-maven:check -q
|
run: ./mvnw -B org.owasp:dependency-check-maven:check
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Upload report
|
- name: Upload report
|
||||||
@@ -87,10 +104,13 @@ jobs:
|
|||||||
path: target/dependency-check-report.html
|
path: target/dependency-check-report.html
|
||||||
retention-days: 14
|
retention-days: 14
|
||||||
|
|
||||||
|
# ==========================================
|
||||||
|
# 发布 (仅 tag 推送时触发)
|
||||||
|
# ==========================================
|
||||||
release:
|
release:
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/jre21')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
@@ -103,17 +123,20 @@ jobs:
|
|||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
|
|
||||||
- name: Get version
|
- name: Build & Deploy
|
||||||
id: version
|
run: ./mvnw -B clean deploy
|
||||||
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Build & Publish
|
|
||||||
run: ./mvnw -B deploy -q
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
# 需要在 GitHub 仓库 Settings > Secrets 中配置:
|
||||||
|
# MAVEN_USERNAME — Maven Central (OSSRH) 用户名
|
||||||
|
# MAVEN_PASSWORD — Maven Central (OSSRH) 密码
|
||||||
|
# GPG_PRIVATE_KEY — GPG 私钥 (ASCII armored)
|
||||||
|
# GPG_PASSPHRASE — GPG 密钥密码
|
||||||
|
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
|
||||||
|
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
|
||||||
|
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||||
|
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: target/*.jar
|
files: target/*.jar
|
||||||
|
|||||||
+76
-89
@@ -9,20 +9,25 @@ stages:
|
|||||||
- release
|
- release
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
MVN_OPTS: "-Dmaven.repo.local=.m2/repository"
|
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
|
||||||
CACHE_DIR: ".m2/repository"
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
key: ${CI_COMMIT_REF_SLUG}
|
key: "${CI_COMMIT_REF_SLUG}"
|
||||||
paths:
|
paths:
|
||||||
- .m2/repository/
|
- .m2/repository/
|
||||||
|
|
||||||
# Java 矩阵构建
|
# ============================================
|
||||||
|
# 构建阶段 — 根据分支自动选择 JDK
|
||||||
|
# ============================================
|
||||||
build:java21:
|
build:java21:
|
||||||
stage: build
|
stage: build
|
||||||
extends: .java-build
|
image: maven:3.9-eclipse-temurin-21
|
||||||
variables:
|
script:
|
||||||
JDK_VERSION: "21"
|
- ./mvnw -B clean compile
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- target/classes/
|
||||||
|
expire_in: 1 hour
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- jre21
|
- jre21
|
||||||
@@ -30,52 +35,49 @@ build:java21:
|
|||||||
|
|
||||||
build:java17:
|
build:java17:
|
||||||
stage: build
|
stage: build
|
||||||
extends: .java-build
|
image: maven:3.9-eclipse-temurin-17
|
||||||
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
|
|
||||||
script:
|
script:
|
||||||
- ./mvnw -B clean compile -q
|
- ./mvnw -B clean compile
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- target/classes/
|
- target/classes/
|
||||||
expire_in: 1 hour
|
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:
|
test:java21:
|
||||||
stage: test
|
stage: test
|
||||||
image: maven:3.9-eclipse-temurin-21
|
image: maven:3.9-eclipse-temurin-21
|
||||||
@@ -91,7 +93,7 @@ test:java21:
|
|||||||
paths:
|
paths:
|
||||||
- target/surefire-reports/
|
- target/surefire-reports/
|
||||||
- target/site/jacoco/
|
- target/site/jacoco/
|
||||||
expire_in: 1 week
|
expire_in: 7 days
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- jre21
|
- jre21
|
||||||
@@ -107,11 +109,10 @@ test:java17:
|
|||||||
junit: target/surefire-reports/*.xml
|
junit: target/surefire-reports/*.xml
|
||||||
paths:
|
paths:
|
||||||
- target/surefire-reports/
|
- target/surefire-reports/
|
||||||
expire_in: 1 week
|
expire_in: 7 days
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- jre17
|
- jre17
|
||||||
- jre21
|
|
||||||
- merge_requests
|
- merge_requests
|
||||||
|
|
||||||
test:java11:
|
test:java11:
|
||||||
@@ -124,12 +125,10 @@ test:java11:
|
|||||||
junit: target/surefire-reports/*.xml
|
junit: target/surefire-reports/*.xml
|
||||||
paths:
|
paths:
|
||||||
- target/surefire-reports/
|
- target/surefire-reports/
|
||||||
expire_in: 1 week
|
expire_in: 7 days
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- jre11
|
- jre11
|
||||||
- jre17
|
|
||||||
- jre21
|
|
||||||
- merge_requests
|
- merge_requests
|
||||||
|
|
||||||
test:java8:
|
test:java8:
|
||||||
@@ -142,16 +141,15 @@ test:java8:
|
|||||||
junit: target/surefire-reports/*.xml
|
junit: target/surefire-reports/*.xml
|
||||||
paths:
|
paths:
|
||||||
- target/surefire-reports/
|
- target/surefire-reports/
|
||||||
expire_in: 1 week
|
expire_in: 7 days
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- jre8
|
- jre8
|
||||||
- jre11
|
|
||||||
- jre17
|
|
||||||
- jre21
|
|
||||||
- merge_requests
|
- merge_requests
|
||||||
|
|
||||||
# 代码质量检查
|
# ============================================
|
||||||
|
# 代码质量检查 (仅 Java 21)
|
||||||
|
# ============================================
|
||||||
checkstyle:
|
checkstyle:
|
||||||
stage: quality
|
stage: quality
|
||||||
image: maven:3.9-eclipse-temurin-21
|
image: maven:3.9-eclipse-temurin-21
|
||||||
@@ -162,11 +160,8 @@ checkstyle:
|
|||||||
checkstyle: target/checkstyle-result.xml
|
checkstyle: target/checkstyle-result.xml
|
||||||
paths:
|
paths:
|
||||||
- target/checkstyle-result.xml
|
- target/checkstyle-result.xml
|
||||||
expire_in: 1 week
|
expire_in: 7 days
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
only:
|
|
||||||
- merge_requests
|
|
||||||
- pushes
|
|
||||||
|
|
||||||
pmd:
|
pmd:
|
||||||
stage: quality
|
stage: quality
|
||||||
@@ -178,30 +173,33 @@ pmd:
|
|||||||
pmd: target/pmd-report.xml
|
pmd: target/pmd-report.xml
|
||||||
paths:
|
paths:
|
||||||
- target/pmd-report.xml
|
- target/pmd-report.xml
|
||||||
expire_in: 1 week
|
expire_in: 7 days
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
only:
|
|
||||||
- merge_requests
|
|
||||||
- pushes
|
|
||||||
|
|
||||||
# 安全扫描
|
# ============================================
|
||||||
|
# 安全扫描 (仅 master/jre21)
|
||||||
|
# ============================================
|
||||||
owasp-check:
|
owasp-check:
|
||||||
stage: security
|
stage: security
|
||||||
image: maven:3.9-eclipse-temurin-21
|
image: maven:3.9-eclipse-temurin-21
|
||||||
|
variables:
|
||||||
|
MAVEN_OPTS: "-Xmx2048m -Dmaven.repo.local=.m2/repository"
|
||||||
script:
|
script:
|
||||||
- ./mvnw -B org.owasp:dependency-check-maven:check
|
- ./mvnw -B org.owasp:dependency-check-maven:check
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- target/dependency-check-report.html
|
- target/dependency-check-report.html
|
||||||
- target/dependency-check-report.xml
|
- target/dependency-check-report.xml
|
||||||
expire_in: 1 week
|
expire_in: 14 days
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- jre21
|
- jre21
|
||||||
- merge_requests
|
- merge_requests
|
||||||
|
|
||||||
|
# ============================================
|
||||||
# 打包
|
# 打包
|
||||||
|
# ============================================
|
||||||
package:
|
package:
|
||||||
stage: package
|
stage: package
|
||||||
image: maven:3.9-eclipse-temurin-21
|
image: maven:3.9-eclipse-temurin-21
|
||||||
@@ -211,31 +209,20 @@ package:
|
|||||||
paths:
|
paths:
|
||||||
- target/*.jar
|
- target/*.jar
|
||||||
expire_in: 1 day
|
expire_in: 1 day
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
- jre17
|
|
||||||
- jre11
|
|
||||||
- jre8
|
|
||||||
|
|
||||||
# 发布
|
# ============================================
|
||||||
|
# 发布到 Maven Central (仅 tag, 手动触发)
|
||||||
|
# ============================================
|
||||||
release:maven-central:
|
release:maven-central:
|
||||||
stage: release
|
stage: release
|
||||||
image: maven:3.9-eclipse-temurin-21
|
image: maven:3.9-eclipse-temurin-21
|
||||||
script:
|
script:
|
||||||
- |
|
- ./mvnw -B deploy -Dgpg.skip=false
|
||||||
# 配置 Maven Central
|
only:
|
||||||
./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 推送时触发
|
|
||||||
- tags
|
- tags
|
||||||
when: manual
|
when: manual
|
||||||
|
# 需要在 GitLab 项目 Settings > CI/CD > Variables 中配置:
|
||||||
|
# MAVEN_CENTRAL_USERNAME — OSSRH 用户名
|
||||||
|
# MAVEN_CENTRAL_PASSWORD — OSSRH 密码
|
||||||
|
# GPG_PRIVATE_KEY — GPG 私钥 (ASCII armored)
|
||||||
|
# GPG_PASSPHRASE — GPG 密钥密码
|
||||||
@@ -1,275 +0,0 @@
|
|||||||
# Gitee Go CI/CD 配置
|
|
||||||
# 使用 Gitee 的流水线功能 (流水线 -> 新建流水线 -> 模板 -> Java)
|
|
||||||
# 文件名: gitee.yml 或 gitee-ci.yml (放在项目根目录)
|
|
||||||
|
|
||||||
name: Java CI/CD
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
- jre17
|
|
||||||
- jre11
|
|
||||||
- jre8
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
- jre17
|
|
||||||
- jre11
|
|
||||||
- jre8
|
|
||||||
tag:
|
|
||||||
push:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
displayName:
|
|
||||||
- master: '主分支构建'
|
|
||||||
- jre21: 'Java 21 构建'
|
|
||||||
- jre17: 'Java 17 构建'
|
|
||||||
- jre11: 'Java 11 构建'
|
|
||||||
- jre8: 'Java 8 构建'
|
|
||||||
|
|
||||||
env:
|
|
||||||
MAVEN_OPTS: -Dmaven.repo.local=/cache/.m2/repository
|
|
||||||
CACHE_VERSION: v1
|
|
||||||
|
|
||||||
cache:
|
|
||||||
key: ${GITEA_BUILD_REF} # Gitee Go 缓存 key
|
|
||||||
paths:
|
|
||||||
- /cache/.m2/repository
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- build
|
|
||||||
- test
|
|
||||||
- quality
|
|
||||||
- package
|
|
||||||
- deploy
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# 构建阶段
|
|
||||||
# ============================================
|
|
||||||
build:java21:
|
|
||||||
stage: build
|
|
||||||
displayName: '[构建] Java 21'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw clean compile
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
- /^jre21-.+$/
|
|
||||||
allow_failure: false
|
|
||||||
|
|
||||||
build:java17:
|
|
||||||
stage: build
|
|
||||||
displayName: '[构建] Java 17'
|
|
||||||
image: maven:3.9-eclipse-temurin-17
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw clean compile
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre17
|
|
||||||
- /^jre17-.+$/
|
|
||||||
allow_failure: false
|
|
||||||
|
|
||||||
build:java11:
|
|
||||||
stage: build
|
|
||||||
displayName: '[构建] Java 11'
|
|
||||||
image: maven:3.9-eclipse-temurin-11
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw clean compile
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre11
|
|
||||||
- /^jre11-.+$/
|
|
||||||
allow_failure: false
|
|
||||||
|
|
||||||
build:java8:
|
|
||||||
stage: build
|
|
||||||
displayName: '[构建] Java 8'
|
|
||||||
image: maven:3.9-eclipse-temurin-8
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw clean compile
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre8
|
|
||||||
- /^jre8-.+$/
|
|
||||||
allow_failure: false
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# 测试阶段
|
|
||||||
# ============================================
|
|
||||||
test:
|
|
||||||
stage: test
|
|
||||||
displayName: '[测试] 单元测试'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw test
|
|
||||||
coverage: "/(?i)(total.*?)?([0-9]{1,3})\\s*%.*$/"
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
paths:
|
|
||||||
- target/surefire-reports/
|
|
||||||
- target/site/jacoco/
|
|
||||||
expire_in: 7 days
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
- jre17
|
|
||||||
- jre11
|
|
||||||
- jre8
|
|
||||||
allow_failure: false
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# 代码质量检查
|
|
||||||
# ============================================
|
|
||||||
checkstyle:
|
|
||||||
stage: quality
|
|
||||||
displayName: '[质量] Checkstyle'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw checkstyle:check
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
paths:
|
|
||||||
- target/checkstyle-result.xml
|
|
||||||
expire_in: 7 days
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- merge_requests
|
|
||||||
- pushes
|
|
||||||
|
|
||||||
pmd:
|
|
||||||
stage: quality
|
|
||||||
displayName: '[质量] PMD'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw pmd:pmd
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
paths:
|
|
||||||
- target/pmd-report.xml
|
|
||||||
expire_in: 7 days
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- merge_requests
|
|
||||||
- pushes
|
|
||||||
|
|
||||||
jacoco:
|
|
||||||
stage: quality
|
|
||||||
displayName: '[质量] JaCoCo 覆盖率'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw test jacoco:report
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
paths:
|
|
||||||
- target/site/jacoco/
|
|
||||||
expire_in: 7 days
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
- jre17
|
|
||||||
- jre11
|
|
||||||
- jre8
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# 安全扫描 (需要 Gitee 私有化版或企业版)
|
|
||||||
# ============================================
|
|
||||||
owasp:
|
|
||||||
stage: quality
|
|
||||||
displayName: '[安全] OWASP 依赖检查'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw org.owasp:dependency-check-maven:check
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
paths:
|
|
||||||
- target/dependency-check-report.html
|
|
||||||
expire_in: 30 days
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
variables:
|
|
||||||
# 增加内存避免 OWASP 扫描 OOM
|
|
||||||
MAVEN_OPTS: -Xmx2048m -Dmaven.repo.local=/cache/.m2/repository
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# 打包阶段
|
|
||||||
# ============================================
|
|
||||||
package:
|
|
||||||
stage: package
|
|
||||||
displayName: '[打包] 生成 JAR'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- ./mvnw package -DskipTests
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- target/yexuejc-base*.jar
|
|
||||||
expire_in: 30 days
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
- jre17
|
|
||||||
- jre11
|
|
||||||
- jre8
|
|
||||||
allow_failure: false
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# 发布阶段 (仅 tag 触发)
|
|
||||||
# ============================================
|
|
||||||
release:
|
|
||||||
stage: deploy
|
|
||||||
displayName: '[发布] Maven Central'
|
|
||||||
image: maven:3.9-eclipse-temurin-21
|
|
||||||
script:
|
|
||||||
- cd $GITEA_REPO clone_DIR
|
|
||||||
- |
|
|
||||||
# 设置版本号
|
|
||||||
VERSION=${GITEA_TAG#$"v"}
|
|
||||||
./mvnw versions:set -DnewVersion=$VERSION
|
|
||||||
# 发布到 Maven Central
|
|
||||||
./mvnw deploy -Dgpg.skip=false
|
|
||||||
env:
|
|
||||||
# 在 Gitee 仓库设置中配置以下密钥
|
|
||||||
# OSSRH_USERNAME: $MAVEN_CENTRAL_USERNAME
|
|
||||||
# OSSRH_PASSWORD: $MAVEN_CENTRAL_PASSWORD
|
|
||||||
# GPG_PRIVATE_KEY: $GPG_PRIVATE_KEY
|
|
||||||
# GPG_PASSPHRASE: $GPG_PASSPHRASE
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- target/yexuejc-base*.jar
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
when: manual
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# 钉钉/企业微信通知 (可选)
|
|
||||||
# ============================================
|
|
||||||
notify:
|
|
||||||
stage: .post
|
|
||||||
displayName: '[通知] 构建结果'
|
|
||||||
image: curlimages/curl:latest
|
|
||||||
script: |
|
|
||||||
if [ "$GITEA_BUILD_STATUS" = "success" ]; then
|
|
||||||
echo "构建成功"
|
|
||||||
else
|
|
||||||
echo "构建失败"
|
|
||||||
fi
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- jre21
|
|
||||||
when: always
|
|
||||||
Reference in new issue
Block a user