Skip to content

Commit a267c93

Browse files
committed
Contract workflow: dedupe drift issues and auto-close on recovery
1 parent 9a317a6 commit a267c93

1 file changed

Lines changed: 45 additions & 10 deletions

File tree

.github/workflows/contract.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,48 @@ jobs:
4040
env:
4141
AUDD_OPENAPI_FIXTURES: ${{ github.workspace }}/audd-openapi/fixtures
4242
run: composer test-contract
43-
- name: Open issue on failure (dispatched runs only)
44-
if: failure() && github.event_name == 'repository_dispatch'
45-
env:
46-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47-
TRIGGER_SHA: ${{ github.event.client_payload.trigger_sha }}
48-
run: |
49-
gh issue create \
50-
--title "Contract drift: audd-openapi spec change broke parser" \
51-
--body "An openapi-updated dispatch (trigger SHA: $TRIGGER_SHA) caused contract tests to fail." \
52-
--label "contract-drift" || true
43+
- name: Report drift issue
44+
if: failure() && github.event_name != 'pull_request'
45+
uses: actions/github-script@v7
46+
with:
47+
script: |
48+
const { data: open } = await github.rest.issues.listForRepo({
49+
owner: context.repo.owner, repo: context.repo.repo,
50+
state: 'open', labels: 'contract-drift'
51+
});
52+
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
53+
if (open.length > 0) {
54+
await github.rest.issues.createComment({
55+
owner: context.repo.owner, repo: context.repo.repo,
56+
issue_number: open[0].number,
57+
body: `Still failing against the latest audd-openapi spec.\n\nRun: ${runUrl}`
58+
});
59+
} else {
60+
await github.rest.issues.create({
61+
owner: context.repo.owner, repo: context.repo.repo,
62+
title: `contract drift detected (${context.workflow})`,
63+
body: `Contract tests failed against the latest audd-openapi spec.\n\nRun: ${runUrl}`,
64+
labels: ['contract-drift']
65+
});
66+
}
67+
- name: Close drift issue on recovery
68+
if: success() && github.event_name != 'pull_request'
69+
uses: actions/github-script@v7
70+
with:
71+
script: |
72+
const { data: open } = await github.rest.issues.listForRepo({
73+
owner: context.repo.owner, repo: context.repo.repo,
74+
state: 'open', labels: 'contract-drift'
75+
});
76+
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
77+
for (const issue of open) {
78+
await github.rest.issues.createComment({
79+
owner: context.repo.owner, repo: context.repo.repo,
80+
issue_number: issue.number,
81+
body: `Contract tests are passing again — closing.\n\nRun: ${runUrl}`
82+
});
83+
await github.rest.issues.update({
84+
owner: context.repo.owner, repo: context.repo.repo,
85+
issue_number: issue.number, state: 'closed'
86+
});
87+
}

0 commit comments

Comments
 (0)