Repository navigation
Add nh deployment release list, show, create and update - #29
Merged
joshk merged 2 commits intoNov 23, 2026
Merged
Conversation
NervesHub now has endpoints for a deployment group's releases (nerves-hub/nerves_hub_web#3338). These commands use them, and `nh deployment update` and `nh firmware upload --deploy` create their release with POST .../releases where the server has it, falling back to the release PUT on older servers. The request order stays the same: settings first, then the release, then --state on. An older server answers every release route with the same 404 body as a missing group or release, so a 404 is explained by asking for the group (and, for one release, the group's release list). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`firmware upload --deploy` went through UpdateDeployment, which reads the group back after POST .../releases. A failed read turned a release that had been made into an error and stopped the remaining groups. The new DeployFirmware creates the release, with the same fallback, and stops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joshk
force-pushed
the
feature/deployment-release-commands
branch
from
November 23, 2026 23:49
8ff3d30 to
5a1898d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #25 (
fix/deployment-create-update), so this PR only shows the release work. Retarget it tomainonce #25 merges. The new commands need nerves-hub/nerves_hub_web#3338 on the server. That PR is open, not merged. On a server without it, thereleasecommands fail with an upgrade message, anddeployment update/firmware upload --deploykeep working as they did in #25.What changed
nh deployment release list|show|create|updateNew file
cmd/deployment_release.go. All four commands support-o json.list <group>: a table with number, current marker (*), firmware version and UUID, archive, required, delta status, created by and inserted at. Newest first, in the server's order.show <group> <number>: every field, including description, notes, connecting code and its mode.create <group> --firmware [--archive] [--required] [--description] [--notes] [--connecting-code | --connecting-code-file] [--connecting-code-mode first|last|override]update <group> <number> [--required[=false]] [--connecting-code | --connecting-code-file | --clear-connecting-code] [--connecting-code-mode]The client is in
internal/api/deployment_release.go(ListDeploymentReleases,GetDeploymentRelease,CreateDeploymentRelease,UpdateDeploymentRelease). It checks input the waydeployment.godoes: org, product and group are required, a release number must be 1 or more,firmwareis required on create, the mode must befirst,lastoroverride, and an update has to change something. The request bodies followDeploymentReleaseControllerin #3338:POSTsends a flat body with only the fields given. The controller readsfirmwareandarchiveitself and takes@create_fieldsfrom the rest.PATCHsends onlyrequired,connecting_codeandconnecting_code_mode(@update_fields).--clear-connecting-codesends"connecting_code": null.Telling an old server from a missing group or release
In #3338,
FallbackControllerreturnsErrorJSON"404.json"for a group or release that doesn't exist. That's the same body Phoenix gives for a route that doesn't exist. So neither the status nor the body says why a 404 happened. Instead, only after a release endpoint returns 404, the client asks follow-up questions whose answers differ (explainReleaseNotFound):showandupdate), it lists the group's releases. If that succeeds, the server has the API and the group exists, so the error isdeployment group "x" has no release N.GET /deployments/:name, which every server has. If that succeeds, the release route is the missing piece, and the error isErrReleasesUnsupported: "this NervesHub server doesn't support deployment group releases; upgrade NervesHub to use them". If that also returns 404, the error isdeployment group "x" not found in org/product.Errors other than 404 (401 permission refusals, 422, 5xx) are passed on with no extra requests.
I looked at
cmd/device_list_query_support.goand didn't use its pattern. That probe works because a new server answers a probe query differently (422) from an old one. Here a new server also returns 404 for a group that doesn't exist, so a probe sent up front can't settle the question. The check only runs after a 404 anyway, so there's nothing worth caching.deployment updateandfirmware upload --deployuse the new endpointUpdateDeploymentnow creates its release throughsendRelease. That triesPOST .../releasesfirst. If the POST returns 404 and the group is known to exist, it falls back to #25's releasePUT. The group counts as known if the settingsPUTin the same update succeeded, or if the archive-only path already read the group's current firmware. Otherwise the client gets the group first, and a 404 there is returned as is, with noPUT. A 422 from the POST (for example "The current release already has this firmware and archive") is returned and never triggers the fallback.The order from #25 is unchanged: settings (including
--state off), then the release, then--state on.The POST returns a release, but
deployment updateprints the group, including with-o json. So after a POST the group is read back with oneGET, unless the closing--state onPUT already returned it. If that read fails, the error says the release was created.deployFirmwareincmd/firmware_upload.gonow calls a newDeployFirmwareclient method. It uses the same POST-then-fallback logic but skips the read-back, because the upload never uses the group. Without it, a failed GET after a successful release would report that group as failed and skip the remaining--deploygroups (found in review).Choices I made (Josh, please check)
releasecommands never fall back toPUT. An old server has no way to list, show or patch a release. APUTthat creates a release would silently drop--description,--notesand the connecting code. So on an old server these commands fail with the upgrade message.--connecting-code-file). The server would take""as "remove it". Removing it takes--clear-connecting-codeinstead, so an empty file can't wipe the code by accident.""(archive_uuid,description,notes,connecting_code), as the existingDeploymenttype does witharchive_uuid.created_byis a pointer, so anullauthor staysnullin-o json.--archiveis passed, indeployment release createand indeployment update --firmwarealike. That matches #3338 (DeploymentReleaseCreationRequest: "Left out, the release has no archive, whatever the previous release had"), which leaves it as an open question for Josh. If the answer is that releases should keep the archive, the CLI could read the current release and pass it along.Server code checked
I read #3338's head (
f2f0c9a). I found no place where its description and its code disagree.lib/nerves_hub_web/router.ex:get/post /:name/releases, plusget/patch /:name/releases/:number. There's noPUTon a release, so the client usesPATCH.lib/nerves_hub_web/controllers/api/deployment_release_controller.ex: the fields each write takes, 201 on create, andget_release/2returning 404 for a non-integer number, 0, or a number past int4.lib/nerves_hub_web/controllers/api/deployment_release_json.ex: the release shape, includingis_currentandcreated_by(userwithemail,api_key, ornil).lib/nerves_hub_web/controllers/api/schemas/deployment_release_schemas.ex: theconnecting_code_modeanddelta_statusenums.lib/nerves_hub_web/controllers/api/fallback_controller.exanderror_json.ex: the 404 body that's identical in every case.Tests
internal/api/deployment_release_test.go: each method's method, path and body; decoding every field; validation; old-server detection for all four methods (noPUTever sent); a missing release; a missing group; other errors passed through; andUpdateDeploymentfalling back on an old server (release only, settings plus--state onorder, archive only), not falling back on a missing group or a 422, and reporting a failed read-back.cmd/deployment_release_test.go: each command's table output, JSON, flags and validation; connecting code from stdin; the upgrade message from every command; anddeployment updateagainst an old server.deployment updateandfirmware upload --deploytests for the new endpoint, and addedTestFirmwareUploadDeploysOnServerWithoutReleaseAPI.go test ./...,go vet ./...andgofmt -l .are clean.Not verified: none of this has been run against a real NervesHub with #3338. The tests use httptest fakes modelled on the server code above.
🤖 Generated with Claude Code