Skip to content

Commit 66d8535

Browse files
committed
Convert python testing workflow to reusable workflow
This PR is part of a larger initiative to standardize CI workflows across all Datadog API client repositories. By converting our Python testing workflow to a reusable workflow, we can: - **Enable centralized CI management**: The datadog-api-spec repo will be able to use the same testing workflow - **Prepare for MergeQueue**: Centralizing the CI in the datadog-api-spec repo is necessary to enable the MergeQueue ## Changes ### New Files - **`.github/workflows/reusable-python-test.yml`**: A reusable workflow that contains the same logic as the original test workflow ### Modified Files - **`.github/workflows/test.yml`**: Simplified to call the reusable workflow ### Key Design Decisions - **Behavior preservation**: Every aspect of the original workflow is maintained through input parameters - **Configurability**: The reusable workflow accepts inputs for all major parameters (Python versions, platforms, matrix exclusions) - **Environment variables**: Git author information is inherited from the caller workflow
1 parent 5453d0b commit 66d8535

File tree

2 files changed

+118
-79
lines changed

2 files changed

+118
-79
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Reusable Python Testing Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
python-versions:
7+
description: 'JSON array of Python versions to test against'
8+
required: false
9+
type: string
10+
default: '["3.8", "3.12"]'
11+
platforms:
12+
description: 'JSON array of platforms to run tests on'
13+
required: false
14+
type: string
15+
default: '["ubuntu-22.04", "ubuntu-latest", "macos-latest"]'
16+
matrix-exclude:
17+
description: 'JSON array of matrix combinations to exclude'
18+
required: false
19+
type: string
20+
default: '[{"platform": "macos-latest", "python-version": "3.8"}, {"platform": "ubuntu-latest", "python-version": "3.8"}, {"platform": "ubuntu-22.04", "python-version": "3.12"}]'
21+
enable-status-reporting:
22+
description: 'Whether to post status checks to datadog-api-spec repo'
23+
required: false
24+
type: boolean
25+
default: false
26+
status-context:
27+
description: 'Context for status checks'
28+
required: false
29+
type: string
30+
default: 'master/unit'
31+
secrets:
32+
PIPELINE_GITHUB_APP_ID:
33+
required: false
34+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
35+
required: false
36+
37+
jobs:
38+
test:
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
python-version: ${{ fromJSON(inputs.python-versions) }}
43+
platform: ${{ fromJSON(inputs.platforms) }}
44+
exclude: ${{ fromJSON(inputs.matrix-exclude) }}
45+
runs-on: ${{ matrix.platform }}
46+
steps:
47+
- uses: actions/checkout@v3
48+
- name: Set up Python ${{ matrix.python-version }}
49+
uses: actions/setup-python@v4
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
cache: "pip"
53+
- name: Upgrade pip
54+
run: |
55+
python -m pip install --upgrade pip
56+
pip install --upgrade wheel setuptools build
57+
- name: Install
58+
run: pip install --disable-pip-version-check -e .[tests]
59+
- name: Test
60+
run: ./run-tests.sh
61+
shell: bash
62+
63+
examples:
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v3
67+
- name: Install Python
68+
uses: actions/setup-python@v4
69+
with:
70+
python-version: "3.12"
71+
cache: "pip"
72+
- name: Upgrade pip
73+
run: |
74+
python -m pip install --upgrade pip
75+
pip install --upgrade wheel setuptools build
76+
- name: Install
77+
run: pip install --disable-pip-version-check pyflakes
78+
- name: Check examples
79+
run: ./check-examples.sh
80+
shell: bash
81+
82+
report:
83+
runs-on: ubuntu-latest
84+
if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && inputs.enable-status-reporting
85+
needs:
86+
- test
87+
- examples
88+
steps:
89+
- name: Get GitHub App token
90+
if: github.event_name == 'pull_request'
91+
id: get_token
92+
uses: actions/create-github-app-token@v1
93+
with:
94+
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
95+
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
96+
repositories: datadog-api-spec
97+
- name: Post status check
98+
uses: DataDog/github-actions/post-status-check@v2
99+
with:
100+
github-token: ${{ steps.get_token.outputs.token }}
101+
repo: datadog-api-spec
102+
status: ${{ (needs.test.result == 'cancelled' || needs.examples.result == 'cancelled') && 'pending' || needs.test.result == 'success' && needs.examples.result == 'success' && 'success' || 'failure' }}
103+
context: ${{ inputs.status-context }}

.github/workflows/test.yml

Lines changed: 15 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -75,82 +75,18 @@ jobs:
7575
pre-commit run --all-files --show-diff-on-failure --color=always
7676
7777
test:
78-
strategy:
79-
fail-fast: false
80-
matrix:
81-
python-version: ["3.8", "3.12"]
82-
platform: [ubuntu-22.04, ubuntu-latest, macos-latest] # windows-latest
83-
# test only latest version on macos and windows
84-
exclude:
85-
- platform: macos-latest
86-
python-version: "3.8"
87-
- platform: ubuntu-latest
88-
python-version: "3.8"
89-
- platform: ubuntu-22.04
90-
python-version: "3.12"
91-
# TODO enable once dd-trace-py is updated
92-
# - platform: windows-latest
93-
# python-version: 3.8
94-
# - platform: windows-latest
95-
# python-version: 3.8
96-
runs-on: ${{ matrix.platform }}
97-
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'
98-
steps:
99-
- uses: actions/checkout@v3
100-
- name: Set up Python ${{ matrix.python-version }}
101-
uses: actions/setup-python@v4
102-
with:
103-
python-version: ${{ matrix.python-version }}
104-
cache: "pip"
105-
- name: Upgrade pip
106-
run: |
107-
python -m pip install --upgrade pip
108-
pip install --upgrade wheel setuptools build
109-
- name: Install
110-
run: pip install --disable-pip-version-check -e .[tests]
111-
- name: Test
112-
run: ./run-tests.sh
113-
shell: bash
114-
115-
examples:
116-
runs-on: ubuntu-latest
117-
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'
118-
steps:
119-
- uses: actions/checkout@v3
120-
- name: Install Python
121-
uses: actions/setup-python@v4
122-
with:
123-
python-version: "3.12"
124-
cache: "pip"
125-
- name: Upgrade pip
126-
run: |
127-
python -m pip install --upgrade pip
128-
pip install --upgrade wheel setuptools build
129-
- name: Install
130-
run: pip install --disable-pip-version-check pyflakes
131-
- name: Check examples
132-
run: ./check-examples.sh
133-
shell: bash
134-
135-
report:
136-
runs-on: ubuntu-latest
137-
if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
138-
needs:
139-
- test
140-
- examples
141-
steps:
142-
- name: Get GitHub App token
143-
if: github.event_name == 'pull_request'
144-
id: get_token
145-
uses: actions/create-github-app-token@v1
146-
with:
147-
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
148-
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
149-
repositories: datadog-api-spec
150-
- name: Post status check
151-
uses: DataDog/github-actions/post-status-check@v2
152-
with:
153-
github-token: ${{ steps.get_token.outputs.token }}
154-
repo: datadog-api-spec
155-
status: ${{ (needs.test.result == 'cancelled' || needs.examples.result == 'cancelled') && 'pending' || needs.test.result == 'success' && needs.examples.result == 'success' && 'success' || 'failure' }}
156-
context: master/unit
78+
if: >
79+
(github.event.pull_request.draft == false &&
80+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
81+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
82+
github.event_name == 'schedule'
83+
uses: ./.github/workflows/reusable-python-test.yml
84+
with:
85+
python-versions: '["3.8", "3.12"]'
86+
platforms: '["ubuntu-22.04", "ubuntu-latest", "macos-latest"]'
87+
matrix-exclude: '[{"platform": "macos-latest", "python-version": "3.8"}, {"platform": "ubuntu-latest", "python-version": "3.8"}, {"platform": "ubuntu-22.04", "python-version": "3.12"}]'
88+
enable-status-reporting: true
89+
status-context: 'master/unit'
90+
secrets:
91+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
92+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}

0 commit comments

Comments
 (0)