Skip to content

Maven Release

Maven Release #10

Workflow file for this run

name: 'Maven Release'
on:
workflow_dispatch:
inputs:
releaseVersion:
description: "Define the RELEASE version"
required: false
default: ""
developmentVersion:
description: "Define the SNAPSHOT version"
required: false
default: ""
autoReleaseAfterClose:
description: "Auto release after close"
required: false
default: "false"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-package: 'jdk'
cache: 'maven'
server-id: ossrh
- 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 GPG Key
uses: crazy-max/[email protected]
with:
gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
- name: Verify Whether a Release is Ready
shell: bash
run: |
if [ "${{ github.event.inputs.releaseVersion }}" != "" ] && [ "${{ github.event.inputs.developmentVersion }}" != "" ]; then
echo "auto_version=false" >> $GITHUB_ENV
else
echo "auto_version=true" >> $GITHUB_ENV
fi
if [ "${{ github.event.inputs.autoReleaseAfterClose }}" == "true" ] ; then
echo "auto_release=true" >> $GITHUB_ENV
else
echo "auto_release=false" >> $GITHUB_ENV
fi
- name: Fetch Artifact Information
shell: bash
run: |
# remove '-SNAPSHOT'
echo "artifact_version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT$//')" >> "$GITHUB_ENV"
echo "artifact_name=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> "$GITHUB_ENV"
echo "artifact_packaging=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.packaging -q -DforceStdout)" >> "$GITHUB_ENV"
echo "${{ env.artifact_name }} ${{ env.artifact_version }} ${{ env.artifact_packaging }}"
- name: Release With Maven
run: |
if [ "${{ env.auto_version }}" == "true" ]; then
mvn -B -U \
release:prepare \
release:perform \
-DreleaseVersion=${{ github.event.inputs.releaseVersion }} \
-DdevelopmentVersion=${{ github.event.inputs.developmentVersion }} \
deploy \
-s settings.xml \
-Prelease \
-Dgpg.passphrase=${{ secrets.MAVEN_GPG_PASSPHRASE }}
else
mvn -B -U \
release:prepare \
release:perform \
deploy \
-s settings.xml \
-Prelease \
-Dgpg.passphrase=${{ secrets.MAVEN_GPG_PASSPHRASE }}
fi
ls -al ./target/
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
AUTO_RELEASE_AFTER_CLOSE: ${{ env.auto_release }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}-${{ env.artifact_version }}
path: ./target/${{ env.artifact_name }}-${{ env.artifact_version }}.${{ env.artifact_packaging }}
- name: Workflow Release Notes
uses: peter-evans/repository-dispatch@v2
with:
event-type: github-release
client-payload: '{"auto_release": "${{ env.auto_release }}", "artifact": "${{ env.artifact_name }}-${{ env.artifact_version }}"}'