Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/reusable-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Reusable Complete CI Workflow

on:
workflow_call:
inputs:
target-branch:
description: 'Branch to checkout and test (defaults to the calling branch)'
required: false
type: string
default: ''
python-versions:
description: 'JSON array of Python versions to test against'
required: false
type: string
default: '["3.8", "3.12"]'
platforms:
description: 'JSON array of platforms to run tests on'
required: false
type: string
default: '["ubuntu-22.04", "ubuntu-latest", "macos-latest"]'
matrix-exclude:
description: 'JSON array of matrix combinations to exclude'
required: false
type: string
default: '[{"platform": "macos-latest", "python-version": "3.8"}, {"platform": "ubuntu-latest", "python-version": "3.8"}, {"platform": "ubuntu-22.04", "python-version": "3.12"}]'
secrets:
PIPELINE_GITHUB_APP_ID:
required: false
PIPELINE_GITHUB_APP_PRIVATE_KEY:
required: false
# Integration test secrets
DD_API_KEY:
required: false
DD_CLIENT_API_KEY:
required: false
DD_CLIENT_APP_KEY:
required: false
SLEEP_AFTER_REQUEST:
required: false

jobs:
pre-commit:
uses: ./.github/workflows/reusable-pre-commit.yml
with:
target-branch: ${{ inputs.target-branch }}
enable-commit-changes: false # Don't auto-commit in external CI
secrets:
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}

test:
uses: ./.github/workflows/reusable-python-test.yml
with:
target-branch: ${{ inputs.target-branch }}
python-versions: ${{ inputs.python-versions }}
platforms: ${{ inputs.platforms }}
matrix-exclude: ${{ inputs.matrix-exclude }}
secrets:
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}

examples:
uses: ./.github/workflows/reusable-examples.yml
with:
target-branch: ${{ inputs.target-branch }}

integration:
uses: ./.github/workflows/reusable-integration-test.yml
with:
target-branch: ${{ inputs.target-branch }}
secrets:
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
DD_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }}
DD_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }}
SLEEP_AFTER_REQUEST: ${{ secrets.SLEEP_AFTER_REQUEST }}

48 changes: 48 additions & 0 deletions .github/workflows/reusable-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Reusable Examples Workflow

on:
workflow_call:
inputs:
target-branch:
description: 'Branch to checkout and test (defaults to the calling branch)'
required: false
type: string
default: ''
examples-script:
description: 'Examples script to execute'
required: false
type: string
default: './check-examples.sh'
python-version:
description: 'Python version to use'
required: false
type: string
default: '3.12'

jobs:
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
with:
repository: DataDog/datadog-api-client-python
ref: ${{ inputs.target-branch || github.ref }}
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
cache: "pip"
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
pip install --upgrade wheel setuptools build
- name: Install
run: pip install --disable-pip-version-check pyflakes
- name: Check examples
run: ${{ inputs.examples-script }}
shell: bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Integration Tests
name: Reusable Integration Test Workflow

permissions:
contents: read
Expand All @@ -16,6 +16,41 @@ on:
- master
schedule:
- cron: "0 1 * * *"
workflow_call:
inputs:
target-branch:
description: 'Branch to checkout and test (defaults to the calling branch)'
required: false
type: string
default: ''
enable-status-reporting:
description: 'Whether to post status checks to datadog-api-spec repo'
required: false
type: boolean
default: false
status-context:
description: 'Context for status checks'
required: false
type: string
default: 'integration'
target-repo:
description: 'Repository to post status to'
required: false
type: string
default: 'datadog-api-spec'
secrets:
PIPELINE_GITHUB_APP_ID:
required: false
PIPELINE_GITHUB_APP_PRIVATE_KEY:
required: false
DD_API_KEY:
required: true
DD_CLIENT_API_KEY:
required: true
DD_CLIENT_APP_KEY:
required: true
SLEEP_AFTER_REQUEST:
required: false

concurrency:
group: integration-${{ github.head_ref }}
Expand Down Expand Up @@ -48,17 +83,20 @@ jobs:
with:
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
repositories: datadog-api-spec
repositories: ${{ inputs.target-repo || 'datadog-api-spec' }}
- name: Checkout code
uses: actions/checkout@v3
with:
repository: DataDog/datadog-api-client-python
ref: ${{ inputs.target-branch || github.ref }}
- name: Post pending status check
if: github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
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')
uses: DataDog/github-actions/post-status-check@v2
with:
github-token: ${{ steps.get_token.outputs.token }}
repo: datadog-api-spec
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
status: pending
context: integration
context: ${{ inputs.status-context || 'integration' }}
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -86,18 +124,18 @@ jobs:
DD_PYTEST_OPERATION_NAME: "test"
DD_TRACE_PROPAGATION_STYLE_INJECT: "datadog"
- name: Post failure status check
if: failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
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')
uses: DataDog/github-actions/post-status-check@v2
with:
github-token: ${{ steps.get_token.outputs.token }}
repo: datadog-api-spec
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
status: failure
context: integration
context: ${{ inputs.status-context || 'integration' }}
- name: Post success status check
if: "!failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')"
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')"
uses: DataDog/github-actions/post-status-check@v2
with:
github-token: ${{ steps.get_token.outputs.token }}
repo: datadog-api-spec
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
status: success
context: integration
context: ${{ inputs.status-context || 'integration' }}
82 changes: 82 additions & 0 deletions .github/workflows/reusable-pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Reusable Pre-commit Workflow

on:
workflow_call:
inputs:
target-branch:
description: 'Branch to checkout and test (defaults to the calling branch)'
required: false
type: string
default: ''
enable-commit-changes:
description: 'Whether to commit and push pre-commit fixes'
required: false
type: boolean
default: true
secrets:
PIPELINE_GITHUB_APP_ID:
required: false
PIPELINE_GITHUB_APP_PRIVATE_KEY:
required: false

env:
GIT_AUTHOR_EMAIL: "[email protected]"
GIT_AUTHOR_NAME: "ci.datadog-api-spec"

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
if: inputs.enable-commit-changes
uses: actions/create-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
repository: DataDog/datadog-api-client-python
ref: ${{ inputs.target-branch || github.event.pull_request.head.sha || github.ref }}
token: ${{ inputs.enable-commit-changes && steps.get_token.outputs.token || github.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') }}
- id: pre_commit
name: Run pre-commit
if: github.event.action != 'closed' && github.event.pull_request.merged != true
run: |
pre-commit run --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() && inputs.enable-commit-changes }}
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
59 changes: 59 additions & 0 deletions .github/workflows/reusable-python-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Reusable Python Testing Workflow

on:
workflow_call:
inputs:
target-branch:
description: 'Branch to checkout and test (defaults to the calling branch)'
required: false
type: string
default: ''
python-versions:
description: 'JSON array of Python versions to test against'
required: false
type: string
default: '["3.8", "3.12"]'
platforms:
description: 'JSON array of platforms to run tests on'
required: false
type: string
default: '["ubuntu-22.04", "ubuntu-latest", "macos-latest"]'
matrix-exclude:
description: 'JSON array of matrix combinations to exclude'
required: false
type: string
default: '[{"platform": "macos-latest", "python-version": "3.8"}, {"platform": "ubuntu-latest", "python-version": "3.8"}, {"platform": "ubuntu-22.04", "python-version": "3.12"}]'
secrets:
PIPELINE_GITHUB_APP_ID:
required: false
PIPELINE_GITHUB_APP_PRIVATE_KEY:
required: false

jobs:
test:
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(inputs.python-versions) }}
platform: ${{ fromJSON(inputs.platforms) }}
exclude: ${{ fromJSON(inputs.matrix-exclude) }}
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
with:
repository: DataDog/datadog-api-client-python
ref: ${{ inputs.target-branch || github.ref }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
pip install --upgrade wheel setuptools build
- name: Install
run: pip install --disable-pip-version-check -e .[tests]
- name: Test
run: ./run-tests.sh
shell: bash
Loading
Loading