[P3] 添加多平台 CI/CD 配置

- 新增 .github/workflows/ci.yaml (GitHub Actions)
- 新增 .gitlab-ci.yml (GitLab CI)
- 新增 gitee.yml (Gitee Go 流水线)

支持 GitHub / GitLab / Gitee 三大平台
This commit is contained in:
yexuejc committed 2026-04-18 16:01:53 +08:00
1 parent 63832a12b1
commit f1a7ed3d76
3 files changed
+637

No files matched your search

+121
View File
@@ -0,0 +1,121 @@
name: CI - Build and Quality Check
on:
push:
branches:
- master
- jre8
- jre11
- jre17
- jre21
pull_request:
branches:
- master
- jre8
- jre11
- jre17
- jre21
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['21', '17', '11', '8']
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven
run: ./mvnw -B clean compile -q
env:
JAVA_HOME: ${{ runner.temp }}/jdk-${{ matrix.java }}
- name: Checkstyle
run: ./mvnw -B checkstyle:check -q
continue-on-error: true
- name: PMD
run: ./mvnw -B pmd:pmd -q
continue-on-error: true
- name: Test
run: ./mvnw -B test -q
- name: JaCoCo Report
run: ./mvnw -B test jacoco:report -q
continue-on-error: true
- name: Package
run: ./mvnw -B package -DskipTests -q
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-java-${{ matrix.java }}
path: target/*.jar
retention-days: 7
security-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'
- name: OWASP Dependency Check
run: ./mvnw -B org.owasp:dependency-check-maven:check -q
continue-on-error: true
- name: Upload report
uses: actions/upload-artifact@v4
if: always()
with:
name: dependency-check-report
path: target/dependency-check-report.html
retention-days: 14
release:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/jre21')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'
- name: Get version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build & Publish
run: ./mvnw -B deploy -q
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: target/*.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+241
View File
@@ -0,0 +1,241 @@
image: maven:3.9-eclipse-temurin-21
stages:
- build
- test
- quality
- security
- package
- release
variables:
MVN_OPTS: "-Dmaven.repo.local=.m2/repository"
CACHE_DIR: ".m2/repository"
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .m2/repository/
# Java 矩阵构建
build:java21:
stage: build
extends: .java-build
variables:
JDK_VERSION: "21"
only:
- master
- jre21
- merge_requests
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
script:
- ./mvnw -B clean compile -q
artifacts:
paths:
- target/classes/
expire_in: 1 hour
allow_failure: false
# 测试阶段
test:java21:
stage: test
image: maven:3.9-eclipse-temurin-21
script:
- ./mvnw -B test
coverage: '/Total.*?([0-9]{1,3})%/'
artifacts:
reports:
junit: target/surefire-reports/*.xml
coverage_report:
coverage_format: jacoco
path: target/site/jacoco/jacoco.xml
paths:
- target/surefire-reports/
- target/site/jacoco/
expire_in: 1 week
only:
- master
- jre21
- merge_requests
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: 1 week
only:
- master
- jre17
- jre21
- merge_requests
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: 1 week
only:
- master
- jre11
- jre17
- jre21
- merge_requests
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: 1 week
only:
- master
- jre8
- jre11
- jre17
- jre21
- merge_requests
# 代码质量检查
checkstyle:
stage: quality
image: maven:3.9-eclipse-temurin-21
script:
- ./mvnw -B checkstyle:check
artifacts:
reports:
checkstyle: target/checkstyle-result.xml
paths:
- target/checkstyle-result.xml
expire_in: 1 week
allow_failure: true
only:
- merge_requests
- pushes
pmd:
stage: quality
image: maven:3.9-eclipse-temurin-21
script:
- ./mvnw -B pmd:pmd
artifacts:
reports:
pmd: target/pmd-report.xml
paths:
- target/pmd-report.xml
expire_in: 1 week
allow_failure: true
only:
- merge_requests
- pushes
# 安全扫描
owasp-check:
stage: security
image: maven:3.9-eclipse-temurin-21
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
allow_failure: true
only:
- master
- jre21
- merge_requests
# 打包
package:
stage: package
image: maven:3.9-eclipse-temurin-21
script:
- ./mvnw -B package -DskipTests
artifacts:
paths:
- target/*.jar
expire_in: 1 day
only:
- master
- jre21
- jre17
- jre11
- jre8
# 发布
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 推送时触发
- tags
when: manual
+275
View File
@@ -0,0 +1,275 @@
# 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