Skip to content

Implement complete DOI publication workflow - #87

Merged
neuromechanist merged 2 commits into
devfrom
feature/issue-86-complete-doi-workflow
Jan 30, 2026
Merged

neuromechanist merged 2 commits into
devfrom
feature/issue-86-complete-doi-workflow

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Implements the complete DOI publication workflow as described in #86. The orchestrator now performs all steps needed to properly publish DOIs to Zenodo with dataset archives.

Changes

New Orchestrator Steps

Added 6 missing steps between doi_create and s3_lock:

  1. update_metadata - Updates dataset_description.json with pre-reserved DOI
  2. update_readme - Adds DOI badge to README.md
  3. create_tag - Creates git tag (e.g., v1.0.0) from Version field
  4. create_release - Creates GitHub release with source archive
  5. upload_to_zenodo - Downloads release archive and uploads to Zenodo
  6. publish_doi - Publishes the DOI (permanent!)

New GitHub Functions

  • createTag() - Create annotated git tags
  • createRelease() - Create GitHub releases from tags
  • downloadReleaseArchive() - Download GitHub-generated release archives

Complete Workflow

ci_check → repo_public → tag_protect → doi_create → 
update_metadata → update_readme → create_tag → create_release → 
upload_to_zenodo → publish_doi → s3_lock → notify_user

Why This Matters

The pre-reserved DOI workflow ensures data integrity:

  1. Pre-reserve DOI from Zenodo
  2. Embed DOI in dataset files (ensures DOI is in archival copy)
  3. Create git tag and GitHub release
  4. Upload complete dataset archive to Zenodo
  5. Publish DOI (permanent)

Critical: The DOI must be embedded in dataset files BEFORE creating the archive. This ensures the archived dataset contains its own DOI, preventing data loss if GitHub/S3 fails.

Testing Plan

  • Type checking passes (✅ verified)
  • Backend deploys successfully
  • E2E test with nm000151 (sandbox mode)
  • Verify DOI workflow completes all steps
  • Verify dataset_description.json contains DOI in archive
  • Verify Zenodo record is published

Related Issues

Closes #86

Add missing steps to publication orchestrator:
- update_metadata: Embed DOI in dataset_description.json
- update_readme: Add DOI badge to README.md
- create_tag: Create git tag from Version field
- create_release: Create GitHub release with archive
- upload_to_zenodo: Upload release archive to Zenodo
- publish_doi: Publish DOI (permanent)

Add GitHub helper functions:
- createTag(): Create annotated git tags
- createRelease(): Create GitHub releases
- downloadReleaseArchive(): Download release archives

Ensures DOI is embedded in dataset before archiving,
preventing data loss if GitHub/S3 fails.

Closes #86
@github-actions

github-actions Bot commented Jan 29, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR87

Version: 0.3.7-PR87.de877a0
Commit: de877a0


🤖 Updated on each push.

- Add PublicationStep union type for compile-time step name safety
- Replace dynamic imports with static imports in all 6 new steps
- Remove duplicate GITHUB_API/ORG_NAME constants from admin.ts
- Add getMainBranchSha() to github.ts service layer
- Extract helpers: readDatasetDescription, getConceptDoi, getZenodoConfig, getVersionTag
- Make updateProgress resilient (catches its own DB errors)
- Add console.error logging with full error objects in all catch blocks
- Fix publish_doi: separate DB update try/catch after irreversible publish
- Fail on missing Version field instead of silently defaulting to 1.0.0
- Add idempotency: handle 422 in createTag and createRelease for re-runs
- Add NaN check for parseInt of zenodo_concept_id
- Add JSON.parse safety with descriptive error messages
- Add content-type and size validation to downloadReleaseArchive
- Fix JSDoc: downloadReleaseArchive uses repo archive endpoint not releases API
- Add @throws annotations to new github.ts functions
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Code Review Summary

Ran 6 review agents in parallel (code reviewer, silent failure hunter, code simplifier, comment analyzer, test coverage analyzer, type design analyzer). Here is a summary of findings and the fixes applied in commit de877a0.

Critical Issues Found and Fixed

  1. No server-side logging in any of the 6 new catch blocks - Stack traces were discarded. All catch blocks now include console.error with the full error object.

  2. publish_doi DB failure after irreversible publish - If publishDeposition() succeeded but the subsequent DB update failed, the response said "DOI publication failed," which is misleading since the DOI is already live on Zenodo. Fixed: separate try/catch after the irreversible publish, with a clear message including the published DOI and "manual database correction required."

  3. updateProgress could throw inside catch blocks - If the D1 write in updateProgress failed, it would mask the original error. Fixed: updateProgress now catches its own errors internally.

  4. Duplicate GITHUB_API/ORG_NAME constants - These were duplicated in admin.ts when they already exist in github.ts. Fixed: removed from admin.ts; added getMainBranchSha() helper to github.ts service layer so admin.ts does not need raw fetch calls to GitHub API.

  5. Dynamic imports repeated 6 times - All 6 new steps used await import("../services/github") instead of static imports. Fixed: added all needed functions to the existing static import block.

High-Priority Issues Found and Fixed

  1. Silent version default to "1.0.0" - datasetDesc.Version || "1.0.0" silently defaulted for permanent DOI records with no warning. Fixed: fail with a clear error if Version field is missing; this is too important for a silent default.

  2. JSON.parse without specific error handling (4 occurrences) - Fixed: extracted readDatasetDescription() helper with descriptive error messages including content preview for debugging.

  3. No idempotency for tag/release creation - createTag and createRelease would fail on re-runs if the tag/release already existed. Fixed: both now handle HTTP 422 gracefully; createRelease fetches the existing release ID on conflict.

  4. downloadReleaseArchive no size/content-type validation - Could crash CF Worker with large archives or silently accept HTML error pages. Fixed: validates content-type and rejects archives >100MB.

  5. Number.parseInt NaN not checked - zenodo_concept_id parsed without NaN check before Zenodo API calls. Fixed: extracted getZenodoConfig() helper with NaN validation.

Code Simplification

  1. Extracted 4 helper functions to eliminate ~100 lines of duplication:
    • readDatasetDescription() - reads and parses dataset_description.json with safe JSON handling
    • getConceptDoi() - reads concept DOI from DB
    • getZenodoConfig() - reads Zenodo config with NaN validation
    • getVersionTag() - gets version/tag from dataset_description.json with Version field validation

JSDoc/Comment Fixes

  1. downloadReleaseArchive JSDoc was misleading (said "for a release" but uses the repository archive endpoint, not the releases API). Fixed with accurate description.
  2. Added @throws annotations to createTag, createRelease, downloadReleaseArchive, and getMainBranchSha.
  3. Added comment clarifying the DOI badge check limitation (does not update an existing badge if the DOI changed).

Type Safety

  1. Added PublicationStep union type - All step names, allSteps, completed, stepsCompleted, and updateProgress are now typed. Typos in step names are caught at compile time.

Not Addressed (out of scope for this PR)

  • Test coverage: The PR adds 0 test files. The test coverage analyzer rated the publish_doi step as 10/10 criticality for missing tests. Integration tests for the DOI workflow should be added in a follow-up, gated behind RUN_DOI_WORKFLOW_TESTS=true.
  • Step runner abstraction: A generic runStep() loop could further reduce boilerplate in the existing steps, but that is a broader refactor affecting pre-existing code.
  • BidsDatasetDescription interface: A typed representation of dataset_description.json would add compile-time field name checking but is a broader change.

TypeScript verification

[x] npx tsc --noEmit passes cleanly after all changes.

@neuromechanist
neuromechanist merged commit 8d6a7a3 into dev Jan 30, 2026
@neuromechanist
neuromechanist deleted the feature/issue-86-complete-doi-workflow branch January 30, 2026 01:11
@neuromechanist neuromechanist mentioned this pull request Feb 11, 2026
2 of 5 tasks

This branch was previously deployed

1 inactive deployment
npm — de877a0d Deployed Jan 30, 2026 by neuromechanist
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