Skip to content

Commit be2058a

Browse files
authored
Make Java test workflow reusable (#3118)
1 parent 25eef0d commit be2058a

File tree

8 files changed

+473
-133
lines changed

8 files changed

+473
-133
lines changed

.github/workflows/reusable-ci.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
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+
examples-script:
27+
description: 'Examples script to execute'
28+
required: false
29+
type: string
30+
default: './check-examples.sh'
31+
secrets:
32+
PIPELINE_GITHUB_APP_ID:
33+
required: false
34+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
35+
required: false
36+
# Integration test secrets
37+
DD_API_KEY:
38+
required: false
39+
DD_CLIENT_API_KEY:
40+
required: false
41+
DD_CLIENT_APP_KEY:
42+
required: false
43+
SLEEP_AFTER_REQUEST:
44+
required: false
45+
46+
jobs:
47+
pre-commit:
48+
uses: ./.github/workflows/reusable-pre-commit.yml
49+
with:
50+
target-branch: ${{ inputs.target-branch }}
51+
enable-commit-changes: false # Don't auto-commit in external CI
52+
secrets:
53+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
54+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
55+
56+
javadoc:
57+
uses: ./.github/workflows/reusable-javadoc.yml
58+
with:
59+
target-branch: ${{ inputs.target-branch }}
60+
secrets:
61+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
62+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
63+
64+
shading:
65+
uses: ./.github/workflows/reusable-shading.yml
66+
with:
67+
target-branch: ${{ inputs.target-branch }}
68+
secrets:
69+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
70+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
71+
72+
test:
73+
uses: ./.github/workflows/reusable-java-test.yml
74+
with:
75+
target-branch: ${{ inputs.target-branch }}
76+
java-versions: ${{ inputs.java-versions }}
77+
platforms: ${{ inputs.platforms }}
78+
test-script: ${{ inputs.test-script }}
79+
secrets:
80+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
81+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
82+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
83+
84+
examples:
85+
uses: ./.github/workflows/reusable-examples.yml
86+
with:
87+
target-branch: ${{ inputs.target-branch }}
88+
examples-script: ${{ inputs.examples-script }}
89+
secrets:
90+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
91+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
92+
93+
integration:
94+
uses: ./.github/workflows/reusable-integration-test.yml
95+
with:
96+
target-branch: ${{ inputs.target-branch }}
97+
secrets:
98+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
99+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
100+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
101+
DD_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }}
102+
DD_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }}
103+
SLEEP_AFTER_REQUEST: ${{ secrets.SLEEP_AFTER_REQUEST }}
104+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
repository: DataDog/datadog-api-client-java
35+
ref: ${{ inputs.target-branch || github.ref }}
36+
- name: Install Java
37+
uses: actions/setup-java@v3
38+
with:
39+
java-version: ${{ inputs.java-version }}
40+
distribution: "temurin"
41+
cache: "maven"
42+
- name: Check examples
43+
run: ${{ inputs.examples-script }}
44+
shell: bash

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

Lines changed: 49 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,20 @@ 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+
repository: DataDog/datadog-api-client-java
91+
ref: ${{ inputs.target-branch || github.ref }}
5492
- name: Post pending status check
55-
if: github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
93+
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')
5694
uses: DataDog/github-actions/post-status-check@v2
5795
with:
5896
github-token: ${{ steps.get_token.outputs.token }}
59-
repo: datadog-api-spec
97+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
6098
status: pending
61-
context: integration
99+
context: ${{ inputs.status-context || 'integration' }}
62100
- name: Install Java
63101
uses: actions/setup-java@v3
64102
with:
@@ -85,18 +123,18 @@ jobs:
85123
RECORD: "none"
86124
SLEEP_AFTER_REQUEST: "${{ vars.SLEEP_AFTER_REQUEST }}"
87125
- name: Post failure status check
88-
if: failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
126+
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')
89127
uses: DataDog/github-actions/post-status-check@v2
90128
with:
91129
github-token: ${{ steps.get_token.outputs.token }}
92-
repo: datadog-api-spec
130+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
93131
status: failure
94-
context: integration
132+
context: ${{ inputs.status-context || 'integration' }}
95133
- name: Post success status check
96-
if: "!failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')"
134+
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')"
97135
uses: DataDog/github-actions/post-status-check@v2
98136
with:
99137
github-token: ${{ steps.get_token.outputs.token }}
100-
repo: datadog-api-spec
138+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
101139
status: success
102-
context: integration
140+
context: ${{ inputs.status-context || 'integration' }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
repository: DataDog/datadog-api-client-java
47+
ref: ${{ inputs.target-branch || github.ref }}
48+
- name: Install Java
49+
uses: actions/setup-java@v3
50+
with:
51+
java-version: ${{ matrix.java-version }}
52+
distribution: "temurin"
53+
cache: "maven"
54+
- name: Configure Datadog Test Optimization
55+
uses: datadog/test-visibility-github-action@v2
56+
with:
57+
languages: java
58+
api_key: ${{ secrets.DD_API_KEY }}
59+
- name: Test
60+
run: ${{ inputs.test-script }}
61+
env:
62+
DD_CIVISIBILITY_COMPILER_PLUGIN_AUTO_CONFIGURATION_ENABLED: "false"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
repository: DataDog/datadog-api-client-java
30+
ref: ${{ inputs.target-branch || github.ref }}
31+
- name: Install Java
32+
uses: actions/setup-java@v3
33+
with:
34+
java-version: ${{ inputs.java-version }}
35+
distribution: "temurin"
36+
cache: "maven"
37+
- name: Build javadoc
38+
run: mvn javadoc:javadoc
39+
shell: bash

0 commit comments

Comments
 (0)