Contract tests #112
This file contains hidden or 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: Contract tests | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| schedule: | |
| - cron: '0 6 * * *' | |
| repository_dispatch: | |
| types: [openapi-updated] | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| contract: | |
| name: validate parser against latest audd-openapi fixtures | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| path: audd-php | |
| - uses: actions/checkout@v4 | |
| with: | |
| repository: AudDMusic/audd-openapi | |
| path: audd-openapi | |
| ref: main | |
| - uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| coverage: none | |
| tools: composer:v2 | |
| - name: Composer install | |
| working-directory: audd-php | |
| run: composer install --prefer-dist --no-progress | |
| - name: Run contract tests | |
| working-directory: audd-php | |
| env: | |
| AUDD_OPENAPI_FIXTURES: ${{ github.workspace }}/audd-openapi/fixtures | |
| run: composer test-contract | |
| - 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' | |
| }); | |
| } |