@eduardo191labs/opencode-actions 0.1.2 → 0.1.3
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 +192 -5
- package/action.yml +18 -0
- package/dist/actions.d.ts +266 -68
- package/dist/actions.js +134 -24
- package/dist/app-auth.d.ts +70 -0
- package/dist/app-auth.js +137 -0
- package/dist/cli.js +34 -3
- package/dist/commands.d.ts +3 -1
- package/dist/commands.js +59 -19
- package/dist/config.d.ts +5 -1
- package/dist/config.js +1 -1
- package/dist/detect.d.ts +37 -4
- package/dist/detect.js +101 -138
- package/dist/format.d.ts +3 -1
- package/dist/format.js +5 -2
- package/dist/git.d.ts +16 -0
- package/dist/git.js +23 -1
- package/dist/github.d.ts +9 -1
- package/dist/implement.d.ts +116 -0
- package/dist/implement.js +192 -0
- package/dist/install.js +195 -20
- package/dist/signals.d.ts +134 -0
- package/dist/signals.js +117 -0
- package/dist/summary.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -247,8 +247,18 @@ When `config-repo` is **private**, pass `config-token` with a token that can rea
|
|
|
247
247
|
|
|
248
248
|
The installer detects the stack in each repository (Node, Rust, Go, Python, JVM,
|
|
249
249
|
Ruby, PHP, C/C++, .NET, Swift, Dart), skips archived, disabled and forked ones, and
|
|
250
|
-
writes
|
|
251
|
-
|
|
250
|
+
writes the workflows that only touch files it owns. Re-running is safe: a workflow
|
|
251
|
+
file without the bot marker is never overwritten.
|
|
252
|
+
|
|
253
|
+
**It installs itself.** The `Install` workflow runs every six hours with `--auto`,
|
|
254
|
+
which treats a repository that already has the bot as skipped. A new repository is
|
|
255
|
+
picked up on the next pass, and one where the bot was removed is repaired. No person
|
|
256
|
+
runs anything.
|
|
257
|
+
|
|
258
|
+
With the GitHub App configured (next section) no personal token is involved. Without
|
|
259
|
+
it, the workflow falls back to `OPENCODE_INSTALL_TOKEN`, a fine-grained token with
|
|
260
|
+
**Administration: write** on the target repositories; `GITHUB_TOKEN` cannot install
|
|
261
|
+
into other repositories.
|
|
252
262
|
|
|
253
263
|
```bash
|
|
254
264
|
# Preview
|
|
@@ -277,9 +287,173 @@ on:
|
|
|
277
287
|
dry_run: { type: boolean, default: true }
|
|
278
288
|
```
|
|
279
289
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
290
|
+
The workflow needs `OPENCODE_APP_ID` and `OPENCODE_APP_PRIVATE_KEY`, or
|
|
291
|
+
`OPENCODE_INSTALL_TOKEN` as a fallback.
|
|
292
|
+
|
|
293
|
+
### What triggers an install
|
|
294
|
+
|
|
295
|
+
There is no schedule. Every run is caused by GitHub saying something changed:
|
|
296
|
+
|
|
297
|
+
| Event | When it happens |
|
|
298
|
+
|---|---|
|
|
299
|
+
| `installation` | the app was installed |
|
|
300
|
+
| `installation_repositories` | a repository was granted to the installation |
|
|
301
|
+
| `repository` | a repository was created, forked, made public, renamed or transferred |
|
|
302
|
+
| `issues` | an issue was opened |
|
|
303
|
+
| `issue_comment` | a command or `@mention` was posted |
|
|
304
|
+
| `pull_request` | a pull request opened, synchronised or became ready |
|
|
305
|
+
| `pull_request_review_comment` | a comment on a diff line |
|
|
306
|
+
| `workflow_run` | a workflow finished, for the autofix |
|
|
307
|
+
|
|
308
|
+
`installation` and `installation_repositories` are lifecycle events: GitHub
|
|
309
|
+
delivers them to every app and rejects them inside a manifest's
|
|
310
|
+
`default_events`, so they are not listed and still arrive.
|
|
311
|
+
|
|
312
|
+
**Everything else has to be subscribed, once, by hand.** A GitHub App receives exactly the
|
|
313
|
+
events listed under *Subscribe to events*, with no exceptions — an app with an
|
|
314
|
+
empty list only ever hears about installations, `check_suite` and pings. The API
|
|
315
|
+
cannot change that list either: `PATCH /app` returns 404 for permissions and
|
|
316
|
+
events, which is why the broker and the native workflow trigger both exist. Set
|
|
317
|
+
them in the app's settings, *Permissions & events*:
|
|
318
|
+
|
|
319
|
+
https://github.com/settings/apps/opencode-actions-bot-new/permissions
|
|
320
|
+
|
|
321
|
+
Tick these six under *Subscribe to events*, then **Save changes**:
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
Issues Issue comment
|
|
325
|
+
Pull request Pull request review
|
|
326
|
+
Pull request review comment Workflow run
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
`PATCH /app` answers 404 for events, so this is the one step the API cannot do.
|
|
330
|
+
Without it the bot still works through each repository's own workflow trigger,
|
|
331
|
+
but the Cloudflare broker never sees an event and cannot skip anything.
|
|
332
|
+
|
|
333
|
+
**Forks are installed like any other repository.** A fork gets pull requests and
|
|
334
|
+
issues, so skipping it left the bot out of exactly where a contributor works.
|
|
335
|
+
`--exclude-forks` opts out. Archived and disabled repositories are still skipped,
|
|
336
|
+
because nothing happens in them.
|
|
337
|
+
|
|
338
|
+
The only repository the installer skips by default is the configuration one,
|
|
339
|
+
which is passed to `--exclude`.
|
|
340
|
+
|
|
341
|
+
### The webhook worker
|
|
342
|
+
|
|
343
|
+
`webhook/worker.js` runs on Cloudflare Workers: free tier, no dependencies, no
|
|
344
|
+
build step. It verifies `X-Hub-Signature-256` before parsing a byte, then asks the
|
|
345
|
+
`Install` workflow to run.
|
|
346
|
+
|
|
347
|
+
Deployment is automatic. Pushing anything under `webhook/` triggers
|
|
348
|
+
`.github/workflows/webhook.yml`, which tests the worker, deploys it, and checks
|
|
349
|
+
that a signed ping is accepted and a forged one refused. It needs two repository
|
|
350
|
+
secrets:
|
|
351
|
+
|
|
352
|
+
| Secret | Purpose |
|
|
353
|
+
|---|---|
|
|
354
|
+
| `CLOUDFLARE_API_TOKEN` | Workers Scripts: Edit |
|
|
355
|
+
| `CLOUDFLARE_ACCOUNT_ID` | the account id from the dashboard |
|
|
356
|
+
|
|
357
|
+
The worker's own secrets are set once and survive redeploys:
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
npx wrangler secret put WEBHOOK_SECRET --config wrangler.toml
|
|
361
|
+
npx wrangler secret put APP_PRIVATE_KEY --config wrangler.toml
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
The app's webhook is configured from the manifest at creation, so there is
|
|
365
|
+
nothing to paste. `scripts/wire-webhook.js` repairs a mismatch between the two:
|
|
366
|
+
it writes the worker's secrets and `PATCH /app/hook/config` in one step, because
|
|
367
|
+
a deploy that rewrites `WEBHOOK_SECRET` silently breaks every delivery.
|
|
368
|
+
|
|
369
|
+
What happens after a repository is created or forked:
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
GitHub ── webhook ──▶ Worker ── verify HMAC ──▶ repository_dispatch(install-requested)
|
|
373
|
+
│
|
|
374
|
+
▼
|
|
375
|
+
Install workflow → discover → write workflows
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
The worker never writes to a repository. It verifies the signature, mints an
|
|
379
|
+
installation token for the one repository it needs, and asks the `Install`
|
|
380
|
+
workflow to run. The installer stays the only thing that knows how to write, so
|
|
381
|
+
there is one implementation and not two.
|
|
382
|
+
|
|
383
|
+
Why a worker at all: Actions cannot react to "a repository exists now" in another
|
|
384
|
+
repository, and a schedule is both slow and wasteful. The six-hour sweep stays as
|
|
385
|
+
a safety net for what a webhook cannot see, such as a workflow deleted by hand.
|
|
386
|
+
|
|
387
|
+
The worker rejects anything whose `X-Hub-Signature-256` does not match, before
|
|
388
|
+
parsing a byte of the body, and ignores every event except those two.
|
|
389
|
+
|
|
390
|
+
### A GitHub App, so new repositories are covered on their own
|
|
391
|
+
|
|
392
|
+
The installer can act as a **GitHub App** instead of a personal token. That changes
|
|
393
|
+
three things worth understanding:
|
|
394
|
+
|
|
395
|
+
| | `GITHUB_TOKEN` / PAT | GitHub App installation token |
|
|
396
|
+
|---|---|---|
|
|
397
|
+
| Scope | one repository (or everything a PAT can reach) | only the repositories the owner picked |
|
|
398
|
+
| Lifetime | the workflow run / until the PAT expires | one hour, minted per run |
|
|
399
|
+
| New repositories | never found | covered as soon as the installation covers the account |
|
|
400
|
+
| Writing workflows and secrets | needs an admin PAT | granted by the manifest, per permission |
|
|
401
|
+
|
|
402
|
+
Create the app once:
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
node scripts/create-app.js --owner <you> --name opencode-actions-bot
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
It opens one page, GitHub asks you to confirm, and the app id and private key are
|
|
409
|
+
written as `OPENCODE_APP_ID` and `OPENCODE_APP_PRIVATE_KEY`. Then install it:
|
|
410
|
+
|
|
411
|
+
<https://github.com/apps/opencode-actions-bot/installations/new>
|
|
412
|
+
|
|
413
|
+
Pick the account and **All repositories** if new repositories should be covered
|
|
414
|
+
automatically, or a selection if the bot should never touch the rest.
|
|
415
|
+
|
|
416
|
+
The manifest in `github-app-manifest.json` requests what the bot uses, nothing more:
|
|
417
|
+
|
|
418
|
+
```json
|
|
419
|
+
"contents": "write", "pull_requests": "write", "issues": "write",
|
|
420
|
+
"workflows": "write", "secrets": "write", "administration": "write",
|
|
421
|
+
"checks": "write", "statuses": "write", "actions": "write",
|
|
422
|
+
"environments": "write", "deployments": "write", "discussions": "write",
|
|
423
|
+
"packages": "write", "pages": "write", "repository_projects": "write",
|
|
424
|
+
"security_events": "write", "metadata": "read",
|
|
425
|
+
"secret_scanning_alerts": "read", "vulnerability_alerts": "read"
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
What each one buys:
|
|
429
|
+
|
|
430
|
+
| Permission | Why |
|
|
431
|
+
|---|---|
|
|
432
|
+
| `contents`, `pull_requests`, `issues` | commit, open and merge PRs, comment, triage |
|
|
433
|
+
| `workflows` | the installer commits the five workflow files |
|
|
434
|
+
| `secrets` | the installer writes `FREEPI_JWT` and the app credentials per repository |
|
|
435
|
+
| `administration` | default workflow permissions and repository settings |
|
|
436
|
+
| `checks`, `statuses` | report review results on the commit |
|
|
437
|
+
| `actions` | inspect failing runs for autofix |
|
|
438
|
+
| `environments`, `deployments` | deploy-related commands |
|
|
439
|
+
| `discussions`, `packages`, `pages`, `repository_projects` | the wider command surface |
|
|
440
|
+
| `security_events`, `secret_scanning_alerts`, `vulnerability_alerts` | read-only security context |
|
|
441
|
+
| `metadata` | mandatory for every app |
|
|
442
|
+
|
|
443
|
+
> Changing permissions on an existing app has **no API**: `PATCH /app` answers
|
|
444
|
+
> `404`. Either edit them in the app settings, or create the app again from the
|
|
445
|
+
> updated manifest with
|
|
446
|
+
> `node scripts/create-app.js --name <name>`, which is what the manifest is for.
|
|
447
|
+
|
|
448
|
+
At run time the CLI exchanges the app JWT for an installation token for the
|
|
449
|
+
repository in the event, sets it as `GITHUB_TOKEN` (so `git push` keeps working)
|
|
450
|
+
and proceeds exactly as before. If the app is not installed on a repository, the
|
|
451
|
+
run fails with the install URL instead of writing anything.
|
|
452
|
+
|
|
453
|
+
The `Install` workflow uses the same credentials: discovery lists
|
|
454
|
+
`/installation/repositories`, which includes a repository created seconds earlier,
|
|
455
|
+
so **a new repository is picked up by the next scheduled pass with nobody doing
|
|
456
|
+
anything**. The schedule is every six hours.
|
|
283
457
|
|
|
284
458
|
### Detecting a repository
|
|
285
459
|
|
|
@@ -309,6 +483,19 @@ opencode-actions --mode capabilities # what the bot may do on GitHub
|
|
|
309
483
|
| `/bot close` / `/bot reopen` | Change issue or PR state. |
|
|
310
484
|
| `/bot help` | List commands. |
|
|
311
485
|
|
|
486
|
+
The bot answers to three shapes, and a bare mention counts:
|
|
487
|
+
|
|
488
|
+
| You write | The bot does |
|
|
489
|
+
|---|---|
|
|
490
|
+
| `/bot review` | runs the `review` command |
|
|
491
|
+
| `@opencode review` | the same |
|
|
492
|
+
| `@opencode how does the retry loop work?` | `answer` — a mention with no keyword is a question |
|
|
493
|
+
| `@opencode-actions-bot fix the null check` | the app slug works too, because that is what autocomplete inserts |
|
|
494
|
+
|
|
495
|
+
Names are configurable: `bot.name` sets the primary mention and `bot.aliases`
|
|
496
|
+
adds more, so `@bot` can coexist with the long slug. A mention inside an email
|
|
497
|
+
address or a code fence is ignored.
|
|
498
|
+
|
|
312
499
|
Commands also work in a **line comment on the diff**: GitHub sends the file, the line
|
|
313
500
|
and the hunk, so the answer is posted in that same thread. A plain comment there is
|
|
314
501
|
ignored unless the bot is mentioned, and `/bot fix` commits the change to the head
|
package/action.yml
CHANGED
|
@@ -15,6 +15,10 @@ inputs:
|
|
|
15
15
|
description: "Inline configuration (JSON or YAML). Overrides the config repository."
|
|
16
16
|
required: false
|
|
17
17
|
default: ""
|
|
18
|
+
payload:
|
|
19
|
+
description: "Path to an event payload. A forwarded { event, payload } object is unwrapped."
|
|
20
|
+
required: false
|
|
21
|
+
default: ""
|
|
18
22
|
config-repo:
|
|
19
23
|
description: "Repository holding opencode-actions.yml, e.g. my-org/bot-config."
|
|
20
24
|
required: false
|
|
@@ -30,6 +34,14 @@ inputs:
|
|
|
30
34
|
github-token:
|
|
31
35
|
description: "Token used for GitHub operations. Needs contents, pull-requests, issues and actions scope."
|
|
32
36
|
required: true
|
|
37
|
+
app-id:
|
|
38
|
+
description: "GitHub App id. When set with app-private-key, the run acts as the app instead of the token."
|
|
39
|
+
required: false
|
|
40
|
+
default: ""
|
|
41
|
+
app-private-key:
|
|
42
|
+
description: "GitHub App private key (PEM). The installation token is minted per run and never stored."
|
|
43
|
+
required: false
|
|
44
|
+
default: ""
|
|
33
45
|
opencode-token:
|
|
34
46
|
description: "Token for the OpenCode service, if you use a managed provider."
|
|
35
47
|
required: false
|
|
@@ -228,6 +240,10 @@ runs:
|
|
|
228
240
|
shell: bash
|
|
229
241
|
env:
|
|
230
242
|
GITHUB_TOKEN: ${{ inputs.github-token }}
|
|
243
|
+
# The app wins when both halves are present: the CLI exchanges the app
|
|
244
|
+
# JWT for an installation token and exports it as GITHUB_TOKEN.
|
|
245
|
+
OPENCODE_APP_ID: ${{ inputs.app-id || env.OPENCODE_APP_ID }}
|
|
246
|
+
OPENCODE_APP_PRIVATE_KEY: ${{ inputs.app-private-key || env.OPENCODE_APP_PRIVATE_KEY }}
|
|
231
247
|
OPENCODE_TOKEN: ${{ inputs.opencode-token }}
|
|
232
248
|
OPENCODE_ACTIONS_CONFIG_REPO: ${{ inputs.config-repo }}
|
|
233
249
|
OPENCODE_ACTIONS_CONFIG_REF: ${{ inputs.config-ref }}
|
|
@@ -243,6 +259,7 @@ runs:
|
|
|
243
259
|
INPUT_LIVE: ${{ inputs.live }}
|
|
244
260
|
INPUT_SUMMARY: ${{ inputs.summary }}
|
|
245
261
|
INPUT_DRY_RUN: ${{ inputs.dry-run }}
|
|
262
|
+
INPUT_PAYLOAD: ${{ inputs.payload }}
|
|
246
263
|
OPENCODE_LOG_STYLE: github
|
|
247
264
|
# The configuration uses the V2 permissions ruleset; there is no V1 path.
|
|
248
265
|
OPENCODE_CONFIG_PROTOCOL: v2
|
|
@@ -258,6 +275,7 @@ runs:
|
|
|
258
275
|
if [ -n "${INPUT_PR:-}" ]; then ARGS+=(--pr "$INPUT_PR"); fi
|
|
259
276
|
if [ -n "${INPUT_ISSUE:-}" ]; then ARGS+=(--issue "$INPUT_ISSUE"); fi
|
|
260
277
|
if [ -n "${INPUT_RUN_ID:-}" ]; then ARGS+=(--run-id "$INPUT_RUN_ID"); fi
|
|
278
|
+
if [ -n "${INPUT_PAYLOAD:-}" ]; then ARGS+=(--payload "$INPUT_PAYLOAD"); fi
|
|
261
279
|
if [ "${INPUT_DRY_RUN:-false}" = "true" ]; then ARGS+=(--dry-run); fi
|
|
262
280
|
|
|
263
281
|
BIN="$RUNNER_TEMP/opencode-actions/node_modules/@eduardo191labs/opencode-actions/dist/cli.js"
|