Run Tests #12635
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Tests | |
permissions: | |
contents: read | |
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 | |
shading: | |
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: Check all dependencies shaded | |
run: ./shade-test.sh | |
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 |