Skip to content

Commit

Permalink
change release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
angeliski committed Nov 8, 2024
1 parent 3e8278d commit 4e92a41
Showing 1 changed file with 101 additions and 40 deletions.
141 changes: 101 additions & 40 deletions .github/workflows/sonatype-publish.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,108 @@
name: Maven Release

name: Maven Release

on:
workflow_dispatch:
inputs:
releaseVersion:
description: "Define the release version"
required: true
default: ""
developmentVersion:
description: "Define the snapshot version"
required: true
default: ""

jobs:
publish:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
path: ~/.m2
key: 'cache'
restore-keys: 'cache'

- name: Setup Java JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11

- name: 'Build with Maven'
run: mvn -B install --file pom.xml

- name: Release
uses: qcastel/github-actions-maven-release@master
env:
JAVA_HOME: /usr/lib/jvm/java-11-openjdk/
with:
git-release-bot-name: "angeliski"
git-release-bot-email: "[email protected]"

maven-args: "-DskipTests -PsonatypeDeploy"
maven-servers: ${{ secrets.MVN_REPO_SERVERS }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

gpg-enabled: true
gpg-key-id: ${{ secrets.GPG_KEY_ID }}
gpg-key: ${{ secrets.GPG_KEY }}
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}

- name: 'Remove Snapshots Before Caching'
run: find ~/.m2 -name '*SNAPSHOT' | xargs rm -Rf
- uses: actions/checkout@v4

- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
path: ~/.m2
key: 'cache'
restore-keys: 'cache'

- name: Setup Java JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11

- name: 'Build with Maven'
run: mvn -B install --file pom.xml

- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Import SSH Key
run: |
#!/usr/bin/env bash
set -e
eval $(ssh-agent -s)
GIT_SSH=/usr/bin/ssh
echo "Do a SSH add with the key under env 'SSH_PRIVATE_KEY'"
mkdir -p ${SSH_ROOT_FOLDER}/
echo " ${{ secrets.SSH_PRIVATE_KEY }}" | base64 -d > ${SSH_ROOT_FOLDER}/id_rsa
chmod 600 ${SSH_ROOT_FOLDER}/id_rsa
echo "Set StrictHostKeyChecking no"
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ${SSH_ROOT_FOLDER}/config
echo "Whitelist github.com in ${SSH_ROOT_FOLDER}/known_hosts"
ssh-keyscan -t rsa github.com >> ${SSH_ROOT_FOLDER}/known_hosts
- name: Verify Whether a Release is Ready
id: release
shell: bash
run: |
if [ "${{ github.event.inputs.releaseVersion }}" != "" ] && [ "${{ github.event.inputs.developmentVersion }}" != "" ]; then
echo "auto_release=true" >> $GITHUB_ENV
else
echo "auto_release=false" >> $GITHUB_ENV
fi
- name: Release With Maven
run: |
mvn -B -U \
-PsonatypeDeploy \
release:prepare \
release:perform \
javadoc:jar \
source:jar \
-Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} \
-DreleaseVersion=${{ github.event.inputs.releaseVersion }} \
-DdevelopmentVersion=${{ github.event.inputs.developmentVersion }} \
deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
AUTO_RELEASE_AFTER_CLOSE: ${{ env.auto_release }}
- name: Artifact Name
shell: bash
run: |
echo "artifact_name=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> "$GITHUB_ENV"
- name: Define Jar Name
shell: bash
run: |
echo "{{ env.artifact_name }}"
ls -al ./target/
mv ./target/*.*:${{ env.artifact_name }}.jar ./target/${{ env.artifact_name }}.jar
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}-${{ env.sha_short }}
path: ./target/${{ env.artifact_name }}.jar
- name: Workflow Release Notes
uses: peter-evans/repository-dispatch@v2
if: ${{ github.event.inputs.releaseVersion }} != "" && ${{ github.event.inputs.developmentVersion }} != ""
with:
event-type: release-notes
client-payload: '{"auto_release": "${{ env.auto_release }}", "artifact": "${{ env.artifact_name }}-${{ env.sha_short }}"}'

0 comments on commit 4e92a41

Please sign in to comment.