-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (103 loc) · 4.05 KB
/
maven-deploy.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
on:
workflow_call:
secrets:
username:
required: true
password:
required: true
gpg_passphrase:
required: false
gpg_key:
required: false
inputs:
java_version:
type: string
description: set version of java used to run the maven
default: '17'
environment:
type: string
description: environment running the deploy maven-publish for using public maven repo and internal-publish for using internal one
required: true
release_type:
type: string
description: choice of release type (snapshot / release)
default: snapshot
directory_path:
type: string
description: directory with pom.xml to be executed
default: .
jobs:
maven-deploy:
name: Deploy to ${{ inputs.environment }}
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
env:
ENVIRONMENT: ${{ inputs.environment }}
RELEASE_TYPE: ${{ inputs.release_type }}
steps:
- uses: actions/checkout@v4
- name: Set environment
# Based on environment and release type of deploy we pick a distribution server - better than setup 3-4 different environments per repository
run: |
echo "$ENVIRONMENT:$RELEASE_TYPE"
if [ "$ENVIRONMENT" == "maven-publish" ]; then
if [ "$RELEASE_TYPE" == "release" ]; then
echo "setting server to ossrh-staging-distribution"
echo "server_id=ossrh-staging-distribution" >> $GITHUB_ENV
elif [ "$RELEASE_TYPE" == "snapshot" ]; then
echo "setting server to ossrh-snapshots-distribution"
echo "server_id=ossrh-snapshots-distribution" >> $GITHUB_ENV
fi
elif [ "$ENVIRONMENT" == "internal-publish" ]; then
echo "setting server to internal"
echo "server_id=jfrog-central" >> $GITHUB_ENV
fi
- name: Set up JDK ${{ inputs.java_version }}
uses: actions/setup-java@v4
with:
java-version: ${{ inputs.java_version }}
distribution: 'temurin'
cache: maven
server-id: ${{ env.server_id }}
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Publish Libraries to ${{ env.server_id }}
run: |
echo "building on $ENVIRONMENT:$RELEASE_TYPE"
cd ${{ inputs.directory_path }}
if [ "$ENVIRONMENT" == "internal-publish" ]; then
echo "running internal deploy"
mvn -B -DuseInternalRepo=true --no-transfer-progress deploy
elif [ "$ENVIRONMENT" == "maven-publish" ]; then
echo "running oss deploy"
if [ "$RELEASE_TYPE" == "release" ]; then
echo -e '${{ secrets.gpg_key }}' > keyfile.asc
echo -e '${{ secrets.gpg_passphrase }}' > passphrase.txt
mvn -B --no-transfer-progress -DperformRelease=true -Dpgp.secretkey=keyfile:keyfile.asc -Dpgp.passphrase=file:passphrase.txt deploy
elif [ "$RELEASE_TYPE" == "snapshot" ]; then
mvn -B --no-transfer-progress deploy
fi
fi
env:
MAVEN_USERNAME: ${{ secrets.username }}
MAVEN_PASSWORD: ${{ secrets.password }}
- name: Prepare artifacts for publish
run: |
mkdir lib war
target_dirs=($(find ${{ inputs.directory_path }} -type d -name "target" -maxdepth 4))
for target_dir in "${target_dirs[@]}"; do
find "$target_dir" -maxdepth 1 -type f -name "*.jar" -exec cp -v {} lib \;
find "$target_dir" -maxdepth 1 -type f -name "*.war" -exec cp -v {} war \;
done
- name: Publish JAR Artifacts
uses: actions/upload-artifact@v4
with:
name: Library Artifacts
path: 'lib/*.jar'
if-no-files-found: ignore
- name: Publish WAR Artifacts
uses: actions/upload-artifact@v4
with:
name: Application Artifacts
path: 'war/*.war'
if-no-files-found: ignore