Skip to content

Add approve-publication workflow - #124

Merged
neuromechanist merged 3 commits into
mainfrom
feature/approve-publication
Oct 1, 2026
Merged

neuromechanist merged 3 commits into
mainfrom
feature/approve-publication

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

What

Adds approve-publication.yml, the executor for web approvals. When an admin clicks Approve on nemar.org, the backend will send one repository_dispatch here; this workflow runs nemar admin publish approve to completion on a runner.

Approval is not a single request. After the DOI is published, the S3 Object Lock step works in batches of 100 objects that the caller must keep requesting, and the nemar CLI is the caller that loops, retries, and resumes. Running that loop in a Cloudflare Worker would cost too much, so an executor drives it. This is one executor; a terminal running the CLI is the other, and the backend route stays the contract.

Trigger and payload

repository_dispatch with event_type: approve-publication, or workflow_dispatch (same inputs, minus request_id; manual runs default to dev).

{
  "dataset_id": "nm000290",
  "request_id": 835,
  "resume": false,
  "environment": "production"
}
  • dataset_id: nm or on plus six digits; on dev also xx plus six digits (the exemplar fleet). Anything else fails the job.
  • environment: production or dev. Required for a dispatch; a missing value fails closed rather than defaulting to production.
  • resume: true runs --resume (skips completed steps). Absent means false.
  • request_id: the request the admin clicked. The run refuses to approve unless it is still the newest active request for the dataset (see Preflight).

How it works

  1. Validate. Every payload value is untrusted. It reaches the job only through env: and is checked in one step that writes the validated values to GITHUB_ENV. No ${{ }} is interpolated into any script, and a rejected value is never echoed.
  2. Install bun and the CLI, before any credential exists, so the admin key never sits in the environment of a third-party action or a package install.
  3. Credentials. The environment selects the API host and the secret from a fixed map (production is https://api.nemar.org, dev is https://api-test.nemar.org). No URL comes from the payload. There is one credentials step per environment, so a missing dev secret fails instead of falling back to the production key. The CLI is pointed at the same host as curl (TEST_API_URL) in both environments.
  4. Preflight. The key must be accepted by the admin-only list route (proving it is an admin key and the host answers). Then the dispatched request_id must still be the newest active request (requested, approving or blocked) for the dataset, because nemar admin publish approve acts on the newest one when it runs. Without this, a run that waited in a queue while an admin denied the request and the owner asked again would approve a request no admin saw. The request must also carry the admin who clicked (the backend records it on the request), since otherwise the approval would be recorded under the workflow's key. The same step decides resume from the request's real state: if the newest active request is already approving, the run resumes it, because the click-time flag can be stale and a fresh run restarts the step list. Manual runs have no request id and skip the request checks.
  5. Approve. nemar auth login --yes (the key comes from the environment, not the command line), then nemar admin publish approve <id> --yes [--resume] in a step capped at 340 minutes. --skip-ci-check is never passed.
  6. Verify. Reads GET /datasets/<id>/publish/status and fails the job unless the status is published, with a hint that depends on where the request stands. Server text goes only to the job summary file, with backticks removed. The summary names who triggered the run.

permissions: {}, timeout-minutes: 350 (same as the import copy job), and a concurrency group per environment and dataset with cancel-in-progress: false.

Findings worth knowing

  • The CLI exits 0 when an approval fails. Its error handler only prints, and an unauthenticated or declined run just returns. A green exit code does not mean a published dataset, which is why step 6 reads the final state back.
  • A resumed run restarts the S3 lock from its first page. The continuation token lives only in the CLI process. Already-locked objects count as success, so it is safe but slow, and a dataset whose lock phase outlasts the timeout cannot finish from here. Approve those from a terminal. Documented in the workflow header.

Testing

  • actionlint with shellcheck is clean.
  • The validate and preflight scripts, extracted from the workflow, were run against hostile and edge inputs: environment and id pairs (including xx on production, newline and command-substitution payloads, wrong case, unknown environment) and a local stand-in for the list route (request still newest and claimed, not claimed, older backend, approving forces resume, denied then re-requested, newer blocked request, no active request, manual run, wrong key, unreachable host).
  • Not run on a real runner: nothing has dispatched it. After merge, a workflow_dispatch with environment=dev for a dataset that has no active request exercises install, login, preflight and verify without changing anything.

Secrets

Secret Status
NEMAR_ADMIN_API_KEY Exists: onboard-openneuro.yml in this repo already uses it. Value not read.
NEMAR_ADMIN_API_KEY_DEV Not established. No workflow here uses a dev admin secret, and nemar-cli's dev admin secret (TEST_ADMIN_API_KEY) lives on that repo, not this one. It must be created on nemarDatasets/.github before environment=dev works. Production does not need it.

Deploy order

Merge this before the backend dispatches in production. A dispatch with no workflow does nothing, so the page would show the approval as queued forever. The backend route and migration go to dev first, then production, then the website.

Testing

  • actionlint (with shellcheck) passes, and fails on a deliberately broken copy
  • yamllint passes
  • Validate step run against valid input and hostile input (command injection, an embedded newline setting API_URL, path traversal, wrong case, unknown environment, resume: yes): all rejected, nothing written
  • Preflight and verify steps run against a local stub API that checks the Bearer header: accepts the right key, rejects a wrong key and an unreachable host, passes only on published, and keeps hostile server text out of the log
  • Approve step run with a fake CLI: flags are built correctly and the exit code is recorded and propagated. This caught a bug (errexit aborted the step before the code was written), fixed in this PR.
  • Not run on a real runner: act is not installed here, and a dispatch would run a real approval
  • Not verified: that NEMAR_ADMIN_API_KEY is an admin key on production, that the dev secret exists, and that the dev Worker's dispatch reaches this repo. The published nemar-cli (0.10.11) matches the source I read for --yes and TEST_API_URL.

Notes

  • The contract names https://api-test.nemar.org for dev. nemar-cli's own test workflows use https://nemar-api-dev.sccn-org.workers.dev. If those are different deployments, the dev URL in the validation step needs to match whichever the dev Worker serves.
  • GitHub keeps one waiting run per concurrency group, so a third dispatch for the same dataset replaces the second. The backend refuses a new dispatch while one is in flight, so this should not occur in practice.

Runs a publication approval to completion on a runner by driving the
nemar CLI loop, so the web Approve button can hand off to it. Inputs
are validated and the environment picks both API host and credential
from a fixed map. The job reads the request's final state back from
the API and fails unless it is published, because the CLI exits 0 on
a failed approval.

Tested: actionlint with shellcheck, yamllint, and the validate,
preflight, approve, and verify steps run locally against hostile
input, a stub API, and a fake CLI. Not run on a real runner.
Refuse to approve unless the dispatched request is still the newest
active one for the dataset, so a delayed run cannot approve a
re-request nobody clicked. Accept xx exemplar ids on dev only. Install
bun and the CLI before the admin key is selected, and log in from the
environment so the key stays off the command line. Default manual runs
to dev, point the CLI at the same host as curl in both environments,
time-box the approve step so the verify step always runs, name the
trigger in the summary, branch the final hint on the request status,
and document the S3 lock resume limit.

Tested: actionlint with shellcheck; the validate and preflight scripts
run against hostile inputs and a local stand-in API.
A click-time resume flag goes stale when a second dispatch follows a
first that already ran steps, and a fresh run restarts the step list.
The preflight now forces --resume when the newest active request is
approving. It also fails when the dispatched request carries no
claiming admin, since the approval would then be recorded under the
workflow's key.

Tested: actionlint; the preflight script against a local stand-in API
(claimed, unclaimed, older backend, approving, re-request, manual).
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