Skip to content

Commit 8850011

Browse files
committed
Make Java test workflow reusable
1 parent 62fa434 commit 8850011

File tree

9 files changed

+572
-133
lines changed

9 files changed

+572
-133
lines changed

.github/workflows/reusable-ci.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Reusable Complete CI Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: 'Branch to checkout and test (defaults to the calling branch)'
8+
required: false
9+
type: string
10+
default: ''
11+
enable-status-reporting:
12+
description: 'Whether to enable status reporting'
13+
required: false
14+
type: boolean
15+
default: true
16+
status-context:
17+
description: 'Context for status checks'
18+
required: false
19+
type: string
20+
default: 'master/unit'
21+
target-repo:
22+
description: 'Repository to post status to'
23+
required: false
24+
type: string
25+
default: 'datadog-api-spec'
26+
java-versions:
27+
description: 'JSON array of Java versions to test against'
28+
required: false
29+
type: string
30+
default: '["8", "16", "18", "19"]'
31+
platforms:
32+
description: 'JSON array of platforms to run tests on'
33+
required: false
34+
type: string
35+
default: '["ubuntu-latest"]'
36+
test-script:
37+
description: 'Test script to execute'
38+
required: false
39+
type: string
40+
default: './run-tests.sh'
41+
examples-script:
42+
description: 'Examples script to execute'
43+
required: false
44+
type: string
45+
default: './check-examples.sh'
46+
secrets:
47+
PIPELINE_GITHUB_APP_ID:
48+
required: false
49+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
50+
required: false
51+
# Integration test secrets
52+
DD_API_KEY:
53+
required: false
54+
DD_CLIENT_API_KEY:
55+
required: false
56+
DD_CLIENT_APP_KEY:
57+
required: false
58+
SLEEP_AFTER_REQUEST:
59+
required: false
60+
61+
jobs:
62+
pre-commit:
63+
uses: ./.github/workflows/reusable-pre-commit.yml
64+
with:
65+
target-branch: ${{ inputs.target-branch }}
66+
enable-commit-changes: false # Don't auto-commit in external CI
67+
secrets:
68+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
69+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
70+
71+
javadoc:
72+
uses: ./.github/workflows/reusable-javadoc.yml
73+
with:
74+
target-branch: ${{ inputs.target-branch }}
75+
secrets:
76+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
77+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
78+
79+
shading:
80+
uses: ./.github/workflows/reusable-shading.yml
81+
with:
82+
target-branch: ${{ inputs.target-branch }}
83+
secrets:
84+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
85+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
86+
87+
test:
88+
uses: ./.github/workflows/reusable-java-test.yml
89+
with:
90+
target-branch: ${{ inputs.target-branch }}
91+
java-versions: ${{ inputs.java-versions }}
92+
platforms: ${{ inputs.platforms }}
93+
test-script: ${{ inputs.test-script }}
94+
secrets:
95+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
96+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
97+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
98+
99+
examples:
100+
uses: ./.github/workflows/reusable-examples.yml
101+
with:
102+
target-branch: ${{ inputs.target-branch }}
103+
examples-script: ${{ inputs.examples-script }}
104+
secrets:
105+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
106+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
107+
108+
integration:
109+
uses: ./.github/workflows/reusable-integration-test.yml
110+
with:
111+
target-branch: ${{ inputs.target-branch }}
112+
enable-status-reporting: false # We handle reporting in the main report job
113+
status-context: 'integration'
114+
target-repo: ${{ inputs.target-repo }}
115+
secrets:
116+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
117+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
118+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
119+
DD_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }}
120+
DD_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }}
121+
SLEEP_AFTER_REQUEST: ${{ secrets.SLEEP_AFTER_REQUEST }}
122+
123+
report:
124+
uses: ./.github/workflows/reusable-report.yml
125+
needs:
126+
- test
127+
- examples
128+
- javadoc
129+
- shading
130+
- integration
131+
if: always()
132+
with:
133+
test-result: ${{ needs.test.result }}
134+
examples-result: ${{ needs.examples.result }}
135+
javadoc-result: ${{ needs.javadoc.result }}
136+
shading-result: ${{ needs.shading.result }}
137+
context: ${{ inputs.status-context }}
138+
target-repo: ${{ inputs.target-repo }}
139+
enable-status-reporting: ${{ inputs.enable-status-reporting }}
140+
secrets:
141+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
142+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Reusable Examples Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: 'Branch to checkout and test (defaults to the calling branch)'
8+
required: false
9+
type: string
10+
default: ''
11+
examples-script:
12+
description: 'Examples script to execute'
13+
required: false
14+
type: string
15+
default: './check-examples.sh'
16+
java-version:
17+
description: 'Java version to use for examples'
18+
required: false
19+
type: string
20+
default: '16'
21+
secrets:
22+
PIPELINE_GITHUB_APP_ID:
23+
required: false
24+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
25+
required: false
26+
27+
jobs:
28+
examples:
29+
runs-on: ubuntu-latest
30+
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'
31+
steps:
32+
- uses: actions/checkout@v3
33+
with:
34+
ref: ${{ inputs.target-branch || github.ref }}
35+
- name: Install Java
36+
uses: actions/setup-java@v3
37+
with:
38+
java-version: ${{ inputs.java-version }}
39+
distribution: "temurin"
40+
cache: "maven"
41+
- name: Check examples
42+
run: ${{ inputs.examples-script }}
43+
shell: bash

.github/workflows/test_integration.yml renamed to .github/workflows/reusable-integration-test.yml

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Integration Tests
1+
name: Reusable Integration Test Workflow
22

33
permissions:
44
contents: read
@@ -16,6 +16,41 @@ on:
1616
- master
1717
schedule:
1818
- cron: "0 3 * * *"
19+
workflow_call:
20+
inputs:
21+
target-branch:
22+
description: 'Branch to checkout and test (defaults to the calling branch)'
23+
required: false
24+
type: string
25+
default: ''
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: 'integration'
36+
target-repo:
37+
description: 'Repository to post status to'
38+
required: false
39+
type: string
40+
default: 'datadog-api-spec'
41+
secrets:
42+
PIPELINE_GITHUB_APP_ID:
43+
required: false
44+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
45+
required: false
46+
DD_API_KEY:
47+
required: true
48+
DD_CLIENT_API_KEY:
49+
required: true
50+
DD_CLIENT_APP_KEY:
51+
required: true
52+
SLEEP_AFTER_REQUEST:
53+
required: false
1954

2055
concurrency:
2156
group: integration-${{ github.head_ref }}
@@ -48,17 +83,19 @@ jobs:
4883
with:
4984
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
5085
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
51-
repositories: datadog-api-spec
86+
repositories: ${{ inputs.target-repo || 'datadog-api-spec' }}
5287
- name: Checkout code
5388
uses: actions/checkout@v3
89+
with:
90+
ref: ${{ inputs.target-branch || github.ref }}
5491
- name: Post pending status check
55-
if: github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
92+
if: github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && (inputs.enable-status-reporting || github.event_name != 'workflow_call')
5693
uses: DataDog/github-actions/post-status-check@v2
5794
with:
5895
github-token: ${{ steps.get_token.outputs.token }}
59-
repo: datadog-api-spec
96+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
6097
status: pending
61-
context: integration
98+
context: ${{ inputs.status-context || 'integration' }}
6299
- name: Install Java
63100
uses: actions/setup-java@v3
64101
with:
@@ -85,18 +122,18 @@ jobs:
85122
RECORD: "none"
86123
SLEEP_AFTER_REQUEST: "${{ vars.SLEEP_AFTER_REQUEST }}"
87124
- name: Post failure status check
88-
if: failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
125+
if: failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && (inputs.enable-status-reporting || github.event_name != 'workflow_call')
89126
uses: DataDog/github-actions/post-status-check@v2
90127
with:
91128
github-token: ${{ steps.get_token.outputs.token }}
92-
repo: datadog-api-spec
129+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
93130
status: failure
94-
context: integration
131+
context: ${{ inputs.status-context || 'integration' }}
95132
- name: Post success status check
96-
if: "!failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')"
133+
if: "!failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && (inputs.enable-status-reporting || github.event_name != 'workflow_call')"
97134
uses: DataDog/github-actions/post-status-check@v2
98135
with:
99136
github-token: ${{ steps.get_token.outputs.token }}
100-
repo: datadog-api-spec
137+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
101138
status: success
102-
context: integration
139+
context: ${{ inputs.status-context || 'integration' }}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Reusable Java Testing Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: 'Branch to checkout and test (defaults to the calling branch)'
8+
required: false
9+
type: string
10+
default: ''
11+
java-versions:
12+
description: 'JSON array of Java versions to test against'
13+
required: false
14+
type: string
15+
default: '["8", "16", "18", "19"]'
16+
platforms:
17+
description: 'JSON array of platforms to run tests on'
18+
required: false
19+
type: string
20+
default: '["ubuntu-latest"]'
21+
test-script:
22+
description: 'Test script to execute'
23+
required: false
24+
type: string
25+
default: './run-tests.sh'
26+
secrets:
27+
PIPELINE_GITHUB_APP_ID:
28+
required: false
29+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
30+
required: false
31+
DD_API_KEY:
32+
required: false
33+
34+
jobs:
35+
test:
36+
strategy:
37+
matrix:
38+
java-version: ${{ fromJSON(inputs.java-versions) }}
39+
platform: ${{ fromJSON(inputs.platforms) }}
40+
runs-on: ${{ matrix.platform }}
41+
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'
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v3
45+
with:
46+
ref: ${{ inputs.target-branch || github.ref }}
47+
- name: Install Java
48+
uses: actions/setup-java@v3
49+
with:
50+
java-version: ${{ matrix.java-version }}
51+
distribution: "temurin"
52+
cache: "maven"
53+
- name: Configure Datadog Test Optimization
54+
uses: datadog/test-visibility-github-action@v2
55+
with:
56+
languages: java
57+
api_key: ${{ secrets.DD_API_KEY }}
58+
- name: Test
59+
run: ${{ inputs.test-script }}
60+
env:
61+
DD_CIVISIBILITY_COMPILER_PLUGIN_AUTO_CONFIGURATION_ENABLED: "false"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Reusable Javadoc Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: 'Branch to checkout and test (defaults to the calling branch)'
8+
required: false
9+
type: string
10+
default: ''
11+
java-version:
12+
description: 'Java version to use for javadoc'
13+
required: false
14+
type: string
15+
default: '8'
16+
secrets:
17+
PIPELINE_GITHUB_APP_ID:
18+
required: false
19+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
20+
required: false
21+
22+
jobs:
23+
javadoc:
24+
runs-on: ubuntu-latest
25+
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'
26+
steps:
27+
- uses: actions/checkout@v3
28+
with:
29+
ref: ${{ inputs.target-branch || github.ref }}
30+
- name: Install Java
31+
uses: actions/setup-java@v3
32+
with:
33+
java-version: ${{ inputs.java-version }}
34+
distribution: "temurin"
35+
cache: "maven"
36+
- name: Build javadoc
37+
run: mvn javadoc:javadoc
38+
shell: bash

0 commit comments

Comments
 (0)