Repository navigation
587 lines (562 loc) · 27.5 KB
/
Copy pathopencode-changelog-update.yml
File metadata and controls
587 lines (562 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
name: OpenCode changelog update
on:
workflow_call:
inputs:
label:
description: Pull-request label that triggers a changelog update
type: string
required: false
default: update-changelog
target_file:
description: Repository-relative target file to update (default CHANGELOG.md)
type: string
required: false
default: CHANGELOG.md
configuration_source:
description: default (supplied profile), local (caller repository), or an approved central alias
type: string
required: false
default: default
configuration_ref:
description: Full 40-character commit SHA for a remote bundle
type: string
required: false
default: ''
configuration_profile:
description: Bundle profile name
type: string
required: false
default: changelog-update
dry_run:
description: Resolve, validate, and generate output without publishing
type: boolean
required: false
default: false
validate_only:
description: Resolve and validate configuration only
type: boolean
required: false
default: false
pull_number:
description: Pull-request number to update when event context is unavailable
type: number
required: false
default: 0
secrets:
OPENROUTER_API_KEY:
required: true
central_config_token:
description: Optional read token for a private central configuration repository; falls back to github.token.
required: false
jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
concurrency:
group: opencode-changelog-update-${{ github.repository }}-${{ inputs.pull_number || github.event.pull_request.number }}
cancel-in-progress: false
steps:
# Keep the caller's trusted base at the workspace root for local
# configuration, policy overlays, and repository operations.
- name: Check out caller repository
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: ${{ github.event.pull_request.base.sha || github.sha }}
persist-credentials: false
fetch-depth: 0
# A reusable workflow loads only this YAML from the called repository.
# Fetch its implementation at the exact revision GitHub selected. Skip
# this checkout when a direct/local invocation already has that exact
# repository revision at the workspace root.
- name: Check out pinned workflow helpers
if: job.workflow_repository != github.repository || job.workflow_sha != github.sha
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .agentic-workflow
persist-credentials: false
- name: Select trusted workflow helpers
env:
WORKFLOW_REPOSITORY: ${{ job.workflow_repository }}
WORKFLOW_SHA: ${{ job.workflow_sha }}
run: |
if [[ "$WORKFLOW_REPOSITORY" == "$GITHUB_REPOSITORY" && "$WORKFLOW_SHA" == "$GITHUB_SHA" ]]; then
echo "AGENTIC_WORKFLOW_ROOT=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
else
echo "AGENTIC_WORKFLOW_ROOT=$GITHUB_WORKSPACE/.agentic-workflow" >> "$GITHUB_ENV"
fi
- name: Resolve invocation
id: resolve
env:
AGENTIC_WORKFLOW: pr-changelog-update
AGENTIC_CONFIGURATION_SOURCE: ${{ inputs.configuration_source || 'local' }}
AGENTIC_CONFIGURATION_REF: ${{ inputs.configuration_ref || '' }}
AGENTIC_CONFIGURATION_PROFILE: ${{ inputs.configuration_profile || 'changelog-update' }}
AGENTIC_DRY_RUN: ${{ inputs.dry_run || false }}
AGENTIC_VALIDATE_ONLY: ${{ inputs.validate_only || false }}
AGENTIC_TARGET_NUMBER: ${{ inputs.pull_number || github.event.pull_request.number || '' }}
AGENTIC_REQUEST_LABEL: ${{ inputs.label || 'update-changelog' }}
AGENTIC_TARGET_FILE: ${{ inputs.target_file || 'CHANGELOG.md' }}
run: |
set -euo pipefail
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/resolve_invocation.py" \
--workflow pr-changelog-update \
--configuration-source "$AGENTIC_CONFIGURATION_SOURCE" \
--configuration-ref "$AGENTIC_CONFIGURATION_REF" \
--configuration-profile "$AGENTIC_CONFIGURATION_PROFILE" \
--dry-run "$AGENTIC_DRY_RUN" \
--validate-only "$AGENTIC_VALIDATE_ONLY" \
--target-number "$AGENTIC_TARGET_NUMBER" \
--request-label "$AGENTIC_REQUEST_LABEL" \
--target-file "$AGENTIC_TARGET_FILE" \
--github-output "$GITHUB_OUTPUT" \
--github-step-summary "$GITHUB_STEP_SUMMARY" \
--result "$RUNNER_TEMP/resolved-invocation.json"
- name: Stop after validation-only
if: steps.resolve.outputs.validate_only == 'true'
env:
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
run: |
echo "validate_only selected; no PR fetch, model invocation, or publication performed."
python3 - <<'PY'
import json, os, sys
from pathlib import Path
import importlib.util
spec = importlib.util.spec_from_file_location(
"agentic_provenance", Path(os.environ["AGENTIC_WORKFLOW_ROOT"]) / "scripts/agentic_provenance.py"
)
prov = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = prov; spec.loader.exec_module(prov)
record = prov.build_provenance(
workflow_version=os.environ.get("AGENTIC_WORKFLOW_VERSION", "dev"),
workflow_name="pr-changelog-update",
caller_repository=os.environ.get("GITHUB_REPOSITORY", ""),
target_kind="pull_request",
target_number=None,
target_head_sha=None,
bundle=None,
prompt_template_sha256=None,
output_contract=None,
model_profile=None,
effective_policy_sha256=None,
mode="validate-only",
result="validated",
)
out = Path(os.environ["RUNNER_TEMP"]) / "resolved-agentic-provenance.json"
out.write_text(record.to_json() + "\n", encoding="utf-8")
summary = Path(os.environ["GITHUB_STEP_SUMMARY"])
existing = summary.read_text() if summary.exists() else ""
if existing and not existing.endswith("\n"):
existing += "\n"
summary.write_text(existing + prov.job_summary(record), encoding="utf-8")
PY
echo "::notice::Resolved configuration written to job summary and artifact."
- name: Guard trigger and resolve pull request
if: steps.resolve.outputs.validate_only != 'true'
id: guard
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ steps.resolve.outputs.target_number }}
REQUEST_LABEL: ${{ steps.resolve.outputs.request_label }}
EVENT_PAYLOAD: ${{ github.event_path }}
EVENT_NAME: ${{ github.event_name }}
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
run: |
set -euo pipefail
if ! [[ "$PR_NUMBER" =~ ^[1-9][0-9]*$ ]]; then
echo "A positive pull-request number is required." >&2
exit 1
fi
gh api "repos/$REPOSITORY/pulls/$PR_NUMBER" > "$RUNNER_TEMP/pr.json"
gh api --paginate "repos/$REPOSITORY/issues/$PR_NUMBER/comments?per_page=100" \
| jq -s 'add // []' > "$RUNNER_TEMP/pr-comments.json"
gh api "repos/$REPOSITORY/pulls/$PR_NUMBER/commits" \
> "$RUNNER_TEMP/pr-commits.json"
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/run_agentic_changelog_update.py" guard \
--event-payload "$EVENT_PAYLOAD" \
--event-name "$EVENT_NAME" \
--pr-json "$RUNNER_TEMP/pr.json" \
--comments-json "$RUNNER_TEMP/pr-comments.json" \
--commits-json "$RUNNER_TEMP/pr-commits.json" \
--request-label "$REQUEST_LABEL" \
--target-number "$PR_NUMBER" \
--github-output "$GITHUB_OUTPUT" \
--result "$RUNNER_TEMP/guard-result.json" \
--provenance "$RUNNER_TEMP/resolved-agentic-provenance.json"
- name: Skip when guard reports idempotency
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action == 'skip'
run: |
echo "Most recent PR action is this workflow's own marker; skipping without side effects."
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip'
with:
python-version: '3.12'
- name: Resolve agentic configuration
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip'
id: config
env:
AGENTIC_WORKFLOW: pr-changelog-update
AGENTIC_CONFIGURATION_SOURCE: ${{ steps.resolve.outputs.configuration_source }}
AGENTIC_CONFIGURATION_REF: ${{ steps.resolve.outputs.configuration_ref }}
AGENTIC_CONFIGURATION_PROFILE: ${{ steps.resolve.outputs.configuration_profile }}
GITHUB_TOKEN: ${{ secrets.central_config_token || github.token }}
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
run: |
set -euo pipefail
if ! python3 "$AGENTIC_WORKFLOW_ROOT/scripts/agentic_configuration.py" \
--workflow pr-changelog-update \
--configuration-source "$AGENTIC_CONFIGURATION_SOURCE" \
--configuration-ref "$AGENTIC_CONFIGURATION_REF" \
--configuration-profile "$AGENTIC_CONFIGURATION_PROFILE" \
--result "$RUNNER_TEMP/resolved-agentic-configuration.json"; then
python3 - <<'PY'
import json, os, sys
from pathlib import Path
import importlib.util
spec = importlib.util.spec_from_file_location("agentic_provenance", Path(os.environ["AGENTIC_WORKFLOW_ROOT"]) / "scripts/agentic_provenance.py")
prov = importlib.util.module_from_spec(spec); sys.modules[spec.name] = prov; spec.loader.exec_module(prov)
record = prov.failure_record(
workflow_version=os.environ.get("AGENTIC_WORKFLOW_VERSION", "dev"),
workflow_name="pr-changelog-update",
caller_repository=os.environ.get("GITHUB_REPOSITORY", ""),
mode="publish",
error=RuntimeError("configuration resolution failed"),
)
Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-provenance.json").write_text(record.to_json() + "\n")
PY
exit 1
fi
echo "model_profile=$(jq -r '.model_profile' "$RUNNER_TEMP/resolved-agentic-configuration.json")" >> "$GITHUB_OUTPUT"
- name: Resolve effective policy
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip'
id: policy
env:
AGENTIC_WORKFLOW: pr-changelog-update
DRY_RUN: ${{ steps.resolve.outputs.dry_run }}
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
run: |
set -euo pipefail
model_profile=$(jq -r '.model_profile' "$RUNNER_TEMP/resolved-agentic-configuration.json")
mode="publish"
if [[ "$DRY_RUN" == "true" ]]; then mode="dry-run"; fi
agent_caps=$(python3 - <<'PY'
import json, sys, os, importlib.util
from pathlib import Path
spec = importlib.util.spec_from_file_location("agentic_policy", Path(os.environ["AGENTIC_WORKFLOW_ROOT"]) / "scripts/agentic_policy.py")
pol = importlib.util.module_from_spec(spec); sys.modules[spec.name] = pol; spec.loader.exec_module(pol)
data = json.loads(Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-configuration.json").read_text())
agent_text = (Path(data["bundle_root"]) / data["agent_file"]).read_text(encoding="utf-8")
print(json.dumps(pol.parse_agent_capabilities(agent_text)))
PY
)
overlay_arg=""
if [[ -f .github/agentic-policy-overlay.json ]]; then
overlay_arg="--overlay .github/agentic-policy-overlay.json"
fi
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/agentic_policy.py" \
--workflow "$AGENTIC_WORKFLOW" \
--model-profile "$model_profile" \
--resolved-config "$RUNNER_TEMP/resolved-agentic-configuration.json" \
--agent-capabilities-json "$agent_caps" \
--mode "$mode" \
$overlay_arg \
--result "$RUNNER_TEMP/effective-policy.json" \
--github-step-summary "$GITHUB_STEP_SUMMARY" \
|| {
python3 - <<'PY'
import json, os, sys
from pathlib import Path
import importlib.util
spec = importlib.util.spec_from_file_location("agentic_provenance", Path(os.environ["AGENTIC_WORKFLOW_ROOT"]) / "scripts/agentic_provenance.py")
prov = importlib.util.module_from_spec(spec); sys.modules[spec.name] = prov; spec.loader.exec_module(prov)
bundle = json.loads(Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-configuration.json").read_text())
record = prov.failure_record(
workflow_version=os.environ.get("AGENTIC_WORKFLOW_VERSION", "dev"),
workflow_name="pr-changelog-update",
caller_repository=os.environ.get("GITHUB_REPOSITORY", ""),
mode="publish",
error=RuntimeError("policy resolution failed"),
bundle=bundle,
)
Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-provenance.json").write_text(record.to_json() + "\n")
PY
exit 1
}
echo "sha256=$(jq -r '.sha256' "$RUNNER_TEMP/effective-policy.json")" >> "$GITHUB_OUTPUT"
- name: Get pull request diff
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip'
env:
BASE_SHA: ${{ steps.guard.outputs.base_sha }}
PR_NUMBER: ${{ steps.guard.outputs.number }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
auth_header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 --wrap=0)"
git -c "http.https://github.com/.extraheader=$auth_header" \
fetch --no-tags origin "pull/$PR_NUMBER/head:pr-head"
merge_base="$(git merge-base "$BASE_SHA" pr-head)"
git diff "$merge_base" pr-head -- > "$RUNNER_TEMP/pr.diff"
- name: Set up Node.js 24
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip'
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
with:
node-version: '24'
- name: Install OpenCode
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip'
# The postinstall script creates the real platform binary
# (bin/opencode.exe); npm's allow-scripts gate blocks it unless the
# exact-pinned package is allow-listed. The scoped flag permits only
# opencode-ai, with no wildcard or persistent npm config.
run: |
set -euo pipefail
npm install -g --allow-scripts=opencode-ai opencode-ai@1.18.16
opencode --version
- name: Generate changelog update
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip'
id: update
env:
GITHUB_TOKEN: ${{ github.token }}
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
DRY_RUN: ${{ steps.resolve.outputs.dry_run }}
TARGET_FILE: ${{ steps.resolve.outputs.target_file }}
GUARD_MODE: ${{ steps.guard.outputs.mode }}
MARKER_COMMENT_ID: ${{ steps.guard.outputs.marker_comment_id }}
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
run: |
set -euo pipefail
args=(
--resolved-config "$RUNNER_TEMP/resolved-agentic-configuration.json"
--effective-policy "$RUNNER_TEMP/effective-policy.json"
--pr-json "$RUNNER_TEMP/pr.json"
--diff-file "$RUNNER_TEMP/pr.diff"
--target-file "$TARGET_FILE"
--repo-root "$GITHUB_WORKSPACE"
--mode "$GUARD_MODE"
--marker-comment-id "$MARKER_COMMENT_ID"
--seed-target
--github-output "$GITHUB_OUTPUT"
--publication-preview "$RUNNER_TEMP/agentic-publication-preview.json"
--response-diagnostics "$RUNNER_TEMP/opencode-response-diagnostics.json"
--provenance "$RUNNER_TEMP/resolved-agentic-provenance.json"
)
if [[ "$DRY_RUN" == "true" ]]; then
args+=(--dry-run)
fi
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/run_agentic_changelog_update.py" update "${args[@]}"
- name: Publish changelog update
if: steps.resolve.outputs.validate_only != 'true' && steps.guard.outputs.action != 'skip' && steps.update.outputs.decision == 'UPDATED'
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ steps.guard.outputs.number }}
HEAD_REF: ${{ steps.guard.outputs.head_ref }}
IS_FORK: ${{ steps.guard.outputs.is_fork }}
TARGET_FILE: ${{ steps.resolve.outputs.target_file }}
DRY_RUN: ${{ steps.resolve.outputs.dry_run }}
MARKER_COMMENT_ID: ${{ steps.guard.outputs.marker_comment_id }}
PREVIEW: ${{ runner.temp }}/agentic-publication-preview.json
AGENTIC_WORKFLOW_ROOT: ${{ env.AGENTIC_WORKFLOW_ROOT }}
run: |
set -uo pipefail
# Run the publication block without -e so we can inspect its exit
# status and gate provenance promotion precisely.
python3 - <<'PY'
import base64, json, os, re, subprocess, sys
from pathlib import Path
from urllib.parse import quote
import importlib.util
# Single source of truth for the comment size cap: the runner module.
_root = Path(os.environ["AGENTIC_WORKFLOW_ROOT"])
_spec = importlib.util.spec_from_file_location(
"run_agentic_changelog_update", _root / "scripts/run_agentic_changelog_update.py"
)
_runner = importlib.util.module_from_spec(_spec)
sys.modules["run_agentic_changelog_update"] = _runner
_spec.loader.exec_module(_runner)
COMMENT_CAP = _runner.MAX_COMMENT_CHARS
GITHUB_HARD_LIMIT = 65535
GH_DIAGNOSTIC_LIMIT = 2_000
preview = json.loads(Path(os.environ["PREVIEW"]).read_text(encoding="utf-8"))
marker = preview["marker"]
target_file = os.environ["TARGET_FILE"]
proposed = preview.get("proposed_content") or ""
dry_run = os.environ.get("DRY_RUN") == "true"
repo = os.environ["REPOSITORY"]
pr_number = os.environ["PR_NUMBER"]
head_ref = os.environ["HEAD_REF"]
is_fork = os.environ.get("IS_FORK") == "true"
marker_comment_id = os.environ.get("MARKER_COMMENT_ID") or ""
# URL-encode the target path for the Contents API endpoint so spaces,
# '#', '?', and other reserved characters cannot corrupt the URL.
# 'safe' keeps path separators intact.
encoded_path = quote(target_file, safe="/")
class GhApiError(RuntimeError):
def __init__(self, returncode: int, status: int | None):
super().__init__(f"GitHub API request failed with exit code {returncode}")
self.status = status
def _safe_gh_diagnostic(text: str) -> str:
token = os.environ.get("GH_TOKEN") or ""
if token:
text = text.replace(token, "[REDACTED]")
text = re.sub(
r"(?i)(bearer\s+|authorization\s*[:=]\s*|gh[pousr]_)[^\s,;]+",
r"\1[REDACTED]",
text,
)
text = " ".join(text.split())
if len(text) > GH_DIAGNOSTIC_LIMIT:
text = "...[truncated] " + text[-GH_DIAGNOSTIC_LIMIT:]
return text or "no diagnostic output"
def gh(*args: str, input_data: str | None = None) -> str:
proc = subprocess.run(
["gh", "api", *args],
input=input_data,
capture_output=True,
text=True,
check=False,
)
if proc.returncode:
raw_diagnostic = proc.stderr or proc.stdout
status_match = re.search(r"\bHTTP\s+([1-5][0-9]{2})\b", raw_diagnostic)
status = int(status_match.group(1)) if status_match else None
print(
"::error::GitHub API request failed "
f"(HTTP {status or 'unknown'}, exit {proc.returncode}): "
f"{_safe_gh_diagnostic(raw_diagnostic)}",
file=sys.stderr,
)
raise GhApiError(proc.returncode, status)
return proc.stdout
if dry_run:
print("Dry run: would publish the proposed changelog update.")
print(f" target_file={target_file} fork={is_fork} bytes={len(proposed.encode())}")
# Exit with a distinct status so the shell wrapper can skip
# provenance promotion. mark-published must never run in dry-run.
sys.exit(42)
if not is_fork:
# Same-repo: commit only the target file to the PR source branch
# via the GitHub Contents API with an optimistic blob SHA.
encoded = base64.b64encode(proposed.encode("utf-8")).decode("ascii")
commit_message = f"Update changelog for #{pr_number}\n\n{marker}"
# Fetch the current file SHA at the PR head ref (may not exist).
current_sha = ""
try:
# gh changes its default method from GET to POST when fields
# are supplied, so force GET to send ref as a query parameter.
meta = gh(
"--method", "GET",
f"repos/{repo}/contents/{encoded_path}",
"-f", f"ref={head_ref}",
)
current_sha = json.loads(meta).get("sha") or ""
except GhApiError as error:
# Only a missing file is a create operation. Permission,
# branch, and transport failures must stop publication.
if error.status != 404:
raise
payload = {
"message": commit_message,
"branch": head_ref,
"content": encoded,
}
if current_sha:
payload["sha"] = current_sha
gh(
"--method", "PUT", f"repos/{repo}/contents/{encoded_path}",
"--input", "-",
input_data=json.dumps(payload),
)
print(f"Committed {target_file} to {head_ref} on {repo}.")
else:
# Fork: never push. Post or update a single marker comment with
# the proposed content under a safe fenced block, bounded below
# GitHub's 65,536-character comment limit.
wrapper_prefix = (
f"{marker}\n"
f"## Proposed changelog update for `{target_file}`\n\n"
"The pull request head is on a fork, so no commit was pushed. "
"The proposed target-file content is below for review.\n\n"
"```markdown\n"
)
wrapper_suffix = "\n```\n"
cap = COMMENT_CAP - len(wrapper_prefix) - len(wrapper_suffix)
if cap < 0:
# Pathologically large wrapper: keep marker + truncation note.
body = (
f"{marker}\n## Proposed changelog update for `{target_file}`\n\n"
"The proposed content exceeds the comment size limit and is "
"available in the workflow artifact.\n"
)
else:
if len(proposed) > cap:
proposed = proposed[:cap] + "\n...[truncated by workflow]\n"
body = wrapper_prefix + proposed + wrapper_suffix
if len(body) > GITHUB_HARD_LIMIT:
body = body[:GITHUB_HARD_LIMIT]
if marker_comment_id:
gh(
"--method", "PATCH",
f"repos/{repo}/issues/comments/{marker_comment_id}",
"-f", f"body={body}",
)
print(f"Updated marker comment {marker_comment_id}.")
else:
gh(
"--method", "POST",
f"repos/{repo}/issues/{pr_number}/comments",
"-f", f"body={body}",
)
print(f"Posted marker comment to #{pr_number}.")
PY
# The Python block exits 42 for dry-run (no write performed) and 0
# after a successful GitHub API write. Promote provenance to
# "published" ONLY after a real write; mark-published is unreachable
# in dry-run and on any failure (set -e aborts before reaching here).
py_status=$?
if [[ "$py_status" -eq 42 ]]; then
exit 0
fi
if [[ "$py_status" -ne 0 ]]; then
exit "$py_status"
fi
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/run_agentic_changelog_update.py" mark-published \
--provenance "$RUNNER_TEMP/resolved-agentic-provenance.json"
- name: Provenance job summary
if: always() && steps.resolve.outputs.validate_only != 'true'
run: |
if [[ -f "$RUNNER_TEMP/resolved-agentic-provenance.json" ]]; then
python3 - <<'PY'
import json, os
from pathlib import Path
record = json.loads(Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-provenance.json").read_text())
summary_path = Path(os.environ["GITHUB_STEP_SUMMARY"])
existing = summary_path.read_text() if summary_path.exists() else ""
if existing and not existing.endswith("\n"):
existing += "\n"
lines = ["### Agentic workflow provenance", ""]
for k in ("workflow_name", "mode", "result", "output_contract", "model_profile", "configuration_digest"):
if record.get(k):
lines.append(f"- {k}: `{record[k]}`")
summary_path.write_text(existing + "\n".join(lines) + "\n")
PY
fi
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: resolved-invocation-pr-changelog-update
path: |
${{ runner.temp }}/resolved-invocation.json
${{ runner.temp }}/guard-result.json
${{ runner.temp }}/pr.json
${{ runner.temp }}/resolved-agentic-configuration.json
${{ runner.temp }}/effective-policy.json
${{ runner.temp }}/resolved-agentic-provenance.json
${{ runner.temp }}/opencode-response-diagnostics.json
${{ runner.temp }}/agentic-publication-preview.json
retention-days: 14
if-no-files-found: ignore