Skip to content

Deploy to Sonatype by @trydofor #28

Deploy to Sonatype by @trydofor

Deploy to Sonatype by @trydofor #28

Workflow file for this run

name: Release-To-OssRh
run-name: Deploy ${{github.event.release.tag_name}} to Sonatype by @${{ github.actor }}
on:
workflow_dispatch:
inputs:
testCoverReport:
description: 'test and coverage report?'
default: true
type: boolean
required: false
testFailureIgnore:
description: 'test ignore failure?'
default: false
type: boolean
required: false
testLoggerLevel:
description: 'test logger level'
default: INFO
type: choice
options:
- DEBUG
- INFO
- WARN
- ERROR
deployOssrh:
description: 'deploy to ossrh?'
default: true
type: boolean
required: false
release:
types: [published]
jobs:
release:
name: Release to Sonatype
runs-on: ubuntu-latest
env:
MAVEN_OPTS: -Xmx2g
LOG_LEVEL: ${{ inputs.testLoggerLevel }}
TEST_VERBOSE: ${{ inputs.testLoggerLevel == 'DEBUG' }}
steps:
- name: Checkout ${{github.event.release.tag_name}}
uses: actions/checkout@v4
with:
fetch-depth: 10
## chache asdf/, m2/repository
- name: Cache Sdk & Repo
id: cache-sdk-repo
uses: actions/cache@v3
with:
path: |
~/.asdf/
~/.m2/repository/
key: asdf-m2-repo-${{hashFiles('.tool-versions')}}
## install jdk and maven
- name: Install asdf & tools
uses: asdf-vm/actions/install@v2
with:
skip_install: ${{steps.cache-sdk-repo.outputs.cache-hit == 'true'}}
## write settings.xml
- name: Maven settings.xml
id: settings
run: |
JAVA_HOME=$(asdf where java)
echo "JAVA_HOME=$JAVA_HOME" >> "$GITHUB_OUTPUT"
echo "GIT_BRANCH=$(git branch --show-current)" >> "$GITHUB_OUTPUT"
_opt=$(git describe --tags --exact-match 2>/dev/null || true)
if [ "$_opt" != "" ]; then
_opt="-Drevision=$_opt"
echo $_opt
echo "MVN_REVISION=$_opt" >> "$GITHUB_OUTPUT"
fi
_ver=$(mvn --quiet --non-recursive -DforceStdout -Dexpression=project.version $_opt help:evaluate)
echo $_ver
echo "WINGS_VERSION=$_ver" >> "$GITHUB_OUTPUT"
mvn -v
git --no-pager log --graph -10 --pretty=format:'%H - %ai %d %s'
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << "EOF"
<settings>
<interactiveMode>false</interactiveMode>
<servers>
<server>
<id>ossrh</id>
<username>${MVN_OSS_USER}</username>
<password>${MVN_OSS_PASS}</password>
</server>
</servers>
</settings>
EOF
## report if not release
- name: Test Coverage ${{ steps.settings.outputs.WINGS_VERSION }} ${{ steps.settings.outputs.GIT_BRANCH }}
if: inputs.testCoverReport
run: |
mvn -P 'test,!example' -Dmaven.test.failure.ignore=${{ inputs.testFailureIgnore }} clean test
mvn -pl ':devs-coverage' -am jacoco:report-aggregate
mvn -pl ':devs-coverage' -DrepoToken=$COVERALLS_WINGS verify
env:
TZ: Asia/Shanghai
JAVA_HOME: ${{ steps.settings.outputs.JAVA_HOME }}
MAIL_USER: ${{ secrets.MAIL_USER }}
MAIL_PASS: ${{ secrets.MAIL_PASS }}
MAIL_FROM: ${{ secrets.MAIL_FROM }}
MAIL_TO: ${{ secrets.MAIL_TO }}
COVERALLS_WINGS: ${{ secrets.COVERALLS_REPO_TOKEN }}
## import gpp private key
- name: Import GPG key
if: inputs.deployOssrh
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.MVN_GPG_SKEY }}
passphrase: ${{ secrets.MVN_GPG_PASS }}
## maven deploy
- name: Deploy ${{ steps.settings.outputs.WINGS_VERSION }} ${{ steps.settings.outputs.GIT_BRANCH }}
if: inputs.deployOssrh
run: >
mvn
-P 'ossrh,doc,!example'
${{ steps.settings.outputs.MVN_REVISION }}
-Dgpg.passphrase=${MVN_GPG_PASS}
clean deploy
env:
JAVA_HOME: ${{ steps.settings.outputs.JAVA_HOME }}
MVN_OSS_USER: ${{ secrets.MVN_OSS_USER }}
MVN_OSS_PASS: ${{ secrets.MVN_OSS_PASS }}
MVN_GPG_PASS: ${{ secrets.MVN_GPG_PASS }}