-
Notifications
You must be signed in to change notification settings - Fork 31
155 lines (146 loc) · 5.62 KB
/
test.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
name: Run Tests
env:
GIT_AUTHOR_EMAIL: "[email protected]"
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
on:
pull_request:
branches:
- master
schedule:
- cron: "0 4 * * *"
concurrency:
group: unit-${{ github.head_ref }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-latest
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'
steps:
- name: Get GitHub App token
id: get_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ steps.get_token.outputs.token }}
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install pre-commit
run: python -m pip install pre-commit
- name: set PY
run: echo "PY=$(python -c 'import platform;print(platform.python_version())')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install Java
uses: actions/setup-java@v3
with:
java-version: "16"
distribution: "temurin"
cache: "maven"
- id: pre_commit
name: Run pre-commit
if: github.event.action != 'closed' && github.event.pull_request.merged != true
run: |
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
pre-commit run --verbose --from-ref "${FROM_REF}" --to-ref "${TO_REF}" --show-diff-on-failure --color=always
env:
FROM_REF: ${{ github.event.pull_request.base.sha }}
TO_REF: ${{ github.event.pull_request.head.sha }}
- name: Commit changes
if: ${{ failure() }}
run: |-
git add -A
git config user.name "${GIT_AUTHOR_NAME}"
git config user.email "${GIT_AUTHOR_EMAIL}"
git commit -m "pre-commit fixes"
git push origin "HEAD:${HEAD_REF}"
exit 1
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
- id: pre_commit_schedule
name: Run pre-commit in schedule
if: github.event_name == 'schedule'
run: |
pre-commit run --all-files --show-diff-on-failure --color=always
javadoc:
runs-on: ubuntu-latest
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'
steps:
- uses: actions/checkout@v3
- name: Install Java
uses: actions/setup-java@v3
with:
java-version: "8"
distribution: "temurin"
cache: "maven"
- name: Build javadoc
run: mvn javadoc:javadoc
shell: bash
test:
strategy:
matrix:
# see DEVELOPMENT.md for information why we're using this specific combination
# of JDKs to run unit tests on
java-version: ["8", "16", "18", "19"]
runs-on: ubuntu-latest
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'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Java
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
distribution: "temurin"
cache: "maven"
- name: Test
run: ./run-tests.sh
examples:
runs-on: ubuntu-latest
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'
steps:
- uses: actions/checkout@v3
- name: Install Java
uses: actions/setup-java@v3
with:
java-version: "16"
distribution: "temurin"
cache: "maven"
- name: Check examples
run: ./check-examples.sh
shell: bash
report:
runs-on: ubuntu-latest
if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
needs:
- test
- examples
- javadoc
steps:
- name: Get GitHub App token
if: github.event_name == 'pull_request'
id: get_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
repository: DataDog/datadog-api-spec
- name: Post status check
uses: DataDog/github-actions/post-status-check@v2
with:
github-token: ${{ steps.get_token.outputs.token }}
repo: datadog-api-spec
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' }}
context: unit