forked from highlight/highlight
-
Notifications
You must be signed in to change notification settings - Fork 0
193 lines (170 loc) · 6.78 KB
/
java-sdk.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
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
187
188
189
190
191
192
193
name: 'Java SDK'
on:
workflow_dispatch:
inputs:
action:
description: 'Action'
required: true
default: 'none'
type: choice
options:
- none
- build
- test
- deploy
push:
branches: ['main']
tags: ['sdk/highlight-java/**']
pull_request:
types: [opened, reopened, synchronize, assigned, review_requested]
paths:
- 'sdk/highlight-java/**'
- '.github/workflows/java-sdk.yml'
permissions:
checks: write
defaults:
run:
working-directory: ./sdk/highlight-java
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
deploy: ${{ steps.deploy.outputs.deploy }}
build: ${{ steps.build.outputs.build }}
test: ${{ steps.test.outputs.test }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Deployment running
id: deploy
env:
GITHUB_EVENT_REF: ${{ startsWith(github.event.ref, 'refs/tags/sdk/highlight-java/') }}
INPUTS_ACTION: ${{ inputs.action }}
run: |
running=$(if [ "$GITHUB_EVENT_REF" = "true" ] || [ "$INPUTS_ACTION" = "deploy" ]; then echo true; else echo false; fi)
echo "deploy=$running" >> "$GITHUB_OUTPUT"
echo "Is deployment running: $running"
- name: Build running
id: build
env:
DEPLOY_RUNNING: ${{ steps.deploy.outputs.deploy }}
INPUTS_ACTION: ${{ inputs.action }}
run: |
running=$(if [ "$INPUTS_ACTION" != "test" ] || [ "$DEPLOY_RUNNING" == "true" ]; then echo true; else echo false; fi)
echo "build=$running" >> "$GITHUB_OUTPUT"
echo "Is build running: $running"
- name: Test running
id: test
env:
DEPLOY_RUNNING: ${{ steps.deploy.outputs.deploy }}
INPUTS_ACTION: ${{ inputs.action }}
run: |
running=$(if [ "$INPUTS_ACTION" != "build" ] || [ "$DEPLOY_RUNNING" == "true" ]; then echo true; else echo false; fi)
echo "test=$running" >> "$GITHUB_OUTPUT"
echo "Is test running: $running"
- name: Build version
id: version
env:
DEPLOY_RUNNING: ${{ steps.deploy.outputs.deploy }}
run: |
# Get latest tag version
version=$(git describe --match "sdk/highlight-java/v*" --abbrev=0 --tags $(git rev-list --tags --max-count=1) | cut -d "v" -f3)
# Returning default when no git tag was found
version=$(if [ "$version" != "" ]; then echo $version; else echo "0.0.0"; fi)
# Adding github runner number only when no deployment is running
version=$(if [ "$DEPLOY_RUNNING" == "true" ]; then echo "$version"; else echo "$version"-b$GITHUB_RUN_NUMBER; fi)
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Build version: $version"
build:
name: Build
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.build == 'true' }}
defaults:
run:
working-directory: ./sdk/highlight-java
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Build
run: |
mvn clean package --batch-mode -DskipTests -Drevision=${{needs.setup.outputs.version}}
mv ./highlight-sdk/target/highlight-sdk-*.jar ./
- name: Publish build artifacts
uses: actions/upload-artifact@v3
with:
name: highlight-java-sdk
path: ./sdk/highlight-java/highlight-sdk-*.jar
test:
name: Test
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.test == 'true' }}
defaults:
run:
working-directory: ./sdk/highlight-java
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Test
run: mvn clean test --batch-mode -Dmaven.test.failure.ignore=true -Drevision=${{needs.setup.outputs.version}}
- name: Upload Test Report
uses: actions/upload-artifact@v3
if: always()
with:
name: junit-test-results
path: '**/target/surefire-reports/TEST-*.xml'
retention-days: 1
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
with:
commit: ${{github.event.workflow_run.head_sha}}
report_paths: '**/target/surefire-reports/TEST-*.xml'
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [setup, build, test]
if: ${{ needs.setup.outputs.deploy == 'true' }}
defaults:
run:
working-directory: ./sdk/highlight-java
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Publish to the Maven Central Repository
run: mvn clean deploy --no-transfer-progress -Drevision=${{needs.setup.outputs.version}}
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}