Skip to content

Commit 26d07d4

Browse files
committed
Contract workflow: dedupe drift issues and auto-close on recovery
1 parent c00f387 commit 26d07d4

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

0 commit comments

Comments
 (0)