Skip to content

test

test #1857

Workflow file for this run

name: test # The name must be the same as in test-docs.yml
on:
workflow_call:
inputs:
full-matrix:
description: "Run the full matrix"
required: true
type: boolean
ref:
description: "The git ref of elastic/apm-agent-python to run test workflow from."
required: false
type: string
pull_request:
paths-ignore:
- "**/*.md"
- "**/*.asciidoc"
push:
branches:
- main
paths-ignore:
- "**/*.md"
- "**/*.asciidoc"
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
inputs:
full-matrix:
description: "Run the full matrix"
required: true
type: boolean
permissions:
contents: read
jobs:
build-distribution:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build-distribution
create-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
data: ${{ steps.split.outputs.data }}
chunks: ${{ steps.split.outputs.chunks }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- id: generate
uses: elastic/oblt-actions/version-framework@v1
with:
# Use .ci/.matrix_python_full.yml if it's a scheduled workflow, otherwise use .ci/.matrix_python.yml
versions-file: .ci/.matrix_python${{ (github.event_name == 'schedule' || github.event_name == 'push' || inputs.full-matrix) && '_full' || '' }}.yml
# Use .ci/.matrix_framework_full.yml if it's a scheduled workflow, otherwise use .ci/.matrix_framework.yml
frameworks-file: .ci/.matrix_framework${{ (github.event_name == 'schedule' || github.event_name == 'push' || inputs.full-matrix) && '_full' || '' }}.yml
excluded-file: .ci/.matrix_exclude.yml
- name: Split matrix
shell: python
id: split
run: |
import os
import json
def split(lst, n):
return [lst[i::n] for i in range(n)]
matrix = json.loads(os.environ['GENERATED_MATRIX'])
# Using the number 4 because the full matrix has roughly 400+ items
# Hence, it is split into chunks of size ~100
# We are doing this because the matrix in GH actions has a max limit of 256
chunks = split(matrix['include'], 4)
chunks_json = json.dumps(chunks)
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
print(f'chunks={chunks_json}', file=f)
env:
GENERATED_MATRIX: ${{ steps.generate.outputs.matrix }}
chunks-0:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[0]) }}
chunks-1:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[1]) }}
chunks-2:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[2]) }}
chunks-3:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[3]) }}
windows:
name: "windows (version: ${{ matrix.version }}, framework: ${{ matrix.framework }}, asyncio: ${{ matrix.asyncio }})"
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
include:
# - version: "3.6"
# framework: "none"
# asyncio: "true"
# - version: "3.7"
# framework: none
# asyncio: true
- version: "3.8"
framework: none
asyncio: true
- version: "3.9" # waiting for greenlet to have binary wheels for 3.9
framework: none
asyncio: true
env:
VERSION: ${{ matrix.version }}
FRAMEWORK: ${{ matrix.framework }}
ASYNCIO: ${{ matrix.asyncio }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.version }}
cache: pip
cache-dependency-path: "tests/requirements/reqs-${{ matrix.framework }}.txt"
- name: Install tools
run: .\scripts\install-tools.bat
- name: Run tests
run: .\scripts\run-tests.bat
- if: success() || failure()
name: Upload JUnit Test Results
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.framework }}-${{ matrix.version }}-asyncio-${{ matrix.asyncio }}
path: "**/*-python-agent-junit.xml"
retention-days: 1
- if: success() || failure()
name: Upload Coverage Reports
uses: actions/upload-artifact@v4
with:
name: coverage-reports-${{ matrix.framework }}-${{ matrix.version }}-asyncio-${{ matrix.asyncio }}
path: "**/.coverage*"
retention-days: 1
# This job is here to have a single status check that can be set as required.
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds
# If a run contains a series of jobs that need each other, a failure applies to all jobs in the dependency chain from the point of failure onwards.
all:
if: always()
runs-on: ubuntu-latest
needs:
- chunks-0
- chunks-1
- chunks-2
- chunks-3
- windows
steps:
- id: check
uses: elastic/oblt-actions/check-dependent-jobs@v1
with:
jobs: ${{ toJSON(needs) }}
- run: ${{ steps.check.outputs.is-success }}
- if: failure() && (github.event_name == 'schedule' || github.event_name == 'push')
uses: elastic/oblt-actions/slack/notify-result@v1
with:
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
status: ${{ steps.check.outputs.status }}
channel-id: "#apm-agent-python"
coverage:
name: Combine & check coverage.
needs: all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-python@v5
with:
# Use latest Python, so it understands all syntax.
python-version: 3.11
- run: python -Im pip install --upgrade coverage[toml]
- uses: actions/download-artifact@v4
with:
pattern: coverage-reports-*
merge-multiple: true
- name: Combine coverage & fail if it's <84%.
run: |
python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
# Report and write to summary.
python -Im coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
# Report again and fail if under 84%.
python -Im coverage report --fail-under=84
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-coverage-report
path: htmlcov
- uses: geekyeggo/delete-artifact@f275313e70c08f6120db482d7a6b98377786765b # 5.1.0
with:
name: coverage-reports-*