Skip to content

Publish package to the Maven Central Repository #61

Publish package to the Maven Central Repository

Publish package to the Maven Central Repository #61

Workflow file for this run

name: Publish package to the Maven Central Repository
# Run workflow on commits to the `main` branch
on:
push:
tags: "RELEASE-*"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
logLevel:
description: "Log level"
required: true
default: "info"
type: choice
options:
- error
- warning
- info
- debug
autoPublish:
description: "Auto publish"
required: true
default: true
type: boolean
waitUntil:
description: "Wait until"
required: true
type: choice
options:
- published
- uploaded
- validated
dino-dependencies-root:
description: "Skip dependencies?"
required: false
type: boolean
dino-spring-assembly:
description: "Skip assembly?"
required: false
type: boolean
dino-spring-boot-starter-parent:
description: "Skip boot?"
required: false
type: boolean
dino-spring-cloud-starter-parent:
description: "Skip cloud?"
required: false
type: boolean
dino-spring-commons:
description: "Skip commons?"
required: false
type: boolean
dino-spring-data:
description: "Skip data?"
required: false
type: boolean
dino-spring-auth:
description: "Skip auth?"
required: false
type: boolean
jobs:
publish:
runs-on: ubuntu-latest
env:
MVN_OPT: "--errors --no-transfer-progress --batch-mode"
BUILD_OPT: "-Dmaven.test.skip=true -P publish"
MVN_NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
MVN_NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
AUTO_PUBLISH: ${{ github.event.inputs.autoPublish || true }}
WAIT_UNTIL: ${{ github.event.inputs.waitUntil }}
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Install Java and Maven
uses: actions/setup-java@v4.5.0
with:
java-version: 17
distribution: "temurin"
server-id: central
server-username: MVN_NEXUS_USERNAME
server-password: MVN_NEXUS_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
cache: "maven"
- name: Package & Install to Local Repository
run: |
touch /home/runner/.m2/settings-security.xml
# 将secrets.MVN_SETTINGS_SECURITY写入到settings-security.xml文件
echo "${{ secrets.MVN_SETTINGS_SECURITY }}" > /home/runner/.m2/settings-security.xml
# 定义项目数组
projects=(
"dino-dependencies-root"
"dino-spring-assembly"
"dino-spring-boot-starter-parent"
"dino-spring-cloud-starter-parent"
"dino-spring-commons"
"dino-spring-data"
"dino-spring-auth"
"dino-spring-core"
)
# 循环遍历项目数组
for project in "${projects[@]}"; do
# 进入项目目录
cd "$project"
# 输出开始打包信息
echo "=============== 开始打包 $project ==============="
# 执行mvn命令
mvn clean package install $MVN_OPT $BUILD_OPT
# 返回到上一级目录
cd ..
done
echo "所有项目打包完成。"
- name: Publish to Maven Central
run: |
echo "是否自动发布:$AUTO_PUBLISH"
echo "等待条件:$WAIT_UNTIL"
# 定义发布参数
if [ "$AUTO_PUBLISH" = false ]; then
export DEPLOY_AUTO_PUBLISH=false
export DEPLOY_WAIT_UNTIL=${WAIT_UNTIL:-"uploaded"}
else
export DEPLOY_AUTO_PUBLISH=true
export DEPLOY_WAIT_UNTIL=${WAIT_UNTIL:-"published"}
fi
# 根据用户选择要skip的项目,设置发布参数
skipedProjects=()
if [ "$dino-dependencies-root" = true ]; then
skipedProjects+=("dino-dependencies-root")
fi
if [ "$dino-spring-assembly" = true ]; then
skipedProjects+=("dino-spring-assembly")
fi
if [ "$dino-spring-boot-starter-parent" = true ]; then
skipedProjects+=("dino-spring-boot-starter-parent")
fi
if [ "$dino-spring-cloud-starter-parent" = true ]; then
skipedProjects+=("dino-spring-cloud-starter-parent")
fi
if [ "$dino-spring-commons" = true ]; then
skipedProjects+=("dino-spring-commons")
fi
if [ "$dino-spring-data" = true ]; then
skipedProjects+=("dino-spring-data")
fi
if [ "$dino-spring-auth" = true ]; then
skipedProjects+=("dino-spring-auth")
fi
echo "=============== 开始发布到Maven中央仓库 ==============="
# 定义项目数组
projects=(
"dino-dependencies-root"
"dino-spring-assembly"
"dino-spring-boot-starter-parent"
"dino-spring-cloud-starter-parent"
"dino-spring-commons"
"dino-spring-data"
"dino-spring-auth"
"dino-spring-core"
)
# 循环遍历项目数组
for project in "${projects[@]}"; do
# 如果用户选择跳过当前项目,则跳过当前项目
if [[ " ${skipedProjects[@]} " =~ " ${project} " ]]; then
echo "=============== 跳过发布 $project ==============="
continue
fi
# 进入项目目录
cd "$project"
# 输出开始发布信息
echo "=============== 开始发布 $project ==============="
# 执行mvn命令
mvn deploy $MVN_OPT $BUILD_OPT $DEPLOY_OPT
# 返回到上一级目录
cd ..
done
echo "所有项目发布完成。"