feat(cli): add fern automations upgrade command#15537
feat(cli): add fern automations upgrade command#15537devin-ai-integration[bot] wants to merge 4 commits intomainfrom
fern automations upgrade command#15537Conversation
…output Add `fern automations upgrade` command that wraps `fern upgrade` and `fern generator upgrade` into a single invocation with `--json` output. Designed for consumption by the fern-upgrade GitHub Action, replacing the snapshot.js / diff.js approach with a single CLI call. Also replace the brittle hardcoded changelog URL map in upgradeGenerator.ts with a regex-based derivation that supports all current and future generators. Co-Authored-By: barry.zou <barry.zou@buildwithfern.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
The CliContext.enableJsonMode() middleware redirects process.stdout to stderr as a safety net. Use writeJsonToStdout() which temporarily restores stdout before writing, ensuring JSON output goes to fd 1. Co-Authored-By: barry.zou <barry.zou@buildwithfern.com>
Testing Results:
|
| Test | Result |
|---|---|
| JSON output to stdout (not stderr) | ✅ Pass |
| JSON schema correctness (11 assertions) | ✅ Pass |
| Human-readable output (no --json) | ✅ Pass |
| File modifications applied | ✅ Pass |
| Help text shows both flags | ✅ Pass |
Test 1: JSON stdout vs stderr (critical fix verification)
Verified writeJsonToStdout() fix using shell fd redirects (1>/tmp/stdout.txt 2>/tmp/stderr.txt):
- stdout: Valid JSON with correct schema (
cli,generators,skippedMajor,alreadyUpToDate) - stderr: Log messages only (
"Running CLI upgrade...","Running generator upgrades...") - Before the fix, JSON went to stderr due to
enableJsonMode()redirecting stdout
JSON output (--json --include-major)
{
"cli": { "from": "4.66.0", "to": "4.66.0", "upgraded": false },
"generators": [
{ "name": "fernapi/fern-csharp-sdk", "group": "csharp-sdk", "api": "internal", "from": "1.6.0", "to": "1.7.0", "changelog": "https://buildwithfern.com/learn/sdks/generators/csharp/changelog", "migrationsApplied": 0 },
{ "name": "fernapi/fern-python-sdk", "group": "python-sdk", "api": "api", "from": "4.3.0", "to": "4.2.7", "changelog": "https://buildwithfern.com/learn/sdks/generators/python/changelog", "migrationsApplied": 0 },
{ "name": "fernapi/fern-java-sdk", "group": "java-sdk", "api": "api", "from": "2.6.0", "to": "2.2.0", "changelog": "https://buildwithfern.com/learn/sdks/generators/java/changelog", "migrationsApplied": 0 },
{ "name": "fernapi/fern-go-sdk", "group": "go-sdk", "api": "api", "from": "0.28.0", "to": "0.27.0", "changelog": "https://buildwithfern.com/learn/sdks/generators/go/changelog", "migrationsApplied": 0 }
],
"skippedMajor": [],
"alreadyUpToDate": []
}Human-readable output (no --json)
CLI: 4.66.0 (already up to date)
Generators upgraded: 4
fernapi/fern-csharp-sdk: 1.6.0 -> 1.7.0
fernapi/fern-python-sdk: 4.3.0 -> 4.2.7
fernapi/fern-java-sdk: 2.6.0 -> 2.2.0
fernapi/fern-go-sdk: 0.28.0 -> 0.27.0
Caveats (dev2 environment)
- TypeScript silently dropped: dev2 registry returns null for TS
getLatestGeneratorVersion()— pre-existing behavior inupgradeGenerator.ts, not a bug in this PR - Version "downgrades" (Python 4.3.0→4.2.7, etc.): dev2 registry has older "latest" versions than production — expected for local dev testing
- CLI
upgraded: false: dev CLI v0.0.0 can't actually upgrade fern.config.json version
Sort generators, skippedMajor, and alreadyUpToDate arrays by name+group+api before returning. Promise.all over workspaces may resolve in any order, causing non-deterministic output that could produce unnecessary PR body churn. Co-Authored-By: barry.zou <barry.zou@buildwithfern.com>
|
I think |
…ests Co-Authored-By: barry.zou <barry.zou@buildwithfern.com>
|
Both addressed in 3c41095:
Also updated the GHA (actions PR #9) to align — since the CLI now defaults to |
Description
Refs Fern Automations Technical Plan
Add
fern automations upgrade— a new hidden command in thefern automationsnamespace (alongsidegenerateandpreview) that wraps bothfern upgrade(CLI version) andfern generator upgrade(generator versions) into a single invocation with structured JSON output.This command is designed to be consumed by the fern-upgrade GitHub Action, replacing the
snapshot.js/diff.jsfile-parsing approach with a single CLI call that outputs everything the GHA needs.Changes Made
New:
fern automations upgradecommand--include-major(default true),--json(structured output to stdout)fern upgrade --yesthenfern generator upgradeacross all API workspacescliContext.writeJsonToStdout()to correctly write to fd 1 when JSON mode redirects stdout→stderrapi::group::namefor stable JSON across runs{ "cli": { "from": "4.66.0", "to": "4.96.0", "upgraded": true }, "generators": [ { "name": "fernapi/fern-typescript-sdk", "group": "ts-sdk", "api": "api", "from": "3.63.4", "to": "3.65.5", "changelog": "https://buildwithfern.com/learn/sdks/generators/typescript/changelog", "migrationsApplied": 1 } ], "skippedMajor": [{ "name": "...", "current": "0.28.0", "latest": "1.37.0" }], "alreadyUpToDate": [{ "name": "...", "version": "3.65.5" }] }Fix: Replace brittle changelog URL map
upgradeGenerator.tshad a hardcodedCHANGELOG_MAPthat broke whenever a new generator was addedfernapi/fern-<language>-*→buildwithfern.com/learn/sdks/generators/<language>/changelogexecuteAutomationsUpgrade.tsTests
executeAutomationsUpgrade.test.tsgetChangelogUrl: 15 tests covering all supported languages, variant names, non-SDK generators, and edge casesAutomationsUpgradeResultschema: 2 tests documenting the JSON contract between CLI and GHAFiles changed
packages/cli/cli/src/cli.ts— Wire upaddAutomationsUpgradeCommandin the automations namespacepackages/cli/cli/src/commands/automations/upgrade/executeAutomationsUpgrade.ts— New command implementationpackages/cli/cli/src/commands/automations/upgrade/__test__/executeAutomationsUpgrade.test.ts— Unit testspackages/cli/cli/src/commands/upgrade/upgradeGenerator.ts— Replace hardcoded changelog map with derived URL functionpackages/cli/cli/changes/unreleased/add-automations-upgrade-command.yml— Changelog entriesTesting
upgradeGeneratorunit tests pass (4/4)fern automations upgrade --jsonagainst fern-demo/sdk-preview-test-config (6 generators across 2 APIs)Link to Devin session: https://app.devin.ai/sessions/0b0ff224ce294b938ff5c2f5aec943fd