Files
jhinno-openapi-java-sdk/.github/workflows/release.yml
2025-04-02 18:47:24 +08:00

83 lines
2.6 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: 发布到 Maven Central
on:
release:
types: [created]
# 可选:也可以手动触发
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 设置 JDK 1.8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
- name: 配置 GPG 密钥
run: |
# 导入 GPG 密钥
echo "${{ secrets.GPG_SECRET }}" | base64 --decode > private.key
gpg --batch --import private.key
rm private.key
# 配置 GPG 为非交互模式
mkdir -p ~/.gnupg/
echo "use-agent" > ~/.gnupg/gpg.conf
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
echo "allow-loopback-pinentry" > ~/.gnupg/gpg-agent.conf
chmod 700 ~/.gnupg
chmod 600 ~/.gnupg/*
gpg-connect-agent reloadagent /bye
- name: 创建 Maven 设置文件
run: |
cat > settings.xml << EOF
<settings>
<servers>
<server>
<id>ossrh</id>
<username>${{ secrets.OSSRH_USER }}</username>
<password>${{ secrets.OSSRH_PASSWORD }}</password>
</server>
<!-- 备用服务器 ID以防某些插件使用不同的 ID -->
<server>
<id>central</id>
<username>${{ secrets.OSSRH_USER }}</username>
<password>${{ secrets.OSSRH_PASSWORD }}</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>${{ secrets.OSSRH_USER }}</username>
<password>${{ secrets.OSSRH_PASSWORD }}</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>${{ secrets.GPG_PASSWORD }}</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
EOF
- name: 构建并发布到 Maven Central
run: |
mvn clean deploy \
--batch-mode \
--settings settings.xml \
-Dgpg.passphrase="${{ secrets.GPG_PASSWORD }}" \
-DskipTests=true