fix: parse the status JSON, pass superseded runs, derive GitHub context - #11
Merged
Merged
Conversation
`dcd status --json` prints pretty JSON (JSON.stringify(obj, null, 2)), so
the compact-JSON greps ('"status":"...') never matched and
DEVICE_CLOUD_UPLOAD_STATUS, DEVICE_CLOUD_FLOW_RESULTS and
DEVICE_CLOUD_APP_BINARY_ID were always empty. Read the document with node,
which is always present because the step runs the CLI through npx.
- DEVICE_CLOUD_FLOW_RESULTS is now a JSON array of {name, status,
failReason?}.
- A status call that returns no JSON reports ERROR; the verdict then rests
on the CLI exit code, as before.
- The verdict logic is unchanged, but a FAILED status now actually fails the
step. That matters with json_file: `dcd cloud --json-file` exits 0 on a
failed run, so until now those runs passed the step. For the same reason,
json_file runs whose status cannot be read now fail instead of passing
(async submissions excepted).
Unskips the two known-bug tests and adds fixture tests for passing,
failing, json_file, compact and noisy status output.
With cancel_previous, a newer run from the same CI context cancels the older run's queued tests. /uploads/status rolls those cancelled tests up to FAILED, so the older build went red for work nobody is waiting on. The status now carries `supersededBy: <uploadId>` for such a run: log "Superseded by <id>" with the newer run's console link, set DEVICE_CLOUD_UPLOAD_STATUS to SUPERSEDED and exit 0, whatever dcd exited with (an older CLI exits 2 for it). This mirrors `dcd cloud` 5.6.0, which exits 0 for a superseded run. Nothing changes when the field is absent, as it is on every other run and on APIs that predate it.
The variables dump and the echoed command line both printed api_key in full. Print [REDACTED] instead; the key is still passed to the CLI.
GitHub checks need gh_repo + gh_sha on the run, and cancel_previous groups runs by gh_repo + gh_pr_number/gh_branch (+ gh_check_name). The step only ever sent gh_check_name, so on Bitrise neither worked unless users hand-wrote the keys into `metadata`. For a github.com repository the step now attaches: - gh_repo from GIT_REPOSITORY_URL (https, ssh:// and scp-style remotes; other hosts, including GitHub Enterprise, get no gh_repo) - gh_sha from BITRISE_GIT_COMMIT, else GIT_CLONE_COMMIT_HASH - gh_branch from BITRISE_GIT_BRANCH - gh_pr_number and gh_pr_url from BITRISE_PULL_REQUEST and, for any repository, gh_run_id from BITRISEIO_PIPELINE_ID (the pipeline build, shared by every workflow in it), else BITRISE_BUILD_SLUG. The server treats uploads with the same run id as siblings, so parallel iOS/Android workflows of one pipeline no longer cancel each other. A key already set in the metadata input wins; gh_pr_url is only built alongside a derived gh_repo. A new include_github_context input (default true) turns all of it off.
- README: the outputs and their values (including SUPERSEDED and ERROR), the gh_* context derived from Bitrise env vars, and how to run the tests (bash 4.1+, since bash 3.2 lets a mid-test [[ ]] assertion pass). - step.yml: android_no_snapshot is automatic from API 34, not 35; json no longer claims to force exit code 0; json_file writes <upload_id>_dcd.json and still fails a failed run.
Share config for bitrise run share-this-step: the step version was never bumped from 1.0.0, and the fork URL pointed at this repo instead of the devicecloud-dev/bitrise-steplib fork the 1.3.0 steplib PR came from.
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.
Summary
Four fixes to
step.sh, from the 23 Sep docs-vs-production audit (plan section E1).Status outputs were always empty.
dcd status --jsonprints pretty JSON (JSON.stringify(obj, null, 2)), and the compact-JSON greps ('"status":"..."') never matched it. SoDEVICE_CLOUD_UPLOAD_STATUS,DEVICE_CLOUD_FLOW_RESULTSandDEVICE_CLOUD_APP_BINARY_IDwere empty on every run. The step now reads the document withnode, which is always there because the step runs the CLI throughnpx.Superseded runs pass. With
cancel_previous, the older run's queued tests are cancelled, and/uploads/statusrolls them up toFAILED. The status now carriessupersededBy: <uploadId>(dcd C2, not live yet). When that field is present the step:Superseded by <id>and the newer run's console link;DEVICE_CLOUD_UPLOAD_STATUS=SUPERSEDED;This mirrors
dcd cloud5.6.0. Nothing changes when the field is absent.The API key is no longer printed. Both the variables dump and the echoed command line printed it; they now show
[REDACTED].GitHub context is derived from Bitrise env vars. GitHub checks need
gh_repo+gh_sha, andcancel_previousneedsgh_repo+ a PR or branch. Until now the step only sentgh_check_name, so neither worked on Bitrise. For github.com repositories it now attaches:gh_repofromGIT_REPOSITORY_URL(https, ssh and scp-style remotes);gh_shafromBITRISE_GIT_COMMIT, elseGIT_CLONE_COMMIT_HASH;gh_branchfromBITRISE_GIT_BRANCH;gh_pr_numberandgh_pr_urlfromBITRISE_PULL_REQUEST.For any repository it also attaches
gh_run_id, fromBITRISEIO_PIPELINE_ID(the "ID of the running Pipeline build", which every workflow in the pipeline shares), elseBITRISE_BUILD_SLUG. The server treats uploads with the same run id as siblings, so parallel workflows of one pipeline don't cancel each other.metadatawin.include_github_contextinput (defaulttrue) turns it all off.Behaviour changes to note
json_file: truenow fails failed runs.dcd cloud --json-fileexits 0 on a failed run, so while the status was unparsed, those builds went green on failures. They now fail on aFAILEDstatus.check_namenames those checks, andinclude_github_context: "false"opts out.ERRORis a new status value, reported when the status call returns no JSON at all. The verdict then comes from dcd's exit code, as before.DEVICE_CLOUD_FLOW_RESULTShas a fixed shape:[{name, status, failReason?}].Tests
bats test/test.bats: 38 tests pass, under bash 5.2 and under macOS bash 3.2.[known bug]tests are unskipped.test/fixtures/*.json, pretty-printed like the real CLI) cover passing, failed and superseded runs.json_filecases are FAILED → fails, PASSED → passes, superseded → passes, and unreadable status → fails.The
npxstub mimics--json-file(exit 2 → 0). I checked the new tests against the oldstep.shand they fail there.shellcheck --shell=bash step.shreports only the 47 existing advisory findings.Not run: the
bitrise.ymltestworkflow (it needs a real API key and a sample app), andstepman audit(the bitrise CLI isn't installed).step.ymlparses, and all 46 inputs have a title and summary.Release
Don't release yet. The plan is 1.4.0, including
cancel_previous, once the steplib approves 1.3.0 (bitrise-io/bitrise-steplib#5260). ThesupersededBybranch only takes effect once dcd returns the field.🤖 Generated with Claude Code