This repository has been archived by the owner on Aug 31, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (86 loc) · 3.15 KB
/
maven.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This workflow will build a Java project with Maven
name: Java CI with Maven
on:
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@v2
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
java-package: 'jdk'
cache: 'maven'
server-id: ossrh
- name: Configure Git User
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Import GPG Key
uses: crazy-max/ghaction-import-gpg@v5.0.0
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 \
-X \
-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 }}"}'