Skip to content

Phase 4: dataset-repo workflows use App-minted tokens (#439) - #444

Merged
neuromechanist merged 2 commits into
feature/issue-432-epic-github-appfrom
feature/issue-439-phase4-workflow-app-tokens
May 11, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-432-epic-github-appfrom
feature/issue-439-phase4-workflow-app-tokens

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Migrates the 4 `secrets.GITHUB_TOKEN` references in `pr-merge`, `llm-enrichment`, and `version-doi` workflow templates to App-issued installation tokens via `actions/create-github-app-token@v1`.

Original epic scope said "replace `secrets.NEMAR_GITHUB_PAT`" — audit showed no such reference in any workflow template. With user sign-off, rescoped to migrate the `secrets.GITHUB_TOKEN` usages so every dataset-repo CI write carries `nemar-publish-bot[bot]` identity, matching the Worker's auth path now that Phase 3 routes orchestrator calls through the App.

Sanity guarantees

Check Before After
`grep -c "secrets.GITHUB_TOKEN" backend/src/services/github.ts` 4 0
`grep -c "create-github-app-token@v1" backend/src/services/github.ts` 0 4 (pr-merge ×1, llm-enrichment ×1, version-doi ×2)

What this PR ships

  • pr-merge.yml create-release job: app-token step prepended; `actions/checkout` token, `GH_TOKEN` env, and git author/email all swap to the App.
  • llm-enrichment.yml enrich job: app-token step + checkout `token:` override so commit + push of enrichment metadata authenticate as the App.
  • version-doi.yml: app-token step in BOTH jobs (publish-doi for `gh release create`, trigger-archive for `gh api repos/.../dispatches`).
  • App-token `repositories:` scope is the calling repo only — least privilege; a misbehaving workflow can only write to its own dataset.
  • `docs/guides/github-app-setup.md` updated:
    • Actions permission bumped from Read-only to Read & write (required for the trigger-archive dispatch).
    • New Phase 4 ops section: accept the App permission upgrade, set `NEMAR_APP_ID` + `NEMAR_APP_PRIVATE_KEY` org secrets on nemarDatasets, refresh existing dataset repos via `nemar admin ci add`.
  • `test/workflow-yaml.test.ts` (13 tests, all green):
    • Each migrated template has the right `app-token` step inputs.
    • version-doi has exactly 2 `app-token` steps (regression guard for the per-job mint requirement).
    • Read-only / AWS-only templates (`bids-validation`, `version-check`, `generate-archive`) have no app-token reference (drift guard).

What's NOT in this PR

  • The Worker's `GITHUB_ADMIN_PAT` env var — Phase 5 (Phase 5: Decommission GITHUB_ADMIN_PAT (#432) #440) owns the decommission.
  • bids-validation / version-check / generate-archive templates — no GitHub-write that benefits from App identity; auto-token stays.
  • Any `Bindings` change. The new org-level secrets live on `nemarDatasets`, not on the Worker.

Rollout (ops, after merge)

  1. Accept the App permission upgrade in the GitHub UI for both org installations (nemarOrg + nemarDatasets). The new template needs Actions: Read & write; the App was installed with Actions: Read-only.
  2. Set org secrets on `nemarDatasets`:
    • `NEMAR_APP_ID` = the same numeric App ID stored in 1Password.
    • `NEMAR_APP_PRIVATE_KEY` = the PKCS#8 PEM from Phase 1, pasted in full.
  3. Refresh existing dataset repos so they pick up the new template:
    ```
    nemar admin ci add
    ```
    Or sweep via the bulk pattern proven in the May 2026 archive-refresh.

Until step 3 happens for a given dataset, that dataset's CI keeps running the old template with `secrets.GITHUB_TOKEN` — no breakage, gradual rollout.

Test plan

  • `bunx tsc --noEmit` clean at repo root and `backend/`.
  • `bun test test/workflow-yaml.test.ts` — 13 pass / 0 fail.
  • Sanity guarantees above hold.
  • Post-merge ops: one dataset repo refreshed + a write workflow exercised; confirm "Mint App installation token" step succeeds and downstream write is attributed to `nemar-publish-bot[bot]` in the Actions log.

Closes #439. Part of epic #432.

Migrates the 4 `secrets.GITHUB_TOKEN` references in pr-merge,
llm-enrichment, and version-doi over to App-issued installation tokens
via actions/create-github-app-token@v1.

Original epic scope said "replace secrets.NEMAR_GITHUB_PAT" but the
audit found no NEMAR_GITHUB_PAT in any workflow template. Rescoped
with user approval: end state is unified bot identity
(nemar-publish-bot[bot]) for every CI write in dataset repos, matching
the Worker's auth path now that Phase 3 has routed orchestrator calls
through the App.

backend/src/services/github.ts:
- pr-merge.yml `create-release` job: prepend the app-token step,
  override actions/checkout `token:` to the App, swap `GH_TOKEN` env
  for the App, and bump the local git author/email to
  `nemar-publish-bot` to match the resulting commit identity on the
  release tag.
- llm-enrichment.yml `enrich` job: prepend app-token step, override
  checkout `token:` so subsequent `git commit` + `git push` of the
  enrichment metadata authenticate as the App.
- version-doi.yml `publish-doi` job: prepend app-token step, swap
  `GH_TOKEN` for the App so `gh release view`/`gh release create`
  attribute the release to the App.
- version-doi.yml `trigger-archive` job: prepend app-token step (the
  second one in this template by design — each job mints its own
  token), swap `GH_TOKEN` for the App so the
  `gh api repos/.../dispatches` call carries Actions: write from the
  App's installation.

The `repositories: ${{ github.event.repository.name }}` scope on every
app-token step gives least-privilege: even if a workflow misbehaves,
the token can only write to its own dataset repo.

docs/guides/github-app-setup.md:
- Bump the Actions permission in the install instructions from
  Read-only to Read & write (the new `gh api dispatches` call needs
  Actions: write).
- New "Phase 4: dataset-repo CI uses the same App" section with the
  3 ops steps: accept the permission upgrade, set NEMAR_APP_ID +
  NEMAR_APP_PRIVATE_KEY org-level secrets on nemarDatasets, then
  refresh existing dataset repos via `nemar admin ci add`.
- Phase 4 acceptance checklist.

test/workflow-yaml.test.ts:
- New test: each of the three migrated templates has an
  actions/create-github-app-token@v1 step with the right inputs and
  zero `secrets.GITHUB_TOKEN` references.
- New test: version-doi has exactly two app-token steps (one per job).
- New test: the three NOT-migrated templates (bids-validation,
  version-check, generate-archive) have no create-github-app-token
  reference, so future drift in either direction gets caught.

13/13 workflow-yaml tests pass (was 10). tsc --noEmit clean.

Sanity guarantees:
- `grep -c secrets.GITHUB_TOKEN backend/src/services/github.ts` → 0
  (was 4 before this PR).
- `grep -c create-github-app-token backend/src/services/github.ts` → 4
  (pr-merge×1 + llm-enrichment×1 + version-doi×2).

Rollout (ops, after merge):
1. Accept the App permission upgrade in the GitHub UI on both org
   installations.
2. Set NEMAR_APP_ID + NEMAR_APP_PRIVATE_KEY org secrets on
   nemarDatasets (visibility: All repositories).
3. Refresh existing dataset repos: `nemar admin ci add <id>` for each,
   or the bulk sweep pattern proven in the May 2026 archive-refresh
   pass.

Closes #439. Part of epic #432.
@github-actions

github-actions Bot commented May 11, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR444

Version: 0.8.11-PR444.da04c70
Commit: da04c70


🤖 Updated on each push.

code-reviewer:
- llm-enrichment.yml git config used nemar-bot / [email protected],
  contradicting the unified bot identity goal. Swap to
  nemar-publish-bot to match pr-merge and so commit author records
  the App identity authentication uses for the push.

pr-test-analyzer:
- Reparse migrated templates via the existing YAML parser and assert
  structural invariants:
  - The app-token step is at index 0 (must precede checkout/gh
    calls that reference its outputs).
  - with.app-id, with.private-key, with.owner, with.repositories
    are pinned to the exact expected values (not just substring
    presence; catches a hardcoded `repositories: nm000103`).
  - Every GH_TOKEN env block in migrated jobs points at
    steps.app-token.outputs.token (catches partial migrations).

comment-analyzer:
- Drop "Phase 4" framing from runbook section heading + body +
  subheading. The chronological anchor lives in commits and the
  epic issue, not in long-lived ops docs.
- Drop `(#439)` from test name; project rule on rot-prone refs.
- Collapse the 4-bullet test comment that restated each expect()
  into one WHY line.

Defer with PR note (silent-failure-hunter HIGH findings):
- Pre-check guard for missing org secrets — single extra step per
  job; the runbook is explicit and the failure shape, while not
  ideal, is recoverable in one ops cycle.
- 403-on-dispatch hint — operationally acceptable; cause is named
  in the error body.
- Tag-push branch-protection hint — current allowlist includes the
  bot; if that changes, follow-up.
- repositories: scope fallback — every current trigger populates
  github.event.repository.name; defensive fallback can land when a
  new trigger shape is added.
- Two-mint silent drop in version-doi — orchestrator's
  generate_archive retry path covers it; in-workflow warning would
  add noise without a clearer recovery action.

13/13 tests pass (was 10 with 114 expect() calls). tsc --noEmit clean.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings addressed (commit da04c70)

Four reviews aggregated.

Source Finding Action
code-reviewer `llm-enrichment.yml` git config used `nemar-bot` / `[email protected]`, contradicting the unified-identity goal Fixed: swapped to `nemar-publish-bot` to match pr-merge and the App-authenticated push identity.
pr-test-analyzer Tests checked substring presence only; future copy-paste of a hardcoded `repositories: nm000103` would slip through. Step-ordering, owner/repositories pinning, and positive GH_TOKEN-value assertions missing Fixed: reparse migrated templates via the existing YAML parser and structurally assert (a) the app-token step is at `steps[0]`, (b) `with.app-id` / `with.private-key` / `with.owner` / `with.repositories` equal the exact expected values, (c) every `GH_TOKEN` env in migrated jobs points at `steps.app-token.outputs.token`. 11 new `expect()` calls.
comment-analyzer Rot-prone "Phase 4" framing in runbook heading + body + subheading; rot-prone `(#439)` token in test name; 4-bullet test comment restated WHAT Fixed: runbook heading is now "Dataset-repo CI uses the same App", body sentence is "This step raises Actions...", subheading is "Acceptance"; dropped `(#439)`; collapsed the bullet comment to one WHY line.
silent-failure-hunter Five HIGH findings (pre-check guard for missing secrets, 403-on-dispatch hint, tag-push branch-protection hint, `repositories:` scope fallback, two-mint silent drop) Deferred with rationale below.

On the deferred silent-failure findings

These are real concerns but I traded the in-template instrumentation for cleaner workflows and a more explicit runbook:

  1. Missing-secret pre-check guard — adding a step per migrated job to verify `secrets.NEMAR_APP_ID` / `NEMAR_APP_PRIVATE_KEY` is non-empty. Saves ~10 min of ops debug time on a first-run refresh-before-secrets scenario. Runbook step 2 is explicit and orderered; the failure shape is recoverable in one cycle. Skip the noise.
  2. 403-on-dispatch hint — `gh api` already prints the response body, which names "Resource not accessible by integration" on a permission-not-accepted case. The runbook step 1 calls this out before step 3 (refresh).
  3. Tag-push branch-protection hint — would only fire if someone removes `nemar-publish-bot[bot]` from the bypass allowlist. Caught at the time of removal, not in CI.
  4. `repositories:` scope fallback — every current trigger shape (`pull_request`, `push`, `repository_dispatch`) populates `github.event.repository.name`. Defensive fallback can land when a new trigger shape is introduced.
  5. Two-mint silent drop in version-doi — the orchestrator already has a `generate_archive` retry path (`backend/src/routes/admin.ts`). A red `trigger-archive` job is visible in the Actions UI; the orchestrator's retry covers the recovery flow.

If any of (1)–(5) turn out to bite in practice during the rollout, they're each ~5-line additions and can ship as Phase 4 follow-ups without disturbing the structural pattern this PR lands.

13/13 tests pass, 114 `expect()` calls (was 103). `tsc --noEmit` clean.

@neuromechanist
neuromechanist merged commit 01dc9ae into feature/issue-432-epic-github-app May 11, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-439-phase4-workflow-app-tokens branch May 11, 2026 17:25

This branch was previously deployed

1 inactive deployment
npm — da04c707 Deployed May 11, 2026 by neuromechanist via publish #771
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant