forked from Draegerwerk/t2iapi
-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (153 loc) · 6.05 KB
/
Copy pathbuild-java.yml
File metadata and controls
186 lines (153 loc) · 6.05 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Build java package
on:
pull_request: # Apply to all pull requests
push: # Apply to all branches
env:
GRADLE_VERSION: 7.5.1
RELEASE_VERSION: 0
jobs:
build-java:
runs-on: ubuntu-latest
steps:
# Run `git checkout`
- uses: actions/checkout@v4
- name: Source dependency versions
working-directory: config
run: cat versions.txt >> $GITHUB_ENV
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Install Protoc
run: |
sudo apt-get update && apt-get install -y apt-utils && apt-get install -y unzip
mkdir ${{ runner.temp }}/protoc_install
wget https://github.com/protocolbuffers/protobuf/releases/download/v${{ env.COMMON_PROTOC_VERSION }}/protoc-${{ env.COMMON_PROTOC_VERSION }}-linux-x86_64.zip -P ${{ runner.temp }}/protoc_install
unzip ${{ runner.temp }}/protoc_install/*.zip -d ${{ runner.temp }}/protoc_install/protoc
echo "${{ runner.temp }}/protoc_install/protoc/bin" >> $GITHUB_PATH
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
- name: Execute build
working-directory: ./java
run: ./gradlew jar generatePomFileForMavenPublication
- name: Rename pom file for release
if: startsWith(github.ref, 'refs/tags/v')
working-directory: ./java/build/publications/maven
run: mv pom-default.xml ./../../libs/t2iapi-${{ env.BASE_PACKAGE_VERSION }}.pom
- name: Rename pom file for snapshot
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
working-directory: ./java/build/publications/maven
run: mv pom-default.xml ./../../libs/t2iapi-${{ env.BASE_PACKAGE_VERSION }}.${{ github.run_number }}-SNAPSHOT.pom
- name: Archive built jars and pom
uses: actions/upload-artifact@v4
with:
name: target_jars
path: java/build/libs
run-tests-java17:
runs-on: ubuntu-latest
needs: build-java
steps:
# Run `git checkout`
- uses: actions/checkout@v4
- name: Download t2iapi jar artifact
uses: actions/download-artifact@v4
with:
name: target_jars
path: java/build/libs/
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
- name: Execute tests
working-directory: tests/java
run: ./gradlew test
- name: Archive test results
uses: actions/upload-artifact@v4
with:
name: test_results
path: tests/java/build/reports/tests/test/**/*.*
deploy-maven-central:
runs-on: ubuntu-latest
needs: run-tests-java17
permissions:
contents: write
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Source dependency versions
working-directory: config
run: cat versions.txt >> $GITHUB_ENV
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Install Protoc
run: |
sudo apt-get update && apt-get install -y apt-utils && apt-get install -y unzip
mkdir ${{ runner.temp }}/protoc_install
wget https://github.com/protocolbuffers/protobuf/releases/download/v${{ env.COMMON_PROTOC_VERSION }}/protoc-${{ env.COMMON_PROTOC_VERSION }}-linux-x86_64.zip -P ${{ runner.temp }}/protoc_install
unzip ${{ runner.temp }}/protoc_install/*.zip -d ${{ runner.temp }}/protoc_install/protoc
echo "${{ runner.temp }}/protoc_install/protoc/bin" >> $GITHUB_PATH
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
- name: Publish package
working-directory: ./java
run: ./gradlew publish
env:
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
- name: Deploy package
working-directory: ./java
run: ./gradlew jreleaserDeploy
env:
JRELEASER_MAVENCENTRAL_STAGE: UPLOAD
CENTRAL_PORTAL_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }}
CENTRAL_PORTAL_TOKEN: ${{ secrets.CENTRAL_PORTAL_TOKEN }}
- name: Download target_jars
uses: actions/download-artifact@v4
with:
name: target_jars
path: release/jar/
- name: Download test_results
uses: actions/download-artifact@v4
with:
name: test_results
path: release/test_results/
- name: Install zip
if: startsWith(github.ref, 'refs/tags/')
uses: montudor/action-zip@v1
- name: Zip jar files
if: startsWith(github.ref, 'refs/tags/')
run: zip -qq -j -r java-artifacts.zip release/jar/
- name: Zip test results
if: startsWith(github.ref, 'refs/tags/')
run: zip -qq -j -r java-test-results.zip release/test_results/
- name: Attach artifacts to github release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
java-artifacts.zip
java-test-results.zip
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') }}
body_path: CHANGELOG.md