1
+ name : Reusable Java Testing Workflow
2
+
3
+ on :
4
+ workflow_call :
5
+ inputs :
6
+ java-versions :
7
+ description : ' JSON array of Java versions to test against'
8
+ required : false
9
+ type : string
10
+ default : ' ["8", "16", "18", "19"]'
11
+ platforms :
12
+ description : ' JSON array of platforms to run tests on'
13
+ required : false
14
+ type : string
15
+ default : ' ["ubuntu-latest"]'
16
+ test-script :
17
+ description : ' Test script to execute'
18
+ required : false
19
+ type : string
20
+ default : ' ./run-tests.sh'
21
+ examples-script :
22
+ description : ' Examples script to execute'
23
+ required : false
24
+ type : string
25
+ default : ' ./check-examples.sh'
26
+ enable-status-reporting :
27
+ description : ' Whether to post status checks to datadog-api-spec repo'
28
+ required : false
29
+ type : boolean
30
+ default : false
31
+ status-context :
32
+ description : ' Context for status checks'
33
+ required : false
34
+ type : string
35
+ default : ' master/unit'
36
+ secrets :
37
+ PIPELINE_GITHUB_APP_ID :
38
+ required : false
39
+ PIPELINE_GITHUB_APP_PRIVATE_KEY :
40
+ required : false
41
+ DD_API_KEY :
42
+ required : false
43
+
44
+ jobs :
45
+ pre-commit :
46
+ runs-on : ubuntu-latest
47
+ if : >
48
+ (github.event.pull_request.draft == false &&
49
+ !contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
50
+ !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
51
+ github.event_name == 'schedule'
52
+ steps :
53
+ - name : Get GitHub App token
54
+ id : get_token
55
+ uses : actions/create-github-app-token@v1
56
+ with :
57
+ app-id : ${{ secrets.PIPELINE_GITHUB_APP_ID }}
58
+ private-key : ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
59
+ - uses : actions/checkout@v3
60
+ with :
61
+ fetch-depth : 0
62
+ ref : ${{ github.event.pull_request.head.sha }}
63
+ token : ${{ steps.get_token.outputs.token }}
64
+ - uses : actions/setup-python@v4
65
+ with :
66
+ python-version : ' 3.11'
67
+ - name : Install pre-commit
68
+ run : python -m pip install pre-commit
69
+ - name : set PY
70
+ run : echo "PY=$(python -c 'import platform;print(platform.python_version())')" >> $GITHUB_ENV
71
+ - uses : actions/cache@v3
72
+ with :
73
+ path : ~/.cache/pre-commit
74
+ key : pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
75
+ - name : Install Java
76
+ uses : actions/setup-java@v3
77
+ with :
78
+ java-version : " 16"
79
+ distribution : " temurin"
80
+ cache : " maven"
81
+ - id : pre_commit
82
+ name : Run pre-commit
83
+ if : github.event.action != 'closed' && github.event.pull_request.merged != true
84
+ run : |
85
+ wget https://github.com/google/google-java-format/releases/download/v1.16.0/google-java-format-1.16.0-all-deps.jar -O google-java-format.jar
86
+ pre-commit run --verbose --from-ref "${FROM_REF}" --to-ref "${TO_REF}" --show-diff-on-failure --color=always
87
+ env :
88
+ FROM_REF : ${{ github.event.pull_request.base.sha }}
89
+ TO_REF : ${{ github.event.pull_request.head.sha }}
90
+ - name : Commit changes
91
+ if : ${{ failure() }}
92
+ run : |-
93
+ git add -A
94
+ git config user.name "${GIT_AUTHOR_NAME}"
95
+ git config user.email "${GIT_AUTHOR_EMAIL}"
96
+ git commit -m "pre-commit fixes"
97
+ git push origin "HEAD:${HEAD_REF}"
98
+ exit 1
99
+ env :
100
+ HEAD_REF : ${{ github.event.pull_request.head.ref }}
101
+ GIT_AUTHOR_EMAIL :
" [email protected] "
102
+ GIT_AUTHOR_NAME : " ci.datadog-api-spec"
103
+ - id : pre_commit_schedule
104
+ name : Run pre-commit in schedule
105
+ if : github.event_name == 'schedule'
106
+ run : |
107
+ pre-commit run --all-files --show-diff-on-failure --color=always
108
+
109
+ javadoc :
110
+ runs-on : ubuntu-latest
111
+ if : (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
112
+ steps :
113
+ - uses : actions/checkout@v3
114
+ - name : Install Java
115
+ uses : actions/setup-java@v3
116
+ with :
117
+ java-version : " 8"
118
+ distribution : " temurin"
119
+ cache : " maven"
120
+ - name : Build javadoc
121
+ run : mvn javadoc:javadoc
122
+ shell : bash
123
+
124
+ shading :
125
+ runs-on : ubuntu-latest
126
+ if : (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
127
+ steps :
128
+ - uses : actions/checkout@v3
129
+ - name : Install Java
130
+ uses : actions/setup-java@v3
131
+ with :
132
+ java-version : " 8"
133
+ distribution : " temurin"
134
+ cache : " maven"
135
+ - name : Check all dependencies shaded
136
+ run : ./shade-test.sh
137
+
138
+ test :
139
+ strategy :
140
+ matrix :
141
+ java-version : ${{ fromJSON(inputs.java-versions) }}
142
+ platform : ${{ fromJSON(inputs.platforms) }}
143
+ runs-on : ${{ matrix.platform }}
144
+ if : (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
145
+ steps :
146
+ - name : Checkout code
147
+ uses : actions/checkout@v3
148
+ - name : Install Java
149
+ uses : actions/setup-java@v3
150
+ with :
151
+ java-version : ${{ matrix.java-version }}
152
+ distribution : " temurin"
153
+ cache : " maven"
154
+ - name : Configure Datadog Test Optimization
155
+ uses : datadog/test-visibility-github-action@v2
156
+ with :
157
+ languages : java
158
+ api_key : ${{ secrets.DD_API_KEY }}
159
+ - name : Test
160
+ run : ${{ inputs.test-script }}
161
+ env :
162
+ DD_CIVISIBILITY_COMPILER_PLUGIN_AUTO_CONFIGURATION_ENABLED : " false"
163
+
164
+ examples :
165
+ runs-on : ubuntu-latest
166
+ if : (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
167
+ steps :
168
+ - uses : actions/checkout@v3
169
+ - name : Install Java
170
+ uses : actions/setup-java@v3
171
+ with :
172
+ java-version : " 16"
173
+ distribution : " temurin"
174
+ cache : " maven"
175
+ - name : Check examples
176
+ run : ${{ inputs.examples-script }}
177
+ shell : bash
178
+
179
+ report :
180
+ runs-on : ubuntu-latest
181
+ if : always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && inputs.enable-status-reporting
182
+ needs :
183
+ - test
184
+ - examples
185
+ - javadoc
186
+ steps :
187
+ - name : Get GitHub App token
188
+ if : github.event_name == 'pull_request'
189
+ id : get_token
190
+ uses : actions/create-github-app-token@v1
191
+ with :
192
+ app-id : ${{ secrets.PIPELINE_GITHUB_APP_ID }}
193
+ private-key : ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
194
+ repositories : datadog-api-spec
195
+ - name : Post status check
196
+ uses : DataDog/github-actions/post-status-check@v2
197
+ with :
198
+ github-token : ${{ steps.get_token.outputs.token }}
199
+ repo : datadog-api-spec
200
+ status : ${{ (needs.javadoc.result == 'cancelled' || needs.test.result == 'cancelled' || needs.examples.result == 'cancelled') && 'pending' || needs.javadoc.result == 'success' && needs.test.result == 'success' && needs.examples.result == 'success' && 'success' || 'failure' }}
201
+ context : ${{ inputs.status-context }}
0 commit comments