Repository navigation
Expand file tree
/
Copy pathopencode-release-project-review.yml
More file actions
476 lines (459 loc) · 23 KB
/
Copy pathopencode-release-project-review.yml
File metadata and controls
476 lines (459 loc) · 23 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
name: OpenCode release project review
# Manual/reusable only. This workflow never runs automatically on a release
# event; it examines a published GitHub release identified by a release ID or
# tag and creates at most one release-readiness issue in the reviewed
# repository. The supplied `release-project-review` profile is the default for
# direct runs (resolved from the trusted checkout as the `local` source) and
# for reusable calls that select `configuration_source: default`.
on:
workflow_dispatch:
inputs:
target_repository:
description: Canonical owner/repo of the release to review (strict owner/repo grammar)
type: string
required: false
# Input defaults are evaluated while GitHub parses the workflow, when
# contexts are unavailable. An empty value is resolved to the caller
# repository by the runtime expression below.
default: ''
release_id:
description: Positive decimal GitHub release ID. Exactly one of release_id/release_tag is required.
# Workflow-job outputs, including IDs returned by `gh api`, are
# strings. Accept that transport representation so dispatch wrappers
# can forward a discovered ID; resolve_invocation.py validates it as a
# positive integer before the release is fetched.
type: string
required: false
default: ''
release_tag:
description: Conservative release tag selector. Exactly one of release_id/release_tag is required.
type: string
required: false
default: ''
configuration_source:
description: default (supplied profile), local (caller repository), or an approved central alias
type: string
required: false
# Direct runs already have this repository checked out, so resolve the
# supplied profile locally without requiring a redundant remote ref.
default: local
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: release-project-review
focus:
description: Allowlisted release-management focus (not arbitrary prompt text)
type: string
required: false
default: ''
dry_run:
description: Resolve, validate, and generate output without publishing
type: boolean
required: false
default: false
validate_only:
description: Resolve and validate configuration only; no release fetch, checkout, model, or publication
type: boolean
required: false
default: false
workflow_call:
inputs:
target_repository:
description: Canonical owner/repo of the release to review (strict owner/repo grammar)
type: string
# GitHub does not expose the github context while parsing a reusable
# workflow input default. Callers must explicitly pass their target.
required: true
release_id:
description: Positive decimal GitHub release ID. Exactly one of release_id/release_tag is required.
# Workflow-job outputs, including IDs returned by `gh api`, are
# strings. Accept that transport representation so dispatch wrappers
# can forward a discovered ID; resolve_invocation.py validates it as a
# positive integer before the release is fetched.
type: string
required: false
default: ''
release_tag:
description: Conservative release tag selector. Exactly one of release_id/release_tag is required.
type: string
required: false
default: ''
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: release-project-review
focus:
description: Allowlisted release-management focus (not arbitrary prompt text)
type: string
required: false
default: ''
dry_run:
description: Resolve, validate, and generate output without publishing
type: boolean
required: false
default: false
validate_only:
description: Resolve and validate configuration only; no release fetch, checkout, model, or publication
type: boolean
required: false
default: false
secrets:
OPENROUTER_API_KEY:
description: OpenRouter provider API key
required: true
release_target_token:
description: 'Target-scoped GitHub token (contents: read, issues: write) for cross-repository release review. Falls back to github.token for same-repository runs.'
required: false
central_config_token:
description: 'Optional read token for a private central configuration repository; falls back to github.token.'
required: false
permissions:
contents: read
issues: write
jobs:
release-review:
runs-on: ubuntu-latest
env:
FEEDBACK_KIND: release-project-review
steps:
# Keep caller-local configuration and policy at the workspace root.
- name: Check out caller repository
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
# For reusable calls, fetch helper code from the exact called workflow
# revision. Direct/local runs already have those files and skip this.
- 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: release-project-review
# Consume inputs directly. github.event_name retains the caller's
# original event during a reusable call and cannot distinguish it
# from a direct dispatch.
AGENTIC_CONFIGURATION_SOURCE: ${{ inputs.configuration_source || 'local' }}
AGENTIC_CONFIGURATION_REF: ${{ inputs.configuration_ref || '' }}
AGENTIC_CONFIGURATION_PROFILE: ${{ inputs.configuration_profile || 'release-project-review' }}
AGENTIC_FOCUS: ${{ inputs.focus || '' }}
AGENTIC_DRY_RUN: ${{ inputs.dry_run || false }}
AGENTIC_VALIDATE_ONLY: ${{ inputs.validate_only || false }}
AGENTIC_TARGET_REPOSITORY: ${{ inputs.target_repository || github.repository }}
AGENTIC_RELEASE_ID: ${{ inputs.release_id || '' }}
AGENTIC_RELEASE_TAG: ${{ inputs.release_tag || '' }}
run: |
set -euo pipefail
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/resolve_invocation.py" \
--workflow release-project-review \
--configuration-source "$AGENTIC_CONFIGURATION_SOURCE" \
--configuration-ref "$AGENTIC_CONFIGURATION_REF" \
--configuration-profile "$AGENTIC_CONFIGURATION_PROFILE" \
--focus "$AGENTIC_FOCUS" \
--dry-run "$AGENTIC_DRY_RUN" \
--validate-only "$AGENTIC_VALIDATE_ONLY" \
--target-repository "$AGENTIC_TARGET_REPOSITORY" \
--release-id "$AGENTIC_RELEASE_ID" \
--release-tag "$AGENTIC_RELEASE_TAG" \
--github-output "$GITHUB_OUTPUT" \
--github-step-summary "$GITHUB_STEP_SUMMARY" \
--result "$RUNNER_TEMP/resolved-invocation.json"
# Configuration and policy are resolved before the validation-only stop
# so an invalid command configuration (unknown midflight ID, disallowed
# phase, count/overlap violation) is caught without a release fetch,
# checkout, command execution, or model invocation.
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: '3.12'
- name: Resolve agentic configuration
id: config
env:
AGENTIC_WORKFLOW: release-project-review
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 }}
AGENTIC_DRY_RUN: ${{ steps.resolve.outputs.dry_run }}
run: |
set -euo pipefail
if ! python3 "$AGENTIC_WORKFLOW_ROOT/scripts/agentic_configuration.py" \
--workflow release-project-review \
--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)
mode = "dry-run" if os.environ.get("AGENTIC_DRY_RUN") == "true" else "publish"
record = prov.failure_record(
workflow_version=os.environ.get("AGENTIC_WORKFLOW_VERSION", "dev"),
workflow_name="release-project-review",
caller_repository=os.environ.get("GITHUB_REPOSITORY", ""),
mode=mode,
error=RuntimeError("configuration resolution failed"),
)
Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-provenance.json").write_text(record.to_json() + "\n")
PY
exit 1
fi
- name: Resolve effective policy
id: policy
env:
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 release-project-review \
--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())
mode = "dry-run" if os.environ.get("DRY_RUN") == "true" else "publish"
record = prov.failure_record(
workflow_version=os.environ.get("AGENTIC_WORKFLOW_VERSION", "dev"),
workflow_name="release-project-review",
caller_repository=os.environ.get("GITHUB_REPOSITORY", ""),
mode=mode,
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
}
- name: Stop after validation-only
if: steps.resolve.outputs.validate_only == 'true'
env:
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
run: |
echo "validate_only selected; configuration and policy resolved. No release fetch, checkout, command execution, 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)
bundle = json.loads(Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-configuration.json").read_text())
policy = json.loads(Path(os.environ["RUNNER_TEMP"] + "/effective-policy.json").read_text())
record = prov.build_provenance(
workflow_version=os.environ.get("AGENTIC_WORKFLOW_VERSION", "dev"),
workflow_name="release-project-review",
caller_repository=os.environ.get("GITHUB_REPOSITORY", ""),
target_kind="release",
target_number=None,
target_head_sha=None,
bundle=bundle,
prompt_template_sha256=bundle.get("prompt_template_sha256"),
output_contract=bundle.get("output_contract"),
model_profile=bundle.get("model_profile"),
effective_policy_sha256=policy.get("sha256"),
mode="validate-only",
result="validated",
)
Path(os.environ["RUNNER_TEMP"] + "/resolved-agentic-provenance.json").write_text(record.to_json() + "\n")
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 and policy written to job summary and artifact."
- name: Set up Node.js 24
if: steps.resolve.outputs.validate_only != 'true'
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
with:
node-version: '24'
- name: Install OpenCode
if: steps.resolve.outputs.validate_only != 'true'
# 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: Resolve release and prove target access
if: steps.resolve.outputs.validate_only != 'true'
id: release
env:
GITHUB_TOKEN: ${{ github.token }}
# Same-repository runs use the job token. External runs MUST use the
# explicitly forwarded target-scoped token; the boolean flag below
# is the authoritative signal that a target token was forwarded, so
# the runner can fail closed for an external run that omits it. The
# secret value itself is never logged.
RELEASE_TARGET_TOKEN_FORWARDED: ${{ secrets.release_target_token != '' }}
RELEASE_TARGET_TOKEN: ${{ secrets.release_target_token || github.token }}
TARGET_REPOSITORY: ${{ steps.resolve.outputs.target_repository }}
RELEASE_ID: ${{ steps.resolve.outputs.release_id }}
RELEASE_TAG: ${{ steps.resolve.outputs.release_tag }}
CALLER_REPOSITORY: ${{ github.repository }}
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
GITHUB_WORKSPACE: ${{ github.workspace }}
run: |
set -euo pipefail
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/run_agentic_release_project_review.py" resolve-only \
--target-repository "$TARGET_REPOSITORY" \
--caller-repository "$CALLER_REPOSITORY" \
--release-id "$RELEASE_ID" \
--release-tag "$RELEASE_TAG" \
--target-token "$RELEASE_TARGET_TOKEN" \
--target-token-forwarded "$RELEASE_TARGET_TOKEN_FORWARDED" \
--github-output "$GITHUB_OUTPUT" \
--release-metadata "$RUNNER_TEMP/release-metadata.json" \
--provenance "$RUNNER_TEMP/resolved-agentic-provenance.json" \
--workflow-version "$AGENTIC_WORKFLOW_VERSION"
# Exactly one active target checkout runs, mutually exclusive on
# `steps.release.outputs.external`, both skipped in validate_only, both
# writing to the dedicated `release-target` path so trusted scripts in
# $GITHUB_WORKSPACE are never overwritten.
- name: Check out same-repository target commit (read-only)
if: steps.resolve.outputs.validate_only != 'true' && steps.release.outputs.external == 'false'
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: ${{ steps.release.outputs.target_commit_sha }}
path: release-target
persist-credentials: false
# External target: active only for an approved cross-repository call
# (external == 'true') using the explicitly forwarded target-scoped
# token. Same dedicated `release-target` path; exactly one checkout runs.
- name: Check out external target commit (read-only)
if: steps.resolve.outputs.validate_only != 'true' && steps.release.outputs.external == 'true'
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
repository: ${{ steps.release.outputs.target_repository }}
ref: ${{ steps.release.outputs.target_commit_sha }}
token: ${{ secrets.release_target_token }}
path: release-target
persist-credentials: false
- name: Review release and publish release-readiness issue
if: steps.resolve.outputs.validate_only != 'true'
id: review
# The runner, not the workflow YAML, constructs the command execution
# environment from a fixed credential-free allowlist. No workflow secret
# (OPENROUTER_API_KEY, release_target_token, GITHUB_TOKEN) is forwarded
# into the midflight command environment: the registry executor drops
# provider/GitHub/OIDC/SSH/proxy variables and uses a disposable HOME.
# Network isolation posture: only network-disabled registry commands
# are approved for midflight, and the executor refuses to run any
# command requesting network; enforceable OS-level denial (netns /
# locked-down container) is the hosted runner's responsibility.
env:
GITHUB_TOKEN: ${{ github.token }}
RELEASE_TARGET_TOKEN_FORWARDED: ${{ secrets.release_target_token != '' }}
RELEASE_TARGET_TOKEN: ${{ secrets.release_target_token || github.token }}
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
TARGET_REPOSITORY: ${{ steps.release.outputs.target_repository }}
RELEASE_ID: ${{ steps.release.outputs.release_id }}
RELEASE_TAG: ${{ steps.release.outputs.release_tag }}
TARGET_COMMIT_SHA: ${{ steps.release.outputs.target_commit_sha }}
DRY_RUN: ${{ steps.resolve.outputs.dry_run }}
FOCUS: ${{ steps.resolve.outputs.focus }}
CALLER_REPOSITORY: ${{ github.repository }}
AGENTIC_WORKFLOW_VERSION: ${{ job.workflow_sha }}
run: |
set -euo pipefail
args=(
review
--resolved-config "$RUNNER_TEMP/resolved-agentic-configuration.json"
--effective-policy "$RUNNER_TEMP/effective-policy.json"
--release-metadata "$RUNNER_TEMP/release-metadata.json"
--target-repository "$TARGET_REPOSITORY"
--release-id "$RELEASE_ID"
--release-tag "$RELEASE_TAG"
--target-commit-sha "$TARGET_COMMIT_SHA"
--caller-repository "$CALLER_REPOSITORY"
--target-token "$RELEASE_TARGET_TOKEN"
--target-token-forwarded "$RELEASE_TARGET_TOKEN_FORWARDED"
--repo-root "$GITHUB_WORKSPACE/release-target"
--provenance "$RUNNER_TEMP/resolved-agentic-provenance.json"
--publication-preview "$RUNNER_TEMP/agentic-publication-preview.json"
)
if [[ "$DRY_RUN" == "true" ]]; then
args+=(--dry-run)
fi
if [[ -n "$FOCUS" ]]; then
args+=(--focus "$FOCUS")
fi
python3 "$AGENTIC_WORKFLOW_ROOT/scripts/run_agentic_release_project_review.py" "${args[@]}"
- name: Upload resolved invocation artifact
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: resolved-invocation-release-project-review
path: |
${{ runner.temp }}/resolved-invocation.json
${{ runner.temp }}/resolved-agentic-configuration.json
${{ runner.temp }}/effective-policy.json
${{ runner.temp }}/release-metadata.json
${{ runner.temp }}/resolved-agentic-provenance.json
${{ runner.temp }}/agentic-publication-preview.json
retention-days: 14
if-no-files-found: ignore