Skip to content

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.

Add --dry-run to version or publish:

Terminal window
npx unirelman version --dry-run

A 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.

Add --json to get the result of the command as a JSON document on standard output:

Terminal window
npx unirelman version --dry-run --json > release.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.

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:

Terminal window
if npx unirelman version --dry-run --json > release.json; then
jq '.scopes' release.json
else
echo "Release failed" >&2
exit 1
fi

Add --verbose to print the stack trace of the error.

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.

Terminal window
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