-
-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (155 loc) · 6.53 KB
/
cloudsmith_release.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: cloudsmith_release
env:
MAVEN_OPTS: "-Xmx2G -XX:+ExitOnOutOfMemoryError -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 -Dmaven.wagon.http.retryHandler.count=3"
on:
workflow_call:
secrets:
CLOUDSMITH_REPO:
required: true
CLOUDSMITH_USER:
required: true
CLOUDSMITH_API_KEY:
required: true
extra-env:
required: false
inputs:
maven_args:
description: The arguments to pass to all Maven commands when building the code
required: false
default: '-DskipTests=true -Dgpg.skip=true -Dcheck.skip-rat=true -Dcheck.skip-spotbugs=true'
type: string
goal:
description: The Maven goal(s) used when building the code
required: false
default: 'verify'
type: string
maven_version:
description: The Maven version used for builds
required: false
default: '3.8.4'
type: string
os:
description: The OS used
required: false
default: 'ubuntu-22.04'
type: string
jdk:
description: The JDK used
required: false
default: '11'
type: string
jdk-distribution:
description: The JDK distribution used
required: false
default: 'temurin'
type: string
timeout-minutes:
description: 'timeout-minutes used by the builds (defaults to 360)'
required: false
default: 360
type: number
deploy_args:
description: The arguments to pass to all Maven commands when deploying the code
required: false
default: '-Dpackaging=jar -DgeneratePom=true'
type: string
deploy_goal:
description: The Maven deploy goal(s) used
required: false
default: 'deploy:deploy-file'
type: string
failure-upload-path:
description: A file, directory or wildcard pattern that describes what to upload on failure
required: false
type: string
group_id:
description: The group id of the released artifact(s)
required: true
type: string
artifact_id:
description: The artifact id of the artifact(s) to release
required: false
default: '*'
type: string
artifact_suffix:
description: Optional suffix to append to the released artifact(s) id (e.g., -features)
required: false
default: ''
type: string
jobs:
cloudsmith_release:
runs-on: ${{ inputs.os }}
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- name: Set environment variables
run: |
echo '${{ secrets.extra-env }}' | jq -r 'to_entries|map("::add-mask::\(.value|tostring)")|.[]'
echo '${{ secrets.extra-env }}' | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ inputs.jdk }}
distribution: ${{ inputs.jdk-distribution }}
cache: 'maven'
- name: Configure Sonatype mirror
uses: s4u/maven-settings-action@v3.1.0
# Go to Sonatype directly to avoid delay syncs (could get rid of this if actions/setup-java were to support mirrors).
with:
mirrors: '[{"id": "oss-releases", "name": "Sonatype releases", "mirrorOf": "central", "url": "https://oss.sonatype.org/content/repositories/releases"}]'
sonatypeSnapshots: true
githubServer: false
servers: |
[{
"id": "${CLOUDSMITH_REPO}",
"username": "${CLOUDSMITH_USER}",
"password": "${CLOUDSMITH_API_KEY}"
},
{
"id": "github",
"configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}
}]
- name: Set up Maven
run: mvn --errors --batch-mode --show-version wrapper:wrapper "-Dmaven=${{ inputs.maven_version }}"
- name: Set new version
run: |
current_version_with_snapshot=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
current_version_without_snapshot=${current_version_with_snapshot%SNAPSHOT*}
new_version="${current_version_without_snapshot}$(git rev-parse --short HEAD)"
./mvnw versions:set -DnewVersion=${new_version}
echo "::notice ::Version is ${new_version}"
- name: Build artifacts
run: ./mvnw --errors --batch-mode --show-version ${{ inputs.maven_args }} ${{ inputs.goal }}
- name: Deploy artifacts
env:
CLOUDSMITH_USER: ${{ secrets.CLOUDSMITH_USER }}
CLOUDSMITH_REPO: ${{ secrets.CLOUDSMITH_REPO }}
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
run: |
cp -r .mvn mvnw /var/tmp/
VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
FILES=${{ inputs.artifact_id }}-$VERSION.jar
for f in `find . -type f -name "$FILES"`; do
# Make sure the current pom.xml file isn't uploaded
cp $f /var/tmp/
filename=$(basename $f)
artifactId=${filename%-$VERSION*}${{ inputs.artifact_suffix }}
cd /var/tmp
echo "Deploying $filename"
./mvnw --errors --batch-mode --show-version ${{ inputs.maven_deploy_args }} ${{ inputs.deploy_goal }} -Dfile=$filename \
-DrepositoryId=$CLOUDSMITH_REPO \
-Durl=https://maven.cloudsmith.io/killbill/$CLOUDSMITH_REPO \
-DgroupId=${{ inputs.group_id }} \
-DartifactId=$artifactId \
-Dversion=$VERSION
cd -
done
- name: Upload artifact on failure
uses: actions/upload-artifact@v4
if: failure() && inputs.failure-upload-path != ''
with:
name: failure-${{ inputs.os }}-${{ inputs.jdk }}-${{ inputs.jdk-distribution }}
path: ${{ inputs.failure-upload-path }}