semantic-release icon indicating copy to clipboard operation
semantic-release copied to clipboard

CLI option `--branches` does not support JSON objects

Open julisch94 opened this issue 2 years ago • 7 comments

Current behavior

When running the command

npx semantic-release --branches "[\"main\",{\"name\":\"*\",\"prerelease\":true}]"

I receive the following error:

[12:03:06] [semantic-release] › ✖  ERELEASEBRANCHES The release branches are invalid in the `branches` configuration.
A minimum of 1 and a maximum of 3 release branches are required in the branches configuration (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches).

This may occur if your repository does not have a release branch, such as master.

Your configuration for the problematic branches is [].

I want to pass the prerelease option as command line argument.

Expected behavior

I would expect my branches option to be parsed as JSON.

I would expect my command to yield the same output as when having the following in my .releaserc:

{
"branches": [
    "main",
    {
      "name": "*",
      "prerelease": true
    }
  ],
  ...
}

Or, How can I pass the prerelease option as command line argument?

semantic-release version

19.0.5

CI environment

local

Plugins used

No response

semantic-release configuration

I'm trying to pass the --branches option as command line argument.

Why, you ask? Because I would like to have different CI jobs with different configs running for my repo.

CI logs

[12:03:04] [semantic-release] › ℹ  Running semantic-release version 19.0.5
[12:03:04] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/npm"
[12:03:04] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[12:03:04] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/npm"
[12:03:04] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/npm"
[12:03:04] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/npm"
[12:03:04] [semantic-release] › ⚠  This run was not triggered in a known CI environment, running in dry-run mode.
[12:03:06] [semantic-release] › ✖  ERELEASEBRANCHES The release branches are invalid in the `branches` configuration.
A minimum of 1 and a maximum of 3 release branches are required in the branches configuration (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches).

This may occur if your repository does not have a release branch, such as master.

Your configuration for the problematic branches is [].

AggregateError: 
    SemanticReleaseError: The release branches are invalid in the `branches` configuration.
        at module.exports (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/lib/get-error.js:6:10)
        at /Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/lib/branches/index.js:45:19
        at Array.reduce (<anonymous>)
        at module.exports (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/lib/branches/index.js:35:46)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async run (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/index.js:65:22)
        at async module.exports (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/index.js:269:22)
        at async module.exports (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/cli.js:55:5)
    at module.exports (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/lib/branches/index.js:67:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async run (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/index.js:65:22)
    at async module.exports (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/index.js:269:22)
    at async module.exports (/Users/julisch/dev/git/github/juleshq/jules-cve-ui/node_modules/semantic-release/cli.js:55:5)
    ```

julisch94 avatar Nov 14 '22 11:11 julisch94

I can confirm that same problem happens in --plugins

lapastillaroja avatar Dec 15 '22 03:12 lapastillaroja

+1

PedroBern avatar Jan 26 '23 12:01 PedroBern

Everything that uses stringList (cli.js) looks to be broken, based on the branch docs. Realistically the only thing you can pass are strings. const stringList = { type: "string", array: true, coerce: (values) => values.length === 1 && values[0].trim() === "false" ? [] : values.reduce((values, value) => values.concat(value.split(",").map((value) => value.trim())), []), };

.option("b", { alias: "branches", describe: "Git branches to release from", ...stringList, group: "Options" }) <----* .option("r", { alias: "repository-url", describe: "Git repository URL", type: "string", group: "Options" }) .option("t", { alias: "tag-format", describe: "Git tag format", type: "string", group: "Options" }) .option("p", { alias: "plugins", describe: "Plugins", ...stringList, group: "Options" }) <----* .option("e", { alias: "extends", describe: "Shareable configurations", ...stringList, group: "Options" }) <----* .option("ci", { describe: "Toggle CI verifications", type: "boolean", group: "Options" }) .option("verify-conditions", { ...stringList, group: "Plugins" }) <----* .option("analyze-commits", { type: "string", group: "Plugins" }) .option("verify-release", { ...stringList, group: "Plugins" }) <----* .option("generate-notes", { ...stringList, group: "Plugins" }) <----* .option("prepare", { ...stringList, group: "Plugins" }) <----* .option("publish", { ...stringList, group: "Plugins" }) <----* .option("success", { ...stringList, group: "Plugins" }) <----* .option("fail", { ...stringList, group: "Plugins" }) <----* .option("debug", { describe: "Output debugging information", type: "boolean", group: "Options" }) .option("d", { alias: "dry-run", describe: "Skip publishing", type: "boolean", group: "Options" }) .option("h", { alias: "help", group: "Options" }) .strict(false) .exitProcess(false);

As is, take these examples:

cli: npx semantic-release --no-ci -d --debug true --branches ['master','1.2.3'] branches option from debug: branches: [ "['master'", "'1.2.3']" ]

cli: npx semantic-release --no-ci -d --debug true --branches master,1.2.3,{name:temp,prerelease:true} options from debug: branches: [ 'master', '1.2.3', '{name:temp', 'prerelease:true}' ]

cli: npx semantic-release --no-ci -d --debug true --branches 'master','1.2.3' options from debug: branches: [ "'master'", "'1.2.3'" ]

Looks to work as expected: cli: npx semantic-release --no-ci -d --debug true --branches master,1.2.3 options from debug: branches: [ 'master', '1.2.3' ]

GhandiJones avatar Jan 30 '23 16:01 GhandiJones

For those that find this and we still have no fix, if this is a serious issue, just use .releaserc. That is what I end up doing. You can build it programmatically and use it with CI.

GhandiJones avatar Feb 06 '23 14:02 GhandiJones

We are still waiting for the solution to skip building a new .releaserc during the CI run.

krisztianbenda avatar Jul 19 '23 09:07 krisztianbenda

Any news on this?

haukurmar avatar Jul 20 '23 13:07 haukurmar

ping

jawys avatar Nov 24 '23 23:11 jawys