Script releases
This guide shows how to use unirelman from scripts: previewing a release, reading its result, and handling failures.
unirelman prints the result of a command on standard output, and everything else on standard error. See Output streams.
Preview a release
Section titled “Preview a release”Add --dry-run to version or publish:
npx unirelman version --dry-runpnpm unirelman version --dry-runyarn unirelman version --dry-runbunx unirelman version --dry-runA dry run reports what the release contains and changes nothing. Its summary starts with Dry run: nothing was changed. Add --verbose to see each action the run skips, such as Would write CHANGELOG.md.
Read the result
Section titled “Read the result”Add --json to get the result of the command as a JSON document on standard output:
npx unirelman version --dry-run --json > release.jsonpnpm unirelman version --dry-run --json > release.jsonyarn unirelman version --dry-run --json > release.jsonbunx unirelman version --dry-run --json > release.json{ "pipeline": "version", "dryRun": true, "scopes": { "my-package": { "currentVersion": "1.0.0", "nextVersion": "1.0.1" } }, "files": [ { "path": ".unirelman/changesets/1767268800000-1f2e3d4c.md", "action": "delete" }, { "path": "CHANGELOG.md", "action": "write" }, { "path": "package.json", "action": "write" } ]}Each command documents its JSON document, such as version.
Handle failures
Section titled “Handle failures”Check the exit code before reading the result. On failure, unirelman exits with code 1 and prints the error on standard error, with standard output empty:
if npx unirelman version --dry-run --json > release.json; then jq '.scopes' release.jsonelse echo "Release failed" >&2 exit 1fiAdd --verbose to print the stack trace of the error.
Pass every option
Section titled “Pass every option”Outside a terminal, unirelman uses the plain output mode, where a missing option fails the command instead of prompting. In scripts, pass every option of the command, such as --scope and --channel for semver pre.
Check whether a release is pending
Section titled “Check whether a release is pending”set -e
npx unirelman version --dry-run --json > release.json
if [ "$(jq '.files | length' release.json)" -gt 0 ]; then echo "A release is pending"fi