@plainconceptsplatform/workflows 0.5.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -88
- package/dist/catalog-installation.d.ts +67 -0
- package/dist/catalog-installation.js +485 -0
- package/dist/catalog-listing.d.ts +13 -0
- package/dist/catalog-listing.js +70 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +273 -0
- package/dist/package-baseline.d.ts +25 -0
- package/dist/package-baseline.js +138 -0
- package/dist/repository-inspection.d.ts +23 -0
- package/dist/repository-inspection.js +113 -0
- package/dist/route-processing.d.ts +4 -0
- package/dist/route-processing.js +80 -0
- package/dist/stack-defaults.d.ts +11 -0
- package/dist/stack-defaults.js +110 -0
- package/dist/tui.d.ts +25 -0
- package/dist/tui.js +271 -0
- package/dist/worker-env.d.ts +46 -0
- package/dist/worker-env.js +179 -0
- package/dist/workflow-catalog.d.ts +27 -0
- package/dist/workflow-catalog.js +57 -0
- package/loops/actions/add-issue-labels/action.yml +22 -2
- package/loops/actions/apply-agent-bundle/apply-bundle.sh +14 -1
- package/loops/actions/audit-close/action.yml +180 -128
- package/loops/actions/classify-route/action.yml +7 -0
- package/loops/actions/classify-route/classify-route.sh +28 -7
- package/loops/actions/cleanup-artifacts/action.yml +38 -12
- package/loops/actions/housekeeping/action.yml +251 -0
- package/loops/actions/identify-gate-subject/action.yml +3 -1
- package/loops/actions/merge-agent-pr/action.yml +13 -0
- package/loops/actions/remove-issue-labels/action.yml +4 -2
- package/loops/actions/report-workflow-errors/action.yml +385 -0
- package/loops/actions/validate-merge-gate-output/validate-merge-gate-output.sh +13 -1
- package/loops/actions/validate-refine-output/validate-refine-output.sh +18 -2
- package/loops/actions/validate-triage-output/action.yml +1 -1
- package/loops/actions/validate-triage-output/validate-triage-output.sh +9 -5
- package/loops/actions/verify-composite-actions/verify-composite-actions.sh +53 -0
- package/loops/actions/verify-refine-output/verify-refine-output.sh +20 -0
- package/loops/actions/verify-route-matrix/verify-route-matrix.sh +1017 -56
- package/loops/scripts/compile-agent-workflows.mjs +96 -1
- package/loops/scripts/merge-changelog.mjs +76 -0
- package/loops/templates/agentics/actionlint.yaml +13 -0
- package/loops/templates/agentics/agentics-checks.yml +203 -86
- package/loops/templates/agentics/agentics-error-report.yml +97 -0
- package/loops/templates/ci/app-ci-dotnet-next.yml +64 -2
- package/loops/templates/ci/app-ci-node-monorepo.yml +52 -0
- package/loops/templates/opencode/opencode.ci.json +3 -3
- package/loops/templates/opencode/opencode.ci.json.md +4 -1
- package/loops/workflows/agent-apply-review.md +452 -465
- package/loops/workflows/agent-audit.md +201 -213
- package/loops/workflows/agent-implement.md +616 -538
- package/loops/workflows/agent-merge-gate.md +830 -730
- package/loops/workflows/agent-refine.md +599 -609
- package/loops/workflows/agent-release.md +244 -258
- package/loops/workflows/agent-triage.md +476 -447
- package/loops/workflows/authorize-bot-work.yml +26 -6
- package/loops/workflows/work-router.yml +1185 -862
- package/package.json +9 -8
- package/loops/actions/stale-recovery/action.yml +0 -288
- package/loops/actions/update-changelog/action.yml +0 -113
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plainconceptsplatform/workflows",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Install and update Platform GitHub agentic workflows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github-actions",
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
"loops",
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc --project tsconfig.build.json",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
32
|
+
"release": "pnpm build && pnpm test && npm publish --access public",
|
|
33
|
+
"prepack": "node ./scripts/copy-loops.mjs"
|
|
34
|
+
},
|
|
28
35
|
"engines": {
|
|
29
36
|
"node": ">=20.19"
|
|
30
37
|
},
|
|
@@ -33,11 +40,5 @@
|
|
|
33
40
|
"typescript": "^5.8.0",
|
|
34
41
|
"vitest": "^3.0.0",
|
|
35
42
|
"yaml": "^2.9.0"
|
|
36
|
-
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "tsc --project tsconfig.json",
|
|
39
|
-
"test": "vitest run",
|
|
40
|
-
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
41
|
-
"release": "pnpm build && pnpm test && npm publish --access public"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
# Managed by @plainconceptsplatform/workflows. Source: loops/actions/stale-recovery/action.yml. Update with workflows update --force; consumer edits may be overwritten.
|
|
2
|
-
name: Recover stale agent work
|
|
3
|
-
description: Reconcile Refine, Implement, and Merge Gate claims whose bot-working label has outlived the staleness threshold, and dispatch merge-gate for bot PRs with failed CI.
|
|
4
|
-
inputs:
|
|
5
|
-
token:
|
|
6
|
-
description: GitHub token with issues write and pull-requests read access.
|
|
7
|
-
required: true
|
|
8
|
-
stale-threshold-hours:
|
|
9
|
-
description: Hours after which a bot-working claim is stale. Invalid or empty values use 2.
|
|
10
|
-
required: false
|
|
11
|
-
default: ''
|
|
12
|
-
refine-marker:
|
|
13
|
-
description: Marker identifying the comment a Refine run posts when it asks the author a question.
|
|
14
|
-
required: false
|
|
15
|
-
default: '<!-- agent-refine -->'
|
|
16
|
-
working-label:
|
|
17
|
-
description: Label marking an issue the bot currently owns.
|
|
18
|
-
required: false
|
|
19
|
-
default: bot-working
|
|
20
|
-
refine-label:
|
|
21
|
-
description: Label marking an issue queued for refinement.
|
|
22
|
-
required: false
|
|
23
|
-
default: refine
|
|
24
|
-
direct-label:
|
|
25
|
-
description: Label marking an issue with a free-form direct instruction.
|
|
26
|
-
required: false
|
|
27
|
-
default: direct
|
|
28
|
-
implement-label:
|
|
29
|
-
description: Label marking an issue queued for implementation.
|
|
30
|
-
required: false
|
|
31
|
-
default: implement
|
|
32
|
-
review-label:
|
|
33
|
-
description: Label marking an issue that needs a human.
|
|
34
|
-
required: false
|
|
35
|
-
default: review
|
|
36
|
-
ci-workflow-name:
|
|
37
|
-
description: Name of the CI workflow whose failure should trigger a merge-gate dispatch.
|
|
38
|
-
required: false
|
|
39
|
-
default: 'App: CI'
|
|
40
|
-
router-workflow-name:
|
|
41
|
-
description: Name of the work router workflow to dispatch.
|
|
42
|
-
required: false
|
|
43
|
-
default: 'All Work Router'
|
|
44
|
-
runs:
|
|
45
|
-
using: composite
|
|
46
|
-
steps:
|
|
47
|
-
- name: Reconcile stale claims
|
|
48
|
-
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
|
49
|
-
env:
|
|
50
|
-
STALE_THRESHOLD_HOURS: ${{ inputs.stale-threshold-hours }}
|
|
51
|
-
REFINE_MARKER: ${{ inputs.refine-marker }}
|
|
52
|
-
WORKING_LABEL: ${{ inputs.working-label }}
|
|
53
|
-
REFINE_LABEL: ${{ inputs.refine-label }}
|
|
54
|
-
DIRECT_LABEL: ${{ inputs.direct-label }}
|
|
55
|
-
IMPLEMENT_LABEL: ${{ inputs.implement-label }}
|
|
56
|
-
REVIEW_LABEL: ${{ inputs.review-label }}
|
|
57
|
-
CI_WORKFLOW_NAME: ${{ inputs.ci-workflow-name }}
|
|
58
|
-
ROUTER_WORKFLOW_NAME: ${{ inputs.router-workflow-name }}
|
|
59
|
-
with:
|
|
60
|
-
github-token: ${{ inputs.token }}
|
|
61
|
-
script: |
|
|
62
|
-
const WORKING = process.env.WORKING_LABEL;
|
|
63
|
-
const REVIEW = process.env.REVIEW_LABEL;
|
|
64
|
-
const MARKER = process.env.REFINE_MARKER;
|
|
65
|
-
const CI_WORKFLOW_NAME = process.env.CI_WORKFLOW_NAME;
|
|
66
|
-
const ROUTER_WORKFLOW_NAME = process.env.ROUTER_WORKFLOW_NAME;
|
|
67
|
-
|
|
68
|
-
const parsedHours = Number.parseInt(process.env.STALE_THRESHOLD_HOURS, 10);
|
|
69
|
-
const hours = Number.isInteger(parsedHours) && parsedHours > 0 ? parsedHours : 2;
|
|
70
|
-
const cutoff = new Date(Date.now() - hours * 60 * 60 * 1000);
|
|
71
|
-
|
|
72
|
-
core.info(`Stale threshold: ${hours}h (cutoff ${cutoff.toISOString()})`);
|
|
73
|
-
|
|
74
|
-
const staleIssuesLabelled = async (label) => {
|
|
75
|
-
const issues = await github.paginate(github.rest.issues.listForRepo, {
|
|
76
|
-
...context.repo,
|
|
77
|
-
state: 'open',
|
|
78
|
-
labels: `${WORKING},${label}`,
|
|
79
|
-
per_page: 100,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
return issues.filter((issue) => new Date(issue.updated_at) < cutoff);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const removeWorking = async (issueNumber) => {
|
|
86
|
-
try {
|
|
87
|
-
await github.rest.issues.removeLabel({
|
|
88
|
-
...context.repo,
|
|
89
|
-
issue_number: issueNumber,
|
|
90
|
-
name: WORKING,
|
|
91
|
-
});
|
|
92
|
-
} catch (error) {
|
|
93
|
-
if (error.status !== 404) throw error;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// Open bot pull requests keep work in flight. GraphQL exposes authorship and closing
|
|
98
|
-
// references together, so use `__typename` instead of matching a login.
|
|
99
|
-
const openPullRequests = [];
|
|
100
|
-
|
|
101
|
-
for (let cursor = null; ; ) {
|
|
102
|
-
const page = await github.graphql(
|
|
103
|
-
`query($owner: String!, $name: String!, $cursor: String) {
|
|
104
|
-
repository(owner: $owner, name: $name) {
|
|
105
|
-
pullRequests(states: OPEN, first: 100, after: $cursor) {
|
|
106
|
-
pageInfo { hasNextPage endCursor }
|
|
107
|
-
nodes {
|
|
108
|
-
number
|
|
109
|
-
updatedAt
|
|
110
|
-
author { __typename }
|
|
111
|
-
closingIssuesReferences(first: 10) {
|
|
112
|
-
nodes { number labels(first: 20) { nodes { name } } }
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}`,
|
|
118
|
-
{ owner: context.repo.owner, name: context.repo.repo, cursor },
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const { nodes, pageInfo } = page.repository.pullRequests;
|
|
122
|
-
openPullRequests.push(...nodes);
|
|
123
|
-
|
|
124
|
-
if (!pageInfo.hasNextPage) break;
|
|
125
|
-
cursor = pageInfo.endCursor;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const botPullRequests = openPullRequests.filter(
|
|
129
|
-
(pr) => pr.author?.__typename === 'Bot',
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const issuesWithOpenBotPr = new Set(
|
|
133
|
-
botPullRequests.flatMap((pr) => pr.closingIssuesReferences.nodes.map((n) => n.number)),
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const summary = {
|
|
137
|
-
refineEscalated: 0,
|
|
138
|
-
refineAwaitingAuthor: 0,
|
|
139
|
-
implementReleased: 0,
|
|
140
|
-
directReleased: 0,
|
|
141
|
-
mergeGateReleased: 0,
|
|
142
|
-
mergeGateDispatched: 0,
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
for (const issue of await staleIssuesLabelled(process.env.REFINE_LABEL)) {
|
|
146
|
-
const comments = await github.paginate(github.rest.issues.listComments, {
|
|
147
|
-
...context.repo,
|
|
148
|
-
issue_number: issue.number,
|
|
149
|
-
per_page: 100,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const lastMarker = comments.filter((c) => (c.body ?? '').includes(MARKER)).pop();
|
|
153
|
-
const lastHuman = comments.filter((c) => c.user?.type !== 'Bot').pop();
|
|
154
|
-
|
|
155
|
-
// The bot asked a question nobody has answered yet. Escalating would drop the
|
|
156
|
-
// question on the floor, so leave the claim in place.
|
|
157
|
-
if (lastMarker && !(lastHuman && new Date(lastHuman.created_at) > new Date(lastMarker.created_at))) {
|
|
158
|
-
core.info(`#${issue.number}: awaiting author reply, left alone`);
|
|
159
|
-
summary.refineAwaitingAuthor += 1;
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
await removeWorking(issue.number);
|
|
164
|
-
await github.rest.issues.addLabels({
|
|
165
|
-
...context.repo,
|
|
166
|
-
issue_number: issue.number,
|
|
167
|
-
labels: [REVIEW],
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
core.info(`#${issue.number}: escalated to ${REVIEW}`);
|
|
171
|
-
summary.refineEscalated += 1;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
for (const issue of await staleIssuesLabelled(process.env.IMPLEMENT_LABEL)) {
|
|
175
|
-
if (issuesWithOpenBotPr.has(issue.number)) {
|
|
176
|
-
core.info(`#${issue.number}: open bot pull request still in flight, left alone`);
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
await removeWorking(issue.number);
|
|
181
|
-
core.info(`#${issue.number}: released`);
|
|
182
|
-
summary.implementReleased += 1;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
for (const issue of await staleIssuesLabelled(process.env.DIRECT_LABEL)) {
|
|
186
|
-
if (issuesWithOpenBotPr.has(issue.number)) {
|
|
187
|
-
core.info(`#${issue.number}: open bot pull request still in flight, left alone`);
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
await removeWorking(issue.number);
|
|
192
|
-
await github.rest.issues.addLabels({
|
|
193
|
-
...context.repo,
|
|
194
|
-
issue_number: issue.number,
|
|
195
|
-
labels: [REVIEW],
|
|
196
|
-
});
|
|
197
|
-
core.info(`#${issue.number}: direct released, escalated to ${REVIEW}`);
|
|
198
|
-
summary.directReleased += 1;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
for (const pr of botPullRequests.filter((p) => new Date(p.updatedAt) < cutoff)) {
|
|
202
|
-
for (const issue of pr.closingIssuesReferences.nodes) {
|
|
203
|
-
if (!issue.labels.nodes.some((label) => label.name === WORKING)) {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
await removeWorking(issue.number);
|
|
208
|
-
core.info(`PR #${pr.number} / issue #${issue.number}: released`);
|
|
209
|
-
summary.mergeGateReleased += 1;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// The workflow_run trigger does not fire for PR-triggered CI completions on
|
|
214
|
-
// feature branches. This polls every stale-recovery cycle (2h) for bot PRs
|
|
215
|
-
// whose CI concluded failure and dispatches the merge-gate, which is the same
|
|
216
|
-
// thing the workflow_run trigger would have done. A run already in progress
|
|
217
|
-
// for the same PR is skipped by the router's concurrency group.
|
|
218
|
-
const ciWorkflow = await github.rest.actions.getWorkflow({
|
|
219
|
-
...context.repo,
|
|
220
|
-
workflow_id: CI_WORKFLOW_NAME,
|
|
221
|
-
}).catch(() => null);
|
|
222
|
-
|
|
223
|
-
if (ciWorkflow) {
|
|
224
|
-
for (const pr of botPullRequests) {
|
|
225
|
-
const runs = await github.rest.actions.listWorkflowRuns({
|
|
226
|
-
...context.repo,
|
|
227
|
-
workflow_id: CI_WORKFLOW_NAME,
|
|
228
|
-
branch: pr.number.toString(),
|
|
229
|
-
status: 'completed',
|
|
230
|
-
per_page: 1,
|
|
231
|
-
}).catch(() => ({ data: { workflow_runs: [] } }));
|
|
232
|
-
|
|
233
|
-
const latestRun = runs.data.workflow_runs[0];
|
|
234
|
-
if (!latestRun || latestRun.conclusion !== 'failure') continue;
|
|
235
|
-
|
|
236
|
-
// Skip if the issue already carries review (the agent already gave up).
|
|
237
|
-
const issueNumbers = pr.closingIssuesReferences.nodes.map((n) => n.number);
|
|
238
|
-
const hasReview = await Promise.all(
|
|
239
|
-
issueNumbers.map(async (n) => {
|
|
240
|
-
const labels = await github.rest.issues.listLabelsOnIssue({
|
|
241
|
-
...context.repo,
|
|
242
|
-
issue_number: n,
|
|
243
|
-
}).catch(() => ({ data: [] }));
|
|
244
|
-
return labels.data.some((l) => l.name === REVIEW);
|
|
245
|
-
}),
|
|
246
|
-
);
|
|
247
|
-
if (hasReview.some(Boolean)) continue;
|
|
248
|
-
|
|
249
|
-
const routerWorkflow = await github.rest.actions.getWorkflow({
|
|
250
|
-
...context.repo,
|
|
251
|
-
workflow_id: ROUTER_WORKFLOW_NAME,
|
|
252
|
-
}).catch(() => null);
|
|
253
|
-
|
|
254
|
-
if (routerWorkflow) {
|
|
255
|
-
// Resolve the linked issue number for the dispatch.
|
|
256
|
-
const linkedIssue = issueNumbers[0];
|
|
257
|
-
if (!linkedIssue) continue;
|
|
258
|
-
|
|
259
|
-
await github.rest.actions.createWorkflowDispatch({
|
|
260
|
-
...context.repo,
|
|
261
|
-
workflow_id: ROUTER_WORKFLOW_NAME,
|
|
262
|
-
ref: 'main',
|
|
263
|
-
inputs: {
|
|
264
|
-
operation: 'merge-gate',
|
|
265
|
-
'pr-number': pr.number.toString(),
|
|
266
|
-
'ci-conclusion': 'failure',
|
|
267
|
-
'ci-run-id': latestRun.id.toString(),
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
core.info(`PR #${pr.number}: dispatched merge-gate for failed CI (run ${latestRun.id})`);
|
|
272
|
-
summary.mergeGateDispatched += 1;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
await core.summary
|
|
278
|
-
.addHeading('Stale recovery', 2)
|
|
279
|
-
.addList([
|
|
280
|
-
`Threshold: ${hours} hours (cutoff ${cutoff.toISOString()})`,
|
|
281
|
-
`Refine escalated to ${REVIEW}: ${summary.refineEscalated}`,
|
|
282
|
-
`Refine awaiting author: ${summary.refineAwaitingAuthor}`,
|
|
283
|
-
`Implement released: ${summary.implementReleased}`,
|
|
284
|
-
`Direct released: ${summary.directReleased}`,
|
|
285
|
-
`Merge Gate released: ${summary.mergeGateReleased}`,
|
|
286
|
-
`Merge Gate dispatched for failed CI: ${summary.mergeGateDispatched}`,
|
|
287
|
-
])
|
|
288
|
-
.write();
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
# Managed by @plainconceptsplatform/workflows. Source: loops/actions/update-changelog/action.yml. Update with `workflows update --force`; consumer edits may be overwritten.
|
|
2
|
-
name: Update changelog
|
|
3
|
-
description: Prepend a changelog entry for a landed issue and push it to the default branch.
|
|
4
|
-
|
|
5
|
-
inputs:
|
|
6
|
-
token:
|
|
7
|
-
description: Token with contents write on the repository.
|
|
8
|
-
required: true
|
|
9
|
-
issue-number:
|
|
10
|
-
description: Issue the landed commit implements.
|
|
11
|
-
required: true
|
|
12
|
-
commit-sha:
|
|
13
|
-
description: Commit the work landed as. Its subject becomes the summary.
|
|
14
|
-
required: true
|
|
15
|
-
changelog-path:
|
|
16
|
-
description: Path to changelog.json.
|
|
17
|
-
required: false
|
|
18
|
-
default: apps/web/src/shared/data/changelog.json
|
|
19
|
-
max-entries:
|
|
20
|
-
description: Newest entries to keep.
|
|
21
|
-
required: false
|
|
22
|
-
default: "20"
|
|
23
|
-
|
|
24
|
-
runs:
|
|
25
|
-
using: composite
|
|
26
|
-
steps:
|
|
27
|
-
- name: Prepend the entry and push
|
|
28
|
-
shell: bash
|
|
29
|
-
env:
|
|
30
|
-
GH_TOKEN: ${{ inputs.token }}
|
|
31
|
-
REPO: ${{ github.repository }}
|
|
32
|
-
ISSUE_NUMBER: ${{ inputs.issue-number }}
|
|
33
|
-
COMMIT_SHA: ${{ inputs.commit-sha }}
|
|
34
|
-
CHANGELOG_PATH: ${{ inputs.changelog-path }}
|
|
35
|
-
MAX_ENTRIES: ${{ inputs.max-entries }}
|
|
36
|
-
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
|
|
37
|
-
run: |
|
|
38
|
-
set -euo pipefail
|
|
39
|
-
|
|
40
|
-
# This used to be part of the implement prompt. It is deterministic work, and leaving it
|
|
41
|
-
# to the agent made every implement touch the same file: two runs whose branches were cut
|
|
42
|
-
# before the other merged conflicted here, produced correct code, and still failed to open
|
|
43
|
-
# a pull request. Doing it after the merge means exactly one writer, always against a
|
|
44
|
-
# current default branch.
|
|
45
|
-
|
|
46
|
-
host="${GITHUB_SERVER_URL#https://}"
|
|
47
|
-
git config user.name "github-actions[bot]"
|
|
48
|
-
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
49
|
-
git remote set-url origin "https://x-access-token:${GH_TOKEN}@${host}/${GITHUB_REPOSITORY}.git"
|
|
50
|
-
|
|
51
|
-
git fetch --quiet origin "$DEFAULT_BRANCH"
|
|
52
|
-
git checkout --quiet -B "$DEFAULT_BRANCH" "origin/$DEFAULT_BRANCH"
|
|
53
|
-
|
|
54
|
-
if [ ! -f "$CHANGELOG_PATH" ]; then
|
|
55
|
-
echo "::notice::$CHANGELOG_PATH does not exist; nothing to update."
|
|
56
|
-
exit 0
|
|
57
|
-
fi
|
|
58
|
-
|
|
59
|
-
# Idempotent: a re-run, a retry, or a second call for the same commit must not add a
|
|
60
|
-
# duplicate row.
|
|
61
|
-
short_sha="${COMMIT_SHA:0:7}"
|
|
62
|
-
if jq -e --arg c "$short_sha" '.changes[]? | select(.commit == $c)' "$CHANGELOG_PATH" >/dev/null 2>&1; then
|
|
63
|
-
echo "::notice::$short_sha is already in the changelog."
|
|
64
|
-
exit 0
|
|
65
|
-
fi
|
|
66
|
-
|
|
67
|
-
title=$(gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json title --jq '.title')
|
|
68
|
-
|
|
69
|
-
# The commit subject carries what actually changed. Strip the conventional-commit prefix
|
|
70
|
-
# and the trailing issue reference so the summary reads as prose rather than as a commit.
|
|
71
|
-
subject=$(git log -1 --format=%s "$COMMIT_SHA")
|
|
72
|
-
summary=$(printf '%s' "$subject" \
|
|
73
|
-
| sed -E 's/^[a-z]+(\([^)]*\))?!?: *//' \
|
|
74
|
-
| sed -E 's/ *\(#[0-9]+\) *$//')
|
|
75
|
-
[ -n "$summary" ] || summary="$title"
|
|
76
|
-
# Capitalise, because a commit subject conventionally starts lowercase and this is read
|
|
77
|
-
# by people rather than by tooling.
|
|
78
|
-
summary="$(printf '%s' "${summary:0:1}" | tr '[:lower:]' '[:upper:]')${summary:1}"
|
|
79
|
-
|
|
80
|
-
timestamp=$(git log -1 --format=%cI "$COMMIT_SHA")
|
|
81
|
-
|
|
82
|
-
tmp=$(mktemp)
|
|
83
|
-
jq --argjson n "$MAX_ENTRIES" \
|
|
84
|
-
--arg ts "$timestamp" \
|
|
85
|
-
--argjson issue "$ISSUE_NUMBER" \
|
|
86
|
-
--arg title "$title" \
|
|
87
|
-
--arg summary "$summary" \
|
|
88
|
-
--arg commit "$short_sha" \
|
|
89
|
-
'.changes = ([{timestamp: $ts, issue: $issue, title: $title, summary: $summary, commit: $commit}] + (.changes // []))[:$n]' \
|
|
90
|
-
"$CHANGELOG_PATH" > "$tmp"
|
|
91
|
-
mv "$tmp" "$CHANGELOG_PATH"
|
|
92
|
-
|
|
93
|
-
if git diff --quiet -- "$CHANGELOG_PATH"; then
|
|
94
|
-
echo "::notice::changelog unchanged."
|
|
95
|
-
exit 0
|
|
96
|
-
fi
|
|
97
|
-
|
|
98
|
-
git add -- "$CHANGELOG_PATH"
|
|
99
|
-
git commit --quiet -m "docs(changelog): record #${ISSUE_NUMBER}"
|
|
100
|
-
|
|
101
|
-
# The default branch may have moved while this ran. Rebase and retry rather than fail:
|
|
102
|
-
# only this action writes the file, so a rebase here cannot produce a content conflict.
|
|
103
|
-
for attempt in 1 2 3; do
|
|
104
|
-
if git push --quiet origin "$DEFAULT_BRANCH"; then
|
|
105
|
-
echo "Recorded #${ISSUE_NUMBER} at ${short_sha} in the changelog."
|
|
106
|
-
exit 0
|
|
107
|
-
fi
|
|
108
|
-
echo "::notice::push rejected, rebasing (attempt ${attempt})"
|
|
109
|
-
git fetch --quiet origin "$DEFAULT_BRANCH"
|
|
110
|
-
git rebase --quiet "origin/$DEFAULT_BRANCH" || { git rebase --abort || true; break; }
|
|
111
|
-
done
|
|
112
|
-
|
|
113
|
-
echo "::warning::Could not push the changelog entry for #${ISSUE_NUMBER}."
|