-
-
Notifications
You must be signed in to change notification settings - Fork 544
Description
Thanks for this fantastic tool!
Depending on the release, we'd like to set push arguments to set CI/CD variables to toggle certain deployment steps. Whether a certain deployment step is active, is up to whoever creates that release.
To achieve this, I wrote a simple plugin which looks as follows:
import { Plugin } from 'release-it';
import inquirer from 'inquirer';
class ReleaseOptions extends Plugin {
async init() {
const { variables } = this.options;
const { booleans } = variables;
const prompts = Object.entries(booleans).map(([name, defaultValue]) => ({
type: 'confirm',
name: `CI_CUSTOM_${name}`,
default: defaultValue,
}));
await inquirer
.prompt(prompts)
.then((answers) => {
const pushArgs = [
...this.config.getContext('git.pushArgs'),
...Object.entries(answers).map(
([name, value]) => `-o ci.variable="${name}=${value}"`
),
];
this.debug(pushArgs);
this.config.setContext({ git: { pushArgs } });
})
.catch((error) => {
this.log.error(error);
});
return true;
}
}
export default ReleaseOptions;
Configuration in package.json
is:
{
"release-it": {
"plugins": {
"./release-options.js": {
"variables": {
"booleans": {
"FOO": true,
"BAR": false
}
}
}
}
}
}
git.pushArgs
is modified using this.config.setContext
which works. However, when the actual git push
is executed in lib/plugin/git/Git.js
in push()
, the options are passed as a default argument using args = this.options.pushArgs
. args
contains the push arguments as defined when initializing the plugin and defaults to [ '--follow-tags' ]
and does not contain the changes made using config.setContext()
which would look like this:
[
'--follow-tags',
'-o ci.variable="CI_CUSTOM_FOO=true"',
'-o ci.variable="CI_CUSTOM_BAR=false"'
]
To fix this, I see two options:
- I made a stupid mistake and could easily fix this by e.g. using a different plugin hook / setting the arguments in a different way
push()
resolvesargs
usingconfig.getContext
Can you please help me resolve this?