Skip to content

Contract tests

Contract tests #115

Workflow file for this run

name: Contract tests
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 6 * * *' # daily at 06:00 UTC
repository_dispatch:
types: [openapi-updated]
jobs:
contract:
name: validate parser against latest audd-openapi fixtures
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: audd-python
- name: Check out audd-openapi
uses: actions/checkout@v4
with:
repository: AudDMusic/audd-openapi
path: audd-openapi
ref: main
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: audd-python/pyproject.toml
- name: Install
working-directory: audd-python
run: pip install -e '.[dev]'
- name: Run contract tests
working-directory: audd-python
env:
AUDD_OPENAPI_FIXTURES: ${{ github.workspace }}/audd-openapi/fixtures
run: python -m pytest tests/contract/ -v --tb=short
- name: Report drift issue
if: failure() && github.event_name != 'pull_request'
uses: actions/github-script@v7
with:
script: |
const { data: open } = await github.rest.issues.listForRepo({
owner: context.repo.owner, repo: context.repo.repo,
state: 'open', labels: 'contract-drift'
});
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
if (open.length > 0) {
await github.rest.issues.createComment({
owner: context.repo.owner, repo: context.repo.repo,
issue_number: open[0].number,
body: `Still failing against the latest audd-openapi spec.\n\nRun: ${runUrl}`
});
} else {
await github.rest.issues.create({
owner: context.repo.owner, repo: context.repo.repo,
title: `contract drift detected (${context.workflow})`,
body: `Contract tests failed against the latest audd-openapi spec.\n\nRun: ${runUrl}`,
labels: ['contract-drift']
});
}
- name: Close drift issue on recovery
if: success() && github.event_name != 'pull_request'
uses: actions/github-script@v7
with:
script: |
const { data: open } = await github.rest.issues.listForRepo({
owner: context.repo.owner, repo: context.repo.repo,
state: 'open', labels: 'contract-drift'
});
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
for (const issue of open) {
await github.rest.issues.createComment({
owner: context.repo.owner, repo: context.repo.repo,
issue_number: issue.number,
body: `Contract tests are passing again — closing.\n\nRun: ${runUrl}`
});
await github.rest.issues.update({
owner: context.repo.owner, repo: context.repo.repo,
issue_number: issue.number, state: 'closed'
});
}