-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,88 @@ | ||
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created | ||
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path | ||
# This workflow will build a Java project with Maven | ||
|
||
name: Maven Package | ||
name: Java CI with Maven | ||
|
||
on: | ||
release: | ||
types: [created] | ||
push: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
inputs: | ||
releaseVersion: | ||
description: "Define the release version" | ||
required: true | ||
default: "" | ||
developmentVersion: | ||
description: "Define the snapshot version" | ||
required: true | ||
default: "" | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 19 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '19' | ||
distribution: 'temurin' | ||
server-id: github | ||
|
||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
|
||
- name: Publish to GitHub Packages Apache Maven | ||
run: mvn --batch-mode deploy | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.DEPLOY_TOKEN }} | ||
- uses: actions/checkout@v2 | ||
- name: Set up Maven Central Repository | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 20.0.1 | ||
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 | ||
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 \ | ||
-Pci-cd \ | ||
release:prepare \ | ||
release:perform \ | ||
javadoc:jar \ | ||
source:jar \ | ||
-s settings.xml \ | ||
-Dgpg.passphrase=${{ secrets.MAVEN_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 }}"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" | ||
xmlns="http://maven.apache.org/SETTINGS/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<servers> | ||
<server> | ||
<id>ossrh</id> | ||
<username>${env.MAVEN_USERNAME}</username> | ||
<password>${env.MAVEN_PASSWORD}</password> | ||
</server> | ||
</servers> | ||
</settings> |